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 | |
Lei Zhang | b4e7f30 | 2015-11-06 15:52:32 -0800 | [diff] [blame] | 7 | #include "public/fpdf_edit.h" |
| 8 | |
Tom Sepez | 310438f | 2016-03-08 13:10:55 -0800 | [diff] [blame^] | 9 | #include "core/include/fpdfapi/cpdf_document.h" |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 10 | #include "fpdfsdk/include/fsdk_define.h" |
| 11 | #include "public/fpdf_formfill.h" |
Tom Sepez | 2398d89 | 2016-02-17 16:46:26 -0800 | [diff] [blame] | 12 | #include "third_party/base/stl_util.h" |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 13 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 14 | #ifdef PDF_ENABLE_XFA |
Lei Zhang | 875b9c9 | 2016-01-08 13:51:10 -0800 | [diff] [blame] | 15 | #include "fpdfsdk/include/fpdfxfa/fpdfxfa_app.h" |
| 16 | #include "fpdfsdk/include/fpdfxfa/fpdfxfa_doc.h" |
| 17 | #include "fpdfsdk/include/fpdfxfa/fpdfxfa_page.h" |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 18 | #endif // PDF_ENABLE_XFA |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 19 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 20 | #if _FX_OS_ == _FX_ANDROID_ |
| 21 | #include "time.h" |
| 22 | #else |
| 23 | #include <ctime> |
| 24 | #endif |
| 25 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 26 | DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_CreateNewDocument() { |
Tom Sepez | ae51c81 | 2015-08-05 12:34:06 -0700 | [diff] [blame] | 27 | CPDF_Document* pDoc = new CPDF_Document; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 28 | pDoc->CreateNewDoc(); |
| 29 | time_t currentTime; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 30 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 31 | CFX_ByteString DateStr; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 32 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 33 | if (FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS)) { |
| 34 | if (-1 != time(¤tTime)) { |
| 35 | tm* pTM = localtime(¤tTime); |
| 36 | if (pTM) { |
| 37 | DateStr.Format("D:%04d%02d%02d%02d%02d%02d", pTM->tm_year + 1900, |
| 38 | pTM->tm_mon + 1, pTM->tm_mday, pTM->tm_hour, pTM->tm_min, |
| 39 | pTM->tm_sec); |
| 40 | } |
| 41 | } |
| 42 | } |
Tom Sepez | bdeeb8a | 2015-05-27 12:25:00 -0700 | [diff] [blame] | 43 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 44 | CPDF_Dictionary* pInfoDict = NULL; |
| 45 | pInfoDict = pDoc->GetInfo(); |
| 46 | if (pInfoDict) { |
| 47 | if (FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS)) |
Lei Zhang | 4880d1a | 2015-12-18 17:05:11 -0800 | [diff] [blame] | 48 | pInfoDict->SetAt("CreationDate", new CPDF_String(DateStr, FALSE)); |
Tom Sepez | ae51c81 | 2015-08-05 12:34:06 -0700 | [diff] [blame] | 49 | pInfoDict->SetAt("Creator", new CPDF_String(L"PDFium")); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 50 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 51 | |
Tom Sepez | bf59a07 | 2015-10-21 14:07:23 -0700 | [diff] [blame] | 52 | return FPDFDocumentFromCPDFDocument(pDoc); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 53 | } |
| 54 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 55 | DLLEXPORT void STDCALL FPDFPage_Delete(FPDF_DOCUMENT document, int page_index) { |
Tom Sepez | 471a103 | 2015-10-15 16:17:18 -0700 | [diff] [blame] | 56 | CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
| 57 | if (!pDoc || page_index < 0 || page_index >= pDoc->GetPageCount()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 58 | return; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 59 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 60 | pDoc->DeletePage(page_index); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 61 | } |
| 62 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 63 | DLLEXPORT FPDF_PAGE STDCALL FPDFPage_New(FPDF_DOCUMENT document, |
| 64 | int page_index, |
| 65 | double width, |
| 66 | double height) { |
Tom Sepez | 471a103 | 2015-10-15 16:17:18 -0700 | [diff] [blame] | 67 | CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
| 68 | if (!pDoc) |
| 69 | return nullptr; |
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 | if (page_index < 0) |
| 72 | page_index = 0; |
| 73 | if (pDoc->GetPageCount() < page_index) |
| 74 | page_index = pDoc->GetPageCount(); |
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 | |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 89 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 90 | CPDFXFA_Page* pPage = |
Tom Sepez | ae51c81 | 2015-08-05 12:34:06 -0700 | [diff] [blame] | 91 | new CPDFXFA_Page((CPDFXFA_Document*)document, page_index); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 92 | pPage->LoadPDFPage(pPageDict); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 93 | #else // PDF_ENABLE_XFA |
| 94 | CPDF_Page* pPage = new CPDF_Page; |
| 95 | pPage->Load(pDoc, pPageDict); |
Tom Sepez | b5b2a91 | 2016-01-21 11:04:37 -0800 | [diff] [blame] | 96 | pPage->ParseContent(nullptr); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 97 | #endif // PDF_ENABLE_XFA |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 98 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 99 | return pPage; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 100 | } |
| 101 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 102 | DLLEXPORT int STDCALL FPDFPage_GetRotation(FPDF_PAGE page) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 103 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 104 | if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") || |
| 105 | !pPage->m_pFormDict->GetElement("Type")->GetDirect() || |
| 106 | pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare( |
| 107 | "Page")) { |
| 108 | return -1; |
| 109 | } |
| 110 | CPDF_Dictionary* pDict = pPage->m_pFormDict; |
Lei Zhang | 997de61 | 2015-11-04 18:17:53 -0800 | [diff] [blame] | 111 | if (!pDict) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 112 | return -1; |
Lei Zhang | 997de61 | 2015-11-04 18:17:53 -0800 | [diff] [blame] | 113 | |
| 114 | while (pDict) { |
| 115 | if (pDict->KeyExist("Rotate")) { |
| 116 | CPDF_Object* pRotateObj = pDict->GetElement("Rotate")->GetDirect(); |
| 117 | return pRotateObj ? pRotateObj->GetInteger() / 90 : 0; |
| 118 | } |
| 119 | if (!pDict->KeyExist("Parent")) |
| 120 | break; |
| 121 | |
| 122 | pDict = ToDictionary(pDict->GetElement("Parent")->GetDirect()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 123 | } |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 124 | |
Lei Zhang | 997de61 | 2015-11-04 18:17:53 -0800 | [diff] [blame] | 125 | return 0; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 126 | } |
| 127 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 128 | DLLEXPORT void STDCALL FPDFPage_InsertObject(FPDF_PAGE page, |
| 129 | FPDF_PAGEOBJECT page_obj) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 130 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 131 | if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") || |
| 132 | !pPage->m_pFormDict->GetElement("Type")->GetDirect() || |
| 133 | pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare( |
| 134 | "Page")) { |
| 135 | return; |
| 136 | } |
| 137 | CPDF_PageObject* pPageObj = (CPDF_PageObject*)page_obj; |
Lei Zhang | 997de61 | 2015-11-04 18:17:53 -0800 | [diff] [blame] | 138 | if (!pPageObj) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 139 | return; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 140 | |
Tom Sepez | 2398d89 | 2016-02-17 16:46:26 -0800 | [diff] [blame] | 141 | pPage->GetPageObjectList()->push_back( |
| 142 | std::unique_ptr<CPDF_PageObject>(pPageObj)); |
| 143 | |
Wei Li | 7cf13c9 | 2016-02-19 11:53:03 -0800 | [diff] [blame] | 144 | switch (pPageObj->GetType()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 145 | case FPDF_PAGEOBJ_PATH: { |
Wei Li | 7cf13c9 | 2016-02-19 11:53:03 -0800 | [diff] [blame] | 146 | CPDF_PathObject* pPathObj = pPageObj->AsPath(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 147 | pPathObj->CalcBoundingBox(); |
| 148 | break; |
| 149 | } |
| 150 | case FPDF_PAGEOBJ_TEXT: { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 151 | break; |
| 152 | } |
| 153 | case FPDF_PAGEOBJ_IMAGE: { |
Wei Li | 7cf13c9 | 2016-02-19 11:53:03 -0800 | [diff] [blame] | 154 | CPDF_ImageObject* pImageObj = pPageObj->AsImage(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 155 | pImageObj->CalcBoundingBox(); |
| 156 | break; |
| 157 | } |
| 158 | case FPDF_PAGEOBJ_SHADING: { |
Wei Li | 7cf13c9 | 2016-02-19 11:53:03 -0800 | [diff] [blame] | 159 | CPDF_ShadingObject* pShadingObj = pPageObj->AsShading(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 160 | pShadingObj->CalcBoundingBox(); |
| 161 | break; |
| 162 | } |
| 163 | case FPDF_PAGEOBJ_FORM: { |
Wei Li | 7cf13c9 | 2016-02-19 11:53:03 -0800 | [diff] [blame] | 164 | CPDF_FormObject* pFormObj = pPageObj->AsForm(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 165 | pFormObj->CalcBoundingBox(); |
| 166 | break; |
| 167 | } |
| 168 | default: |
| 169 | break; |
| 170 | } |
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 int STDCALL FPDFPage_CountObject(FPDF_PAGE page) { |
Tom Sepez | bf59a07 | 2015-10-21 14:07:23 -0700 | [diff] [blame] | 174 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 175 | if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") || |
| 176 | !pPage->m_pFormDict->GetElement("Type")->GetDirect() || |
| 177 | pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare( |
| 178 | "Page")) { |
| 179 | return -1; |
| 180 | } |
Tom Sepez | 2398d89 | 2016-02-17 16:46:26 -0800 | [diff] [blame] | 181 | return pdfium::CollectionSize<int>(*pPage->GetPageObjectList()); |
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_PAGEOBJECT STDCALL FPDFPage_GetObject(FPDF_PAGE page, |
| 185 | int index) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 186 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 187 | if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") || |
| 188 | pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare( |
| 189 | "Page")) { |
Tom Sepez | 2398d89 | 2016-02-17 16:46:26 -0800 | [diff] [blame] | 190 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 191 | } |
Tom Sepez | 2398d89 | 2016-02-17 16:46:26 -0800 | [diff] [blame] | 192 | return pPage->GetPageObjectList()->GetPageObjectByIndex(index); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 193 | } |
| 194 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 195 | DLLEXPORT FPDF_BOOL STDCALL FPDFPage_HasTransparency(FPDF_PAGE page) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 196 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
| 197 | return pPage && pPage->BackgroundAlphaNeeded(); |
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 |
| 201 | FPDFPageObj_HasTransparency(FPDF_PAGEOBJECT pageObject) { |
| 202 | if (!pageObject) |
| 203 | return FALSE; |
| 204 | CPDF_PageObject* pPageObj = (CPDF_PageObject*)pageObject; |
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 | const CPDF_GeneralStateData* pGeneralState = pPageObj->m_GeneralState; |
| 207 | int blend_type = |
| 208 | pGeneralState ? pGeneralState->m_BlendType : FXDIB_BLEND_NORMAL; |
| 209 | if (blend_type != FXDIB_BLEND_NORMAL) |
| 210 | return TRUE; |
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 | CPDF_Dictionary* pSMaskDict = |
Dan Sinclair | f1251c1 | 2015-10-20 16:24:45 -0400 | [diff] [blame] | 213 | pGeneralState ? ToDictionary(pGeneralState->m_pSoftMask) : NULL; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 214 | if (pSMaskDict) |
| 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 | if (pGeneralState && pGeneralState->m_FillAlpha != 1.0f) |
| 218 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 219 | |
Wei Li | 7cf13c9 | 2016-02-19 11:53:03 -0800 | [diff] [blame] | 220 | if (pPageObj->IsPath()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 221 | if (pGeneralState && pGeneralState->m_StrokeAlpha != 1.0f) |
| 222 | return TRUE; |
| 223 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 224 | |
Wei Li | 7cf13c9 | 2016-02-19 11:53:03 -0800 | [diff] [blame] | 225 | if (pPageObj->IsForm()) { |
| 226 | CPDF_FormObject* pFormObj = pPageObj->AsForm(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 227 | if (pFormObj->m_pForm && |
| 228 | (pFormObj->m_pForm->m_Transparency & PDFTRANS_ISOLATED)) |
| 229 | return TRUE; |
| 230 | if (pFormObj->m_pForm && |
| 231 | (!(pFormObj->m_pForm->m_Transparency & PDFTRANS_ISOLATED) && |
| 232 | (pFormObj->m_pForm->m_Transparency & PDFTRANS_GROUP))) |
| 233 | return TRUE; |
| 234 | } |
| 235 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 236 | } |
| 237 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 238 | DLLEXPORT FPDF_BOOL STDCALL FPDFPage_GenerateContent(FPDF_PAGE page) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 239 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 240 | if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") || |
| 241 | !pPage->m_pFormDict->GetElement("Type")->GetDirect() || |
| 242 | pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare( |
| 243 | "Page")) { |
| 244 | return FALSE; |
| 245 | } |
Tom Sepez | e19e06e | 2016-01-21 10:49:56 -0800 | [diff] [blame] | 246 | CPDF_PageContentGenerator CG(pPage); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 247 | CG.GenerateContent(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 248 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 249 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | DLLEXPORT void STDCALL FPDFPageObj_Transform(FPDF_PAGEOBJECT page_object, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 253 | double a, |
| 254 | double b, |
| 255 | double c, |
| 256 | double d, |
| 257 | double e, |
| 258 | double f) { |
| 259 | CPDF_PageObject* pPageObj = (CPDF_PageObject*)page_object; |
Lei Zhang | 997de61 | 2015-11-04 18:17:53 -0800 | [diff] [blame] | 260 | if (!pPageObj) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 261 | return; |
Lei Zhang | cb78ef5 | 2015-10-02 10:10:49 -0700 | [diff] [blame] | 262 | |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 263 | CFX_Matrix matrix((FX_FLOAT)a, (FX_FLOAT)b, (FX_FLOAT)c, (FX_FLOAT)d, |
| 264 | (FX_FLOAT)e, (FX_FLOAT)f); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 265 | pPageObj->Transform(matrix); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 266 | } |
| 267 | DLLEXPORT void STDCALL FPDFPage_TransformAnnots(FPDF_PAGE page, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 268 | double a, |
| 269 | double b, |
| 270 | double c, |
| 271 | double d, |
| 272 | double e, |
| 273 | double f) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 274 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 275 | if (!pPage) |
| 276 | return; |
| 277 | CPDF_AnnotList AnnotList(pPage); |
Lei Zhang | 1b700c3 | 2015-10-30 23:55:35 -0700 | [diff] [blame] | 278 | for (size_t i = 0; i < AnnotList.Count(); ++i) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 279 | CPDF_Annot* pAnnot = AnnotList.GetAt(i); |
| 280 | // transformAnnots Rectangle |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 281 | CFX_FloatRect rect; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 282 | pAnnot->GetRect(rect); |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 283 | CFX_Matrix matrix((FX_FLOAT)a, (FX_FLOAT)b, (FX_FLOAT)c, (FX_FLOAT)d, |
| 284 | (FX_FLOAT)e, (FX_FLOAT)f); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 285 | rect.Transform(&matrix); |
| 286 | CPDF_Array* pRectArray = NULL; |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 287 | pRectArray = pAnnot->GetAnnotDict()->GetArrayBy("Rect"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 288 | if (!pRectArray) |
Lei Zhang | 4880d1a | 2015-12-18 17:05:11 -0800 | [diff] [blame] | 289 | pRectArray = new CPDF_Array; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 290 | pRectArray->SetAt(0, new CPDF_Number(rect.left)); |
| 291 | pRectArray->SetAt(1, new CPDF_Number(rect.bottom)); |
| 292 | pRectArray->SetAt(2, new CPDF_Number(rect.right)); |
| 293 | pRectArray->SetAt(3, new CPDF_Number(rect.top)); |
| 294 | pAnnot->GetAnnotDict()->SetAt("Rect", pRectArray); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 295 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 296 | // Transform AP's rectangle |
| 297 | // To Do |
| 298 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 299 | } |
Bo Xu | 394010d | 2014-06-12 13:41:50 -0700 | [diff] [blame] | 300 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 301 | DLLEXPORT void STDCALL FPDFPage_SetRotation(FPDF_PAGE page, int rotate) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 302 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 303 | if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") || |
| 304 | !pPage->m_pFormDict->GetElement("Type")->GetDirect() || |
| 305 | pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare( |
| 306 | "Page")) { |
| 307 | return; |
| 308 | } |
| 309 | CPDF_Dictionary* pDict = pPage->m_pFormDict; |
| 310 | rotate %= 4; |
Bo Xu | 394010d | 2014-06-12 13:41:50 -0700 | [diff] [blame] | 311 | |
Tom Sepez | ae51c81 | 2015-08-05 12:34:06 -0700 | [diff] [blame] | 312 | pDict->SetAt("Rotate", new CPDF_Number(rotate * 90)); |
Nico Weber | 0ce77e3 | 2014-07-16 13:19:08 -0700 | [diff] [blame] | 313 | } |