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