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 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 46 | CPDFXFA_App* pApp = CPDFXFA_App::GetInstance(); |
Lei Zhang | cb78ef5 | 2015-10-02 10:10:49 -0700 | [diff] [blame^] | 47 | return new CPDFXFA_Document(pDoc, pApp); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 48 | } |
| 49 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 50 | DLLEXPORT void STDCALL FPDFPage_Delete(FPDF_DOCUMENT document, int page_index) { |
| 51 | CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc(); |
| 52 | if (pDoc == NULL) |
| 53 | return; |
| 54 | if (page_index < 0 || page_index >= pDoc->GetPageCount()) |
| 55 | return; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 56 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 57 | pDoc->DeletePage(page_index); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 58 | } |
| 59 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 60 | DLLEXPORT FPDF_PAGE STDCALL FPDFPage_New(FPDF_DOCUMENT document, |
| 61 | int page_index, |
| 62 | double width, |
| 63 | double height) { |
| 64 | if (!document) |
| 65 | return NULL; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 66 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 67 | // CPDF_Parser* pParser = (CPDF_Parser*)document; |
| 68 | CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc(); |
| 69 | if (page_index < 0) |
| 70 | page_index = 0; |
| 71 | if (pDoc->GetPageCount() < page_index) |
| 72 | page_index = pDoc->GetPageCount(); |
| 73 | // if (page_index < 0 || page_index >= pDoc->GetPageCount()) |
| 74 | // return NULL; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 75 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 76 | CPDF_Dictionary* pPageDict = pDoc->CreateNewPage(page_index); |
| 77 | if (!pPageDict) |
| 78 | return NULL; |
Tom Sepez | ae51c81 | 2015-08-05 12:34:06 -0700 | [diff] [blame] | 79 | CPDF_Array* pMediaBoxArray = new CPDF_Array; |
| 80 | pMediaBoxArray->Add(new CPDF_Number(0)); |
| 81 | pMediaBoxArray->Add(new CPDF_Number(0)); |
| 82 | pMediaBoxArray->Add(new CPDF_Number(FX_FLOAT(width))); |
| 83 | pMediaBoxArray->Add(new CPDF_Number(FX_FLOAT(height))); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 84 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 85 | pPageDict->SetAt("MediaBox", pMediaBoxArray); |
Tom Sepez | ae51c81 | 2015-08-05 12:34:06 -0700 | [diff] [blame] | 86 | pPageDict->SetAt("Rotate", new CPDF_Number(0)); |
| 87 | pPageDict->SetAt("Resources", new CPDF_Dictionary); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 88 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 89 | CPDFXFA_Page* pPage = |
Tom Sepez | ae51c81 | 2015-08-05 12:34:06 -0700 | [diff] [blame] | 90 | new CPDFXFA_Page((CPDFXFA_Document*)document, page_index); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 91 | pPage->LoadPDFPage(pPageDict); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 92 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 93 | return pPage; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 94 | } |
| 95 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 96 | DLLEXPORT int STDCALL FPDFPage_GetRotation(FPDF_PAGE page) { |
| 97 | CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage(); |
| 98 | if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") || |
| 99 | !pPage->m_pFormDict->GetElement("Type")->GetDirect() || |
| 100 | pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare( |
| 101 | "Page")) { |
| 102 | return -1; |
| 103 | } |
| 104 | CPDF_Dictionary* pDict = pPage->m_pFormDict; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 105 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 106 | int rotate = 0; |
| 107 | if (pDict != NULL) { |
| 108 | if (pDict->KeyExist("Rotate")) |
| 109 | rotate = pDict->GetElement("Rotate")->GetDirect() |
| 110 | ? pDict->GetElement("Rotate")->GetDirect()->GetInteger() / 90 |
| 111 | : 0; |
| 112 | else { |
| 113 | if (pDict->KeyExist("Parent")) { |
| 114 | CPDF_Dictionary* pPages = |
| 115 | (CPDF_Dictionary*)pDict->GetElement("Parent")->GetDirect(); |
| 116 | while (pPages) { |
| 117 | if (pPages->KeyExist("Rotate")) { |
| 118 | rotate = |
| 119 | pPages->GetElement("Rotate")->GetDirect() |
| 120 | ? pPages->GetElement("Rotate")->GetDirect()->GetInteger() / |
| 121 | 90 |
| 122 | : 0; |
| 123 | break; |
| 124 | } else if (pPages->KeyExist("Parent")) |
| 125 | pPages = |
| 126 | (CPDF_Dictionary*)pPages->GetElement("Parent")->GetDirect(); |
| 127 | else |
| 128 | break; |
| 129 | } |
| 130 | } |
| 131 | } |
| 132 | } else { |
| 133 | return -1; |
| 134 | } |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 135 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 136 | return rotate; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 137 | } |
| 138 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 139 | DLLEXPORT void STDCALL FPDFPage_InsertObject(FPDF_PAGE page, |
| 140 | FPDF_PAGEOBJECT page_obj) { |
| 141 | CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage(); |
| 142 | if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") || |
| 143 | !pPage->m_pFormDict->GetElement("Type")->GetDirect() || |
| 144 | pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare( |
| 145 | "Page")) { |
| 146 | return; |
| 147 | } |
| 148 | CPDF_PageObject* pPageObj = (CPDF_PageObject*)page_obj; |
| 149 | if (pPageObj == NULL) |
| 150 | return; |
| 151 | FX_POSITION LastPersition = pPage->GetLastObjectPosition(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 152 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 153 | pPage->InsertObject(LastPersition, pPageObj); |
| 154 | switch (pPageObj->m_Type) { |
| 155 | case FPDF_PAGEOBJ_PATH: { |
| 156 | CPDF_PathObject* pPathObj = (CPDF_PathObject*)pPageObj; |
| 157 | pPathObj->CalcBoundingBox(); |
| 158 | break; |
| 159 | } |
| 160 | case FPDF_PAGEOBJ_TEXT: { |
| 161 | // CPDF_PathObject* pPathObj = (CPDF_PathObject*)pPageObj; |
| 162 | // pPathObj->CalcBoundingBox(); |
| 163 | break; |
| 164 | } |
| 165 | case FPDF_PAGEOBJ_IMAGE: { |
| 166 | CPDF_ImageObject* pImageObj = (CPDF_ImageObject*)pPageObj; |
| 167 | pImageObj->CalcBoundingBox(); |
| 168 | break; |
| 169 | } |
| 170 | case FPDF_PAGEOBJ_SHADING: { |
| 171 | CPDF_ShadingObject* pShadingObj = (CPDF_ShadingObject*)pPageObj; |
| 172 | pShadingObj->CalcBoundingBox(); |
| 173 | break; |
| 174 | } |
| 175 | case FPDF_PAGEOBJ_FORM: { |
| 176 | CPDF_FormObject* pFormObj = (CPDF_FormObject*)pPageObj; |
| 177 | pFormObj->CalcBoundingBox(); |
| 178 | break; |
| 179 | } |
| 180 | default: |
| 181 | break; |
| 182 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 183 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 184 | // pPage->ParseContent(); |
| 185 | // pPage->GenerateContent(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 186 | } |
| 187 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 188 | DLLEXPORT int STDCALL FPDFPage_CountObject(FPDF_PAGE page) { |
| 189 | CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage(); |
| 190 | if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") || |
| 191 | !pPage->m_pFormDict->GetElement("Type")->GetDirect() || |
| 192 | pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare( |
| 193 | "Page")) { |
| 194 | return -1; |
| 195 | } |
| 196 | return pPage->CountObjects(); |
| 197 | // return 0; |
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_PAGEOBJECT STDCALL FPDFPage_GetObject(FPDF_PAGE page, |
| 201 | int index) { |
| 202 | CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage(); |
| 203 | if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") || |
| 204 | pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare( |
| 205 | "Page")) { |
| 206 | return NULL; |
| 207 | } |
| 208 | return pPage->GetObjectByIndex(index); |
| 209 | // return NULL; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 210 | } |
| 211 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 212 | DLLEXPORT FPDF_BOOL STDCALL FPDFPage_HasTransparency(FPDF_PAGE page) { |
| 213 | if (!page) |
| 214 | return FALSE; |
| 215 | CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage(); |
| 216 | if (!pPage) |
| 217 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 218 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 219 | return pPage->BackgroundAlphaNeeded(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 220 | } |
| 221 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 222 | DLLEXPORT FPDF_BOOL STDCALL |
| 223 | FPDFPageObj_HasTransparency(FPDF_PAGEOBJECT pageObject) { |
| 224 | if (!pageObject) |
| 225 | return FALSE; |
| 226 | CPDF_PageObject* pPageObj = (CPDF_PageObject*)pageObject; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 227 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 228 | const CPDF_GeneralStateData* pGeneralState = pPageObj->m_GeneralState; |
| 229 | int blend_type = |
| 230 | pGeneralState ? pGeneralState->m_BlendType : FXDIB_BLEND_NORMAL; |
| 231 | if (blend_type != FXDIB_BLEND_NORMAL) |
| 232 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 233 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 234 | CPDF_Dictionary* pSMaskDict = |
| 235 | pGeneralState ? (CPDF_Dictionary*)pGeneralState->m_pSoftMask : NULL; |
| 236 | if (pSMaskDict) |
| 237 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 238 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 239 | if (pGeneralState && pGeneralState->m_FillAlpha != 1.0f) |
| 240 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 241 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 242 | if (pPageObj->m_Type == PDFPAGE_PATH) { |
| 243 | if (pGeneralState && pGeneralState->m_StrokeAlpha != 1.0f) |
| 244 | return TRUE; |
| 245 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 246 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 247 | if (pPageObj->m_Type == PDFPAGE_FORM) { |
| 248 | CPDF_FormObject* pFormObj = (CPDF_FormObject*)pPageObj; |
| 249 | if (pFormObj->m_pForm && |
| 250 | (pFormObj->m_pForm->m_Transparency & PDFTRANS_ISOLATED)) |
| 251 | return TRUE; |
| 252 | if (pFormObj->m_pForm && |
| 253 | (!(pFormObj->m_pForm->m_Transparency & PDFTRANS_ISOLATED) && |
| 254 | (pFormObj->m_pForm->m_Transparency & PDFTRANS_GROUP))) |
| 255 | return TRUE; |
| 256 | } |
| 257 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 258 | } |
| 259 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 260 | DLLEXPORT FPDF_BOOL STDCALL FPDFPage_GenerateContent(FPDF_PAGE page) { |
| 261 | CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage(); |
| 262 | if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") || |
| 263 | !pPage->m_pFormDict->GetElement("Type")->GetDirect() || |
| 264 | pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare( |
| 265 | "Page")) { |
| 266 | return FALSE; |
| 267 | } |
| 268 | CPDF_PageContentGenerate CG(pPage); |
| 269 | CG.GenerateContent(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 270 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 271 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | DLLEXPORT void STDCALL FPDFPageObj_Transform(FPDF_PAGEOBJECT page_object, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 275 | double a, |
| 276 | double b, |
| 277 | double c, |
| 278 | double d, |
| 279 | double e, |
| 280 | double f) { |
| 281 | CPDF_PageObject* pPageObj = (CPDF_PageObject*)page_object; |
| 282 | if (pPageObj == NULL) |
| 283 | return; |
Lei Zhang | cb78ef5 | 2015-10-02 10:10:49 -0700 | [diff] [blame^] | 284 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 285 | CFX_AffineMatrix matrix((FX_FLOAT)a, (FX_FLOAT)b, (FX_FLOAT)c, (FX_FLOAT)d, |
| 286 | (FX_FLOAT)e, (FX_FLOAT)f); |
| 287 | pPageObj->Transform(matrix); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 288 | } |
| 289 | DLLEXPORT void STDCALL FPDFPage_TransformAnnots(FPDF_PAGE page, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 290 | double a, |
| 291 | double b, |
| 292 | double c, |
| 293 | double d, |
| 294 | double e, |
| 295 | double f) { |
| 296 | if (page == NULL) |
| 297 | return; |
| 298 | CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage(); |
| 299 | if (!pPage) |
| 300 | return; |
| 301 | CPDF_AnnotList AnnotList(pPage); |
| 302 | for (int i = 0; i < AnnotList.Count(); i++) { |
| 303 | CPDF_Annot* pAnnot = AnnotList.GetAt(i); |
| 304 | // transformAnnots Rectangle |
| 305 | CPDF_Rect rect; |
| 306 | pAnnot->GetRect(rect); |
| 307 | CFX_AffineMatrix matrix((FX_FLOAT)a, (FX_FLOAT)b, (FX_FLOAT)c, (FX_FLOAT)d, |
| 308 | (FX_FLOAT)e, (FX_FLOAT)f); |
| 309 | rect.Transform(&matrix); |
| 310 | CPDF_Array* pRectArray = NULL; |
| 311 | pRectArray = pAnnot->GetAnnotDict()->GetArray("Rect"); |
| 312 | if (!pRectArray) |
| 313 | pRectArray = CPDF_Array::Create(); |
| 314 | pRectArray->SetAt(0, new CPDF_Number(rect.left)); |
| 315 | pRectArray->SetAt(1, new CPDF_Number(rect.bottom)); |
| 316 | pRectArray->SetAt(2, new CPDF_Number(rect.right)); |
| 317 | pRectArray->SetAt(3, new CPDF_Number(rect.top)); |
| 318 | pAnnot->GetAnnotDict()->SetAt("Rect", pRectArray); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 319 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 320 | // Transform AP's rectangle |
| 321 | // To Do |
| 322 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 323 | } |
Bo Xu | 394010d | 2014-06-12 13:41:50 -0700 | [diff] [blame] | 324 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 325 | DLLEXPORT void STDCALL FPDFPage_SetRotation(FPDF_PAGE page, int rotate) { |
| 326 | if (page == NULL) |
| 327 | return; |
| 328 | CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage(); |
| 329 | if (!pPage) |
| 330 | return; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 331 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 332 | if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") || |
| 333 | !pPage->m_pFormDict->GetElement("Type")->GetDirect() || |
| 334 | pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare( |
| 335 | "Page")) { |
| 336 | return; |
| 337 | } |
| 338 | CPDF_Dictionary* pDict = pPage->m_pFormDict; |
| 339 | rotate %= 4; |
Bo Xu | 394010d | 2014-06-12 13:41:50 -0700 | [diff] [blame] | 340 | |
Tom Sepez | ae51c81 | 2015-08-05 12:34:06 -0700 | [diff] [blame] | 341 | pDict->SetAt("Rotate", new CPDF_Number(rotate * 90)); |
Nico Weber | 0ce77e3 | 2014-07-16 13:19:08 -0700 | [diff] [blame] | 342 | } |