John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1 | // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 4 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
Tom Sepez | 1ed8a21 | 2015-05-11 15:25:39 -0700 | [diff] [blame] | 7 | #include "../../public/fpdf_edit.h" |
| 8 | #include "../../public/fpdf_formfill.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 9 | #include "../include/fsdk_define.h" |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 10 | #include "../include/fpdfxfa/fpdfxfa_doc.h" |
| 11 | #include "../include/fpdfxfa/fpdfxfa_app.h" |
| 12 | #include "../include/fpdfxfa/fpdfxfa_page.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 13 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 14 | #if _FX_OS_ == _FX_ANDROID_ |
| 15 | #include "time.h" |
| 16 | #else |
| 17 | #include <ctime> |
| 18 | #endif |
| 19 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 20 | DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_CreateNewDocument() { |
Tom Sepez | ae51c81 | 2015-08-05 12:34:06 -0700 | [diff] [blame] | 21 | CPDF_Document* pDoc = new CPDF_Document; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 22 | pDoc->CreateNewDoc(); |
| 23 | time_t currentTime; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 24 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 25 | CFX_ByteString DateStr; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 26 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 27 | if (FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS)) { |
| 28 | if (-1 != time(¤tTime)) { |
| 29 | tm* pTM = localtime(¤tTime); |
| 30 | if (pTM) { |
| 31 | DateStr.Format("D:%04d%02d%02d%02d%02d%02d", pTM->tm_year + 1900, |
| 32 | pTM->tm_mon + 1, pTM->tm_mday, pTM->tm_hour, pTM->tm_min, |
| 33 | pTM->tm_sec); |
| 34 | } |
| 35 | } |
| 36 | } |
Tom Sepez | bdeeb8a | 2015-05-27 12:25:00 -0700 | [diff] [blame] | 37 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 38 | CPDF_Dictionary* pInfoDict = NULL; |
| 39 | pInfoDict = pDoc->GetInfo(); |
| 40 | if (pInfoDict) { |
| 41 | if (FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS)) |
| 42 | pInfoDict->SetAt("CreationDate", new CPDF_String(DateStr)); |
Tom Sepez | ae51c81 | 2015-08-05 12:34:06 -0700 | [diff] [blame] | 43 | pInfoDict->SetAt("Creator", new CPDF_String(L"PDFium")); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 44 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 45 | |
Tom Sepez | bf59a07 | 2015-10-21 14:07:23 -0700 | [diff] [blame^] | 46 | return FPDFDocumentFromCPDFDocument(pDoc); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 47 | } |
| 48 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 49 | DLLEXPORT void STDCALL FPDFPage_Delete(FPDF_DOCUMENT document, int page_index) { |
Tom Sepez | 471a103 | 2015-10-15 16:17:18 -0700 | [diff] [blame] | 50 | CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
| 51 | if (!pDoc || page_index < 0 || page_index >= pDoc->GetPageCount()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 52 | return; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 53 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 54 | pDoc->DeletePage(page_index); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 55 | } |
| 56 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 57 | DLLEXPORT FPDF_PAGE STDCALL FPDFPage_New(FPDF_DOCUMENT document, |
| 58 | int page_index, |
| 59 | double width, |
| 60 | double height) { |
Tom Sepez | 471a103 | 2015-10-15 16:17:18 -0700 | [diff] [blame] | 61 | CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
| 62 | if (!pDoc) |
| 63 | return nullptr; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 64 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 65 | if (page_index < 0) |
| 66 | page_index = 0; |
| 67 | if (pDoc->GetPageCount() < page_index) |
| 68 | page_index = pDoc->GetPageCount(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 69 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 70 | CPDF_Dictionary* pPageDict = pDoc->CreateNewPage(page_index); |
| 71 | if (!pPageDict) |
| 72 | return NULL; |
Tom Sepez | ae51c81 | 2015-08-05 12:34:06 -0700 | [diff] [blame] | 73 | CPDF_Array* pMediaBoxArray = new CPDF_Array; |
| 74 | pMediaBoxArray->Add(new CPDF_Number(0)); |
| 75 | pMediaBoxArray->Add(new CPDF_Number(0)); |
| 76 | pMediaBoxArray->Add(new CPDF_Number(FX_FLOAT(width))); |
| 77 | pMediaBoxArray->Add(new CPDF_Number(FX_FLOAT(height))); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 78 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 79 | pPageDict->SetAt("MediaBox", pMediaBoxArray); |
Tom Sepez | ae51c81 | 2015-08-05 12:34:06 -0700 | [diff] [blame] | 80 | pPageDict->SetAt("Rotate", new CPDF_Number(0)); |
| 81 | pPageDict->SetAt("Resources", new CPDF_Dictionary); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 82 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 83 | CPDFXFA_Page* pPage = |
Tom Sepez | ae51c81 | 2015-08-05 12:34:06 -0700 | [diff] [blame] | 84 | new CPDFXFA_Page((CPDFXFA_Document*)document, page_index); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 85 | pPage->LoadPDFPage(pPageDict); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 86 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 87 | return pPage; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 88 | } |
| 89 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 90 | DLLEXPORT int STDCALL FPDFPage_GetRotation(FPDF_PAGE page) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 91 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 92 | if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") || |
| 93 | !pPage->m_pFormDict->GetElement("Type")->GetDirect() || |
| 94 | pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare( |
| 95 | "Page")) { |
| 96 | return -1; |
| 97 | } |
| 98 | CPDF_Dictionary* pDict = pPage->m_pFormDict; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 99 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 100 | int rotate = 0; |
| 101 | if (pDict != NULL) { |
| 102 | if (pDict->KeyExist("Rotate")) |
| 103 | rotate = pDict->GetElement("Rotate")->GetDirect() |
| 104 | ? pDict->GetElement("Rotate")->GetDirect()->GetInteger() / 90 |
| 105 | : 0; |
| 106 | else { |
| 107 | if (pDict->KeyExist("Parent")) { |
| 108 | CPDF_Dictionary* pPages = |
Dan Sinclair | f1251c1 | 2015-10-20 16:24:45 -0400 | [diff] [blame] | 109 | ToDictionary(pDict->GetElement("Parent")->GetDirect()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 110 | while (pPages) { |
| 111 | if (pPages->KeyExist("Rotate")) { |
| 112 | rotate = |
| 113 | pPages->GetElement("Rotate")->GetDirect() |
| 114 | ? pPages->GetElement("Rotate")->GetDirect()->GetInteger() / |
| 115 | 90 |
| 116 | : 0; |
| 117 | break; |
| 118 | } else if (pPages->KeyExist("Parent")) |
Dan Sinclair | f1251c1 | 2015-10-20 16:24:45 -0400 | [diff] [blame] | 119 | pPages = ToDictionary(pPages->GetElement("Parent")->GetDirect()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 120 | else |
| 121 | break; |
| 122 | } |
| 123 | } |
| 124 | } |
| 125 | } else { |
| 126 | return -1; |
| 127 | } |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 128 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 129 | return rotate; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 130 | } |
| 131 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 132 | DLLEXPORT void STDCALL FPDFPage_InsertObject(FPDF_PAGE page, |
| 133 | FPDF_PAGEOBJECT page_obj) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 134 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 135 | if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") || |
| 136 | !pPage->m_pFormDict->GetElement("Type")->GetDirect() || |
| 137 | pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare( |
| 138 | "Page")) { |
| 139 | return; |
| 140 | } |
| 141 | CPDF_PageObject* pPageObj = (CPDF_PageObject*)page_obj; |
| 142 | if (pPageObj == NULL) |
| 143 | return; |
| 144 | FX_POSITION LastPersition = pPage->GetLastObjectPosition(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 145 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 146 | pPage->InsertObject(LastPersition, pPageObj); |
| 147 | switch (pPageObj->m_Type) { |
| 148 | case FPDF_PAGEOBJ_PATH: { |
| 149 | CPDF_PathObject* pPathObj = (CPDF_PathObject*)pPageObj; |
| 150 | pPathObj->CalcBoundingBox(); |
| 151 | break; |
| 152 | } |
| 153 | case FPDF_PAGEOBJ_TEXT: { |
| 154 | // CPDF_PathObject* pPathObj = (CPDF_PathObject*)pPageObj; |
| 155 | // pPathObj->CalcBoundingBox(); |
| 156 | break; |
| 157 | } |
| 158 | case FPDF_PAGEOBJ_IMAGE: { |
| 159 | CPDF_ImageObject* pImageObj = (CPDF_ImageObject*)pPageObj; |
| 160 | pImageObj->CalcBoundingBox(); |
| 161 | break; |
| 162 | } |
| 163 | case FPDF_PAGEOBJ_SHADING: { |
| 164 | CPDF_ShadingObject* pShadingObj = (CPDF_ShadingObject*)pPageObj; |
| 165 | pShadingObj->CalcBoundingBox(); |
| 166 | break; |
| 167 | } |
| 168 | case FPDF_PAGEOBJ_FORM: { |
| 169 | CPDF_FormObject* pFormObj = (CPDF_FormObject*)pPageObj; |
| 170 | pFormObj->CalcBoundingBox(); |
| 171 | break; |
| 172 | } |
| 173 | default: |
| 174 | break; |
| 175 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 176 | } |
| 177 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 178 | DLLEXPORT int STDCALL FPDFPage_CountObject(FPDF_PAGE page) { |
Tom Sepez | bf59a07 | 2015-10-21 14:07:23 -0700 | [diff] [blame^] | 179 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 180 | if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") || |
| 181 | !pPage->m_pFormDict->GetElement("Type")->GetDirect() || |
| 182 | pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare( |
| 183 | "Page")) { |
| 184 | return -1; |
| 185 | } |
| 186 | return pPage->CountObjects(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 187 | } |
| 188 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 189 | DLLEXPORT FPDF_PAGEOBJECT STDCALL FPDFPage_GetObject(FPDF_PAGE page, |
| 190 | int index) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 191 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 192 | if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") || |
| 193 | pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare( |
| 194 | "Page")) { |
| 195 | return NULL; |
| 196 | } |
| 197 | return pPage->GetObjectByIndex(index); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 198 | } |
| 199 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 200 | DLLEXPORT FPDF_BOOL STDCALL FPDFPage_HasTransparency(FPDF_PAGE page) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 201 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
| 202 | return pPage && pPage->BackgroundAlphaNeeded(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 203 | } |
| 204 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 205 | DLLEXPORT FPDF_BOOL STDCALL |
| 206 | FPDFPageObj_HasTransparency(FPDF_PAGEOBJECT pageObject) { |
| 207 | if (!pageObject) |
| 208 | return FALSE; |
| 209 | CPDF_PageObject* pPageObj = (CPDF_PageObject*)pageObject; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 210 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 211 | const CPDF_GeneralStateData* pGeneralState = pPageObj->m_GeneralState; |
| 212 | int blend_type = |
| 213 | pGeneralState ? pGeneralState->m_BlendType : FXDIB_BLEND_NORMAL; |
| 214 | if (blend_type != FXDIB_BLEND_NORMAL) |
| 215 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 216 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 217 | CPDF_Dictionary* pSMaskDict = |
Dan Sinclair | f1251c1 | 2015-10-20 16:24:45 -0400 | [diff] [blame] | 218 | pGeneralState ? ToDictionary(pGeneralState->m_pSoftMask) : NULL; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 219 | if (pSMaskDict) |
| 220 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 221 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 222 | if (pGeneralState && pGeneralState->m_FillAlpha != 1.0f) |
| 223 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 224 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 225 | if (pPageObj->m_Type == PDFPAGE_PATH) { |
| 226 | if (pGeneralState && pGeneralState->m_StrokeAlpha != 1.0f) |
| 227 | return TRUE; |
| 228 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 229 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 230 | if (pPageObj->m_Type == PDFPAGE_FORM) { |
| 231 | CPDF_FormObject* pFormObj = (CPDF_FormObject*)pPageObj; |
| 232 | if (pFormObj->m_pForm && |
| 233 | (pFormObj->m_pForm->m_Transparency & PDFTRANS_ISOLATED)) |
| 234 | return TRUE; |
| 235 | if (pFormObj->m_pForm && |
| 236 | (!(pFormObj->m_pForm->m_Transparency & PDFTRANS_ISOLATED) && |
| 237 | (pFormObj->m_pForm->m_Transparency & PDFTRANS_GROUP))) |
| 238 | return TRUE; |
| 239 | } |
| 240 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 241 | } |
| 242 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 243 | DLLEXPORT FPDF_BOOL STDCALL FPDFPage_GenerateContent(FPDF_PAGE page) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 244 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 245 | if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") || |
| 246 | !pPage->m_pFormDict->GetElement("Type")->GetDirect() || |
| 247 | pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare( |
| 248 | "Page")) { |
| 249 | return FALSE; |
| 250 | } |
| 251 | CPDF_PageContentGenerate CG(pPage); |
| 252 | CG.GenerateContent(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 253 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 254 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | DLLEXPORT void STDCALL FPDFPageObj_Transform(FPDF_PAGEOBJECT page_object, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 258 | double a, |
| 259 | double b, |
| 260 | double c, |
| 261 | double d, |
| 262 | double e, |
| 263 | double f) { |
| 264 | CPDF_PageObject* pPageObj = (CPDF_PageObject*)page_object; |
| 265 | if (pPageObj == NULL) |
| 266 | return; |
Lei Zhang | cb78ef5 | 2015-10-02 10:10:49 -0700 | [diff] [blame] | 267 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 268 | CFX_AffineMatrix matrix((FX_FLOAT)a, (FX_FLOAT)b, (FX_FLOAT)c, (FX_FLOAT)d, |
| 269 | (FX_FLOAT)e, (FX_FLOAT)f); |
| 270 | pPageObj->Transform(matrix); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 271 | } |
| 272 | DLLEXPORT void STDCALL FPDFPage_TransformAnnots(FPDF_PAGE page, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 273 | double a, |
| 274 | double b, |
| 275 | double c, |
| 276 | double d, |
| 277 | double e, |
| 278 | double f) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 279 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 280 | if (!pPage) |
| 281 | return; |
| 282 | CPDF_AnnotList AnnotList(pPage); |
| 283 | for (int i = 0; i < AnnotList.Count(); i++) { |
| 284 | CPDF_Annot* pAnnot = AnnotList.GetAt(i); |
| 285 | // transformAnnots Rectangle |
| 286 | CPDF_Rect rect; |
| 287 | pAnnot->GetRect(rect); |
| 288 | CFX_AffineMatrix matrix((FX_FLOAT)a, (FX_FLOAT)b, (FX_FLOAT)c, (FX_FLOAT)d, |
| 289 | (FX_FLOAT)e, (FX_FLOAT)f); |
| 290 | rect.Transform(&matrix); |
| 291 | CPDF_Array* pRectArray = NULL; |
| 292 | pRectArray = pAnnot->GetAnnotDict()->GetArray("Rect"); |
| 293 | if (!pRectArray) |
| 294 | pRectArray = CPDF_Array::Create(); |
| 295 | pRectArray->SetAt(0, new CPDF_Number(rect.left)); |
| 296 | pRectArray->SetAt(1, new CPDF_Number(rect.bottom)); |
| 297 | pRectArray->SetAt(2, new CPDF_Number(rect.right)); |
| 298 | pRectArray->SetAt(3, new CPDF_Number(rect.top)); |
| 299 | pAnnot->GetAnnotDict()->SetAt("Rect", pRectArray); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 300 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 301 | // Transform AP's rectangle |
| 302 | // To Do |
| 303 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 304 | } |
Bo Xu | 394010d | 2014-06-12 13:41:50 -0700 | [diff] [blame] | 305 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 306 | DLLEXPORT void STDCALL FPDFPage_SetRotation(FPDF_PAGE page, int rotate) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 307 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 308 | if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") || |
| 309 | !pPage->m_pFormDict->GetElement("Type")->GetDirect() || |
| 310 | pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare( |
| 311 | "Page")) { |
| 312 | return; |
| 313 | } |
| 314 | CPDF_Dictionary* pDict = pPage->m_pFormDict; |
| 315 | rotate %= 4; |
Bo Xu | 394010d | 2014-06-12 13:41:50 -0700 | [diff] [blame] | 316 | |
Tom Sepez | ae51c81 | 2015-08-05 12:34:06 -0700 | [diff] [blame] | 317 | pDict->SetAt("Rotate", new CPDF_Number(rotate * 90)); |
Nico Weber | 0ce77e3 | 2014-07-16 13:19:08 -0700 | [diff] [blame] | 318 | } |