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; |
Lei Zhang | 997de61 | 2015-11-04 18:17:53 -0800 | [diff] [blame^] | 99 | if (!pDict) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 100 | return -1; |
Lei Zhang | 997de61 | 2015-11-04 18:17:53 -0800 | [diff] [blame^] | 101 | |
| 102 | while (pDict) { |
| 103 | if (pDict->KeyExist("Rotate")) { |
| 104 | CPDF_Object* pRotateObj = pDict->GetElement("Rotate")->GetDirect(); |
| 105 | return pRotateObj ? pRotateObj->GetInteger() / 90 : 0; |
| 106 | } |
| 107 | if (!pDict->KeyExist("Parent")) |
| 108 | break; |
| 109 | |
| 110 | pDict = ToDictionary(pDict->GetElement("Parent")->GetDirect()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 111 | } |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 112 | |
Lei Zhang | 997de61 | 2015-11-04 18:17:53 -0800 | [diff] [blame^] | 113 | return 0; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 114 | } |
| 115 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 116 | DLLEXPORT void STDCALL FPDFPage_InsertObject(FPDF_PAGE page, |
| 117 | FPDF_PAGEOBJECT page_obj) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 118 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 119 | if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") || |
| 120 | !pPage->m_pFormDict->GetElement("Type")->GetDirect() || |
| 121 | pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare( |
| 122 | "Page")) { |
| 123 | return; |
| 124 | } |
| 125 | CPDF_PageObject* pPageObj = (CPDF_PageObject*)page_obj; |
Lei Zhang | 997de61 | 2015-11-04 18:17:53 -0800 | [diff] [blame^] | 126 | if (!pPageObj) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 127 | return; |
| 128 | FX_POSITION LastPersition = pPage->GetLastObjectPosition(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 129 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 130 | pPage->InsertObject(LastPersition, pPageObj); |
| 131 | switch (pPageObj->m_Type) { |
| 132 | case FPDF_PAGEOBJ_PATH: { |
| 133 | CPDF_PathObject* pPathObj = (CPDF_PathObject*)pPageObj; |
| 134 | pPathObj->CalcBoundingBox(); |
| 135 | break; |
| 136 | } |
| 137 | case FPDF_PAGEOBJ_TEXT: { |
| 138 | // CPDF_PathObject* pPathObj = (CPDF_PathObject*)pPageObj; |
| 139 | // pPathObj->CalcBoundingBox(); |
| 140 | break; |
| 141 | } |
| 142 | case FPDF_PAGEOBJ_IMAGE: { |
| 143 | CPDF_ImageObject* pImageObj = (CPDF_ImageObject*)pPageObj; |
| 144 | pImageObj->CalcBoundingBox(); |
| 145 | break; |
| 146 | } |
| 147 | case FPDF_PAGEOBJ_SHADING: { |
| 148 | CPDF_ShadingObject* pShadingObj = (CPDF_ShadingObject*)pPageObj; |
| 149 | pShadingObj->CalcBoundingBox(); |
| 150 | break; |
| 151 | } |
| 152 | case FPDF_PAGEOBJ_FORM: { |
| 153 | CPDF_FormObject* pFormObj = (CPDF_FormObject*)pPageObj; |
| 154 | pFormObj->CalcBoundingBox(); |
| 155 | break; |
| 156 | } |
| 157 | default: |
| 158 | break; |
| 159 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 160 | } |
| 161 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 162 | DLLEXPORT int STDCALL FPDFPage_CountObject(FPDF_PAGE page) { |
Tom Sepez | bf59a07 | 2015-10-21 14:07:23 -0700 | [diff] [blame] | 163 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 164 | if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") || |
| 165 | !pPage->m_pFormDict->GetElement("Type")->GetDirect() || |
| 166 | pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare( |
| 167 | "Page")) { |
| 168 | return -1; |
| 169 | } |
| 170 | return pPage->CountObjects(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 171 | } |
| 172 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 173 | DLLEXPORT FPDF_PAGEOBJECT STDCALL FPDFPage_GetObject(FPDF_PAGE page, |
| 174 | int index) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 175 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 176 | if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") || |
| 177 | pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare( |
| 178 | "Page")) { |
| 179 | return NULL; |
| 180 | } |
| 181 | return pPage->GetObjectByIndex(index); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 182 | } |
| 183 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 184 | DLLEXPORT FPDF_BOOL STDCALL FPDFPage_HasTransparency(FPDF_PAGE page) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 185 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
| 186 | return pPage && pPage->BackgroundAlphaNeeded(); |
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_BOOL STDCALL |
| 190 | FPDFPageObj_HasTransparency(FPDF_PAGEOBJECT pageObject) { |
| 191 | if (!pageObject) |
| 192 | return FALSE; |
| 193 | CPDF_PageObject* pPageObj = (CPDF_PageObject*)pageObject; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 194 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 195 | const CPDF_GeneralStateData* pGeneralState = pPageObj->m_GeneralState; |
| 196 | int blend_type = |
| 197 | pGeneralState ? pGeneralState->m_BlendType : FXDIB_BLEND_NORMAL; |
| 198 | if (blend_type != FXDIB_BLEND_NORMAL) |
| 199 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 200 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 201 | CPDF_Dictionary* pSMaskDict = |
Dan Sinclair | f1251c1 | 2015-10-20 16:24:45 -0400 | [diff] [blame] | 202 | pGeneralState ? ToDictionary(pGeneralState->m_pSoftMask) : NULL; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 203 | if (pSMaskDict) |
| 204 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 205 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 206 | if (pGeneralState && pGeneralState->m_FillAlpha != 1.0f) |
| 207 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 208 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 209 | if (pPageObj->m_Type == PDFPAGE_PATH) { |
| 210 | if (pGeneralState && pGeneralState->m_StrokeAlpha != 1.0f) |
| 211 | return TRUE; |
| 212 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 213 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 214 | if (pPageObj->m_Type == PDFPAGE_FORM) { |
| 215 | CPDF_FormObject* pFormObj = (CPDF_FormObject*)pPageObj; |
| 216 | if (pFormObj->m_pForm && |
| 217 | (pFormObj->m_pForm->m_Transparency & PDFTRANS_ISOLATED)) |
| 218 | return TRUE; |
| 219 | if (pFormObj->m_pForm && |
| 220 | (!(pFormObj->m_pForm->m_Transparency & PDFTRANS_ISOLATED) && |
| 221 | (pFormObj->m_pForm->m_Transparency & PDFTRANS_GROUP))) |
| 222 | return TRUE; |
| 223 | } |
| 224 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 225 | } |
| 226 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 227 | DLLEXPORT FPDF_BOOL STDCALL FPDFPage_GenerateContent(FPDF_PAGE page) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 228 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 229 | if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") || |
| 230 | !pPage->m_pFormDict->GetElement("Type")->GetDirect() || |
| 231 | pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare( |
| 232 | "Page")) { |
| 233 | return FALSE; |
| 234 | } |
| 235 | CPDF_PageContentGenerate CG(pPage); |
| 236 | CG.GenerateContent(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 237 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 238 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | DLLEXPORT void STDCALL FPDFPageObj_Transform(FPDF_PAGEOBJECT page_object, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 242 | double a, |
| 243 | double b, |
| 244 | double c, |
| 245 | double d, |
| 246 | double e, |
| 247 | double f) { |
| 248 | CPDF_PageObject* pPageObj = (CPDF_PageObject*)page_object; |
Lei Zhang | 997de61 | 2015-11-04 18:17:53 -0800 | [diff] [blame^] | 249 | if (!pPageObj) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 250 | return; |
Lei Zhang | cb78ef5 | 2015-10-02 10:10:49 -0700 | [diff] [blame] | 251 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 252 | CFX_AffineMatrix matrix((FX_FLOAT)a, (FX_FLOAT)b, (FX_FLOAT)c, (FX_FLOAT)d, |
| 253 | (FX_FLOAT)e, (FX_FLOAT)f); |
| 254 | pPageObj->Transform(matrix); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 255 | } |
| 256 | DLLEXPORT void STDCALL FPDFPage_TransformAnnots(FPDF_PAGE page, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 257 | double a, |
| 258 | double b, |
| 259 | double c, |
| 260 | double d, |
| 261 | double e, |
| 262 | double f) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 263 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 264 | if (!pPage) |
| 265 | return; |
| 266 | CPDF_AnnotList AnnotList(pPage); |
Lei Zhang | 1b700c3 | 2015-10-30 23:55:35 -0700 | [diff] [blame] | 267 | for (size_t i = 0; i < AnnotList.Count(); ++i) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 268 | CPDF_Annot* pAnnot = AnnotList.GetAt(i); |
| 269 | // transformAnnots Rectangle |
| 270 | CPDF_Rect rect; |
| 271 | pAnnot->GetRect(rect); |
| 272 | CFX_AffineMatrix matrix((FX_FLOAT)a, (FX_FLOAT)b, (FX_FLOAT)c, (FX_FLOAT)d, |
| 273 | (FX_FLOAT)e, (FX_FLOAT)f); |
| 274 | rect.Transform(&matrix); |
| 275 | CPDF_Array* pRectArray = NULL; |
| 276 | pRectArray = pAnnot->GetAnnotDict()->GetArray("Rect"); |
| 277 | if (!pRectArray) |
| 278 | pRectArray = CPDF_Array::Create(); |
| 279 | pRectArray->SetAt(0, new CPDF_Number(rect.left)); |
| 280 | pRectArray->SetAt(1, new CPDF_Number(rect.bottom)); |
| 281 | pRectArray->SetAt(2, new CPDF_Number(rect.right)); |
| 282 | pRectArray->SetAt(3, new CPDF_Number(rect.top)); |
| 283 | pAnnot->GetAnnotDict()->SetAt("Rect", pRectArray); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 284 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 285 | // Transform AP's rectangle |
| 286 | // To Do |
| 287 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 288 | } |
Bo Xu | 394010d | 2014-06-12 13:41:50 -0700 | [diff] [blame] | 289 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 290 | DLLEXPORT void STDCALL FPDFPage_SetRotation(FPDF_PAGE page, int rotate) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 291 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 292 | if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") || |
| 293 | !pPage->m_pFormDict->GetElement("Type")->GetDirect() || |
| 294 | pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare( |
| 295 | "Page")) { |
| 296 | return; |
| 297 | } |
| 298 | CPDF_Dictionary* pDict = pPage->m_pFormDict; |
| 299 | rotate %= 4; |
Bo Xu | 394010d | 2014-06-12 13:41:50 -0700 | [diff] [blame] | 300 | |
Tom Sepez | ae51c81 | 2015-08-05 12:34:06 -0700 | [diff] [blame] | 301 | pDict->SetAt("Rotate", new CPDF_Number(rotate * 90)); |
Nico Weber | 0ce77e3 | 2014-07-16 13:19:08 -0700 | [diff] [blame] | 302 | } |