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