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 | |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 9 | #include <algorithm> |
| 10 | #include <memory> |
| 11 | #include <utility> |
| 12 | |
dsinclair | 2415435 | 2016-10-04 11:01:48 -0700 | [diff] [blame] | 13 | #include "core/fpdfapi/edit/cpdf_pagecontentgenerator.h" |
dsinclair | 41872fa | 2016-10-04 11:29:35 -0700 | [diff] [blame] | 14 | #include "core/fpdfapi/page/cpdf_form.h" |
| 15 | #include "core/fpdfapi/page/cpdf_formobject.h" |
| 16 | #include "core/fpdfapi/page/cpdf_imageobject.h" |
| 17 | #include "core/fpdfapi/page/cpdf_page.h" |
| 18 | #include "core/fpdfapi/page/cpdf_pageobject.h" |
| 19 | #include "core/fpdfapi/page/cpdf_pathobject.h" |
| 20 | #include "core/fpdfapi/page/cpdf_shadingobject.h" |
dsinclair | 488b7ad | 2016-10-04 11:55:50 -0700 | [diff] [blame] | 21 | #include "core/fpdfapi/parser/cpdf_array.h" |
| 22 | #include "core/fpdfapi/parser/cpdf_document.h" |
| 23 | #include "core/fpdfapi/parser/cpdf_number.h" |
| 24 | #include "core/fpdfapi/parser/cpdf_string.h" |
dsinclair | 1727aee | 2016-09-29 13:12:56 -0700 | [diff] [blame] | 25 | #include "core/fpdfdoc/cpdf_annot.h" |
| 26 | #include "core/fpdfdoc/cpdf_annotlist.h" |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 27 | #include "fpdfsdk/fsdk_define.h" |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 28 | #include "public/fpdf_formfill.h" |
Tom Sepez | 2398d89 | 2016-02-17 16:46:26 -0800 | [diff] [blame] | 29 | #include "third_party/base/stl_util.h" |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 30 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 31 | #ifdef PDF_ENABLE_XFA |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 32 | #include "fpdfsdk/fpdfxfa/cpdfxfa_context.h" |
dsinclair | 4d29e78 | 2016-10-04 14:02:47 -0700 | [diff] [blame] | 33 | #include "fpdfsdk/fpdfxfa/cpdfxfa_page.h" |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 34 | #endif // PDF_ENABLE_XFA |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 35 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 36 | #if _FX_OS_ == _FX_ANDROID_ |
Dan Sinclair | 85c8e7f | 2016-11-21 13:50:32 -0500 | [diff] [blame] | 37 | #include <time.h> |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 38 | #else |
| 39 | #include <ctime> |
| 40 | #endif |
| 41 | |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 42 | namespace { |
| 43 | |
| 44 | static_assert(FPDF_PAGEOBJ_TEXT == CPDF_PageObject::TEXT, |
| 45 | "FPDF_PAGEOBJ_TEXT/CPDF_PageObject::TEXT mismatch"); |
| 46 | static_assert(FPDF_PAGEOBJ_PATH == CPDF_PageObject::PATH, |
| 47 | "FPDF_PAGEOBJ_PATH/CPDF_PageObject::PATH mismatch"); |
| 48 | static_assert(FPDF_PAGEOBJ_IMAGE == CPDF_PageObject::IMAGE, |
| 49 | "FPDF_PAGEOBJ_IMAGE/CPDF_PageObject::IMAGE mismatch"); |
| 50 | static_assert(FPDF_PAGEOBJ_SHADING == CPDF_PageObject::SHADING, |
| 51 | "FPDF_PAGEOBJ_SHADING/CPDF_PageObject::SHADING mismatch"); |
| 52 | static_assert(FPDF_PAGEOBJ_FORM == CPDF_PageObject::FORM, |
| 53 | "FPDF_PAGEOBJ_FORM/CPDF_PageObject::FORM mismatch"); |
| 54 | |
| 55 | bool IsPageObject(CPDF_Page* pPage) { |
| 56 | if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type")) |
| 57 | return false; |
| 58 | |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 59 | CPDF_Object* pObject = pPage->m_pFormDict->GetObjectFor("Type")->GetDirect(); |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 60 | return pObject && !pObject->GetString().Compare("Page"); |
| 61 | } |
| 62 | |
| 63 | } // namespace |
| 64 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 65 | DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_CreateNewDocument() { |
thestig | 931bf37 | 2016-04-26 22:24:30 -0700 | [diff] [blame] | 66 | CPDF_Document* pDoc = new CPDF_Document(nullptr); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 67 | pDoc->CreateNewDoc(); |
| 68 | time_t currentTime; |
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 | CFX_ByteString DateStr; |
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 (FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS)) { |
| 73 | if (-1 != time(¤tTime)) { |
| 74 | tm* pTM = localtime(¤tTime); |
| 75 | if (pTM) { |
| 76 | DateStr.Format("D:%04d%02d%02d%02d%02d%02d", pTM->tm_year + 1900, |
| 77 | pTM->tm_mon + 1, pTM->tm_mday, pTM->tm_hour, pTM->tm_min, |
| 78 | pTM->tm_sec); |
| 79 | } |
| 80 | } |
| 81 | } |
Tom Sepez | bdeeb8a | 2015-05-27 12:25:00 -0700 | [diff] [blame] | 82 | |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 83 | CPDF_Dictionary* pInfoDict = nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 84 | pInfoDict = pDoc->GetInfo(); |
| 85 | if (pInfoDict) { |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 86 | if (FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS)) |
| 87 | pInfoDict->SetNewFor<CPDF_String>("CreationDate", DateStr, false); |
| 88 | pInfoDict->SetNewFor<CPDF_String>("Creator", L"PDFium"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 89 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 90 | |
Tom Sepez | bf59a07 | 2015-10-21 14:07:23 -0700 | [diff] [blame] | 91 | return FPDFDocumentFromCPDFDocument(pDoc); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 92 | } |
| 93 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 94 | DLLEXPORT void STDCALL FPDFPage_Delete(FPDF_DOCUMENT document, int page_index) { |
Tom Sepez | 744da70 | 2016-03-15 12:43:09 -0700 | [diff] [blame] | 95 | if (UnderlyingDocumentType* pDoc = UnderlyingFromFPDFDocument(document)) |
| 96 | pDoc->DeletePage(page_index); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 97 | } |
| 98 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 99 | DLLEXPORT FPDF_PAGE STDCALL FPDFPage_New(FPDF_DOCUMENT document, |
| 100 | int page_index, |
| 101 | double width, |
| 102 | double height) { |
Tom Sepez | 471a103 | 2015-10-15 16:17:18 -0700 | [diff] [blame] | 103 | CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
| 104 | if (!pDoc) |
| 105 | return nullptr; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 106 | |
Lei Zhang | 85f019a | 2017-03-17 15:14:19 -0700 | [diff] [blame] | 107 | page_index = pdfium::clamp(page_index, 0, pDoc->GetPageCount()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 108 | CPDF_Dictionary* pPageDict = pDoc->CreateNewPage(page_index); |
| 109 | if (!pPageDict) |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 110 | return nullptr; |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 111 | |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 112 | CPDF_Array* pMediaBoxArray = pPageDict->SetNewFor<CPDF_Array>("MediaBox"); |
tsepez | 8a3aa45 | 2016-11-16 12:26:06 -0800 | [diff] [blame] | 113 | pMediaBoxArray->AddNew<CPDF_Number>(0); |
| 114 | pMediaBoxArray->AddNew<CPDF_Number>(0); |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 115 | pMediaBoxArray->AddNew<CPDF_Number>(static_cast<float>(width)); |
| 116 | pMediaBoxArray->AddNew<CPDF_Number>(static_cast<float>(height)); |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 117 | pPageDict->SetNewFor<CPDF_Number>("Rotate", 0); |
| 118 | pPageDict->SetNewFor<CPDF_Dictionary>("Resources"); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 119 | |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 120 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 121 | CPDFXFA_Page* pPage = |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 122 | new CPDFXFA_Page(static_cast<CPDFXFA_Context*>(document), page_index); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 123 | pPage->LoadPDFPage(pPageDict); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 124 | #else // PDF_ENABLE_XFA |
thestig | 5cc2465 | 2016-04-26 11:46:02 -0700 | [diff] [blame] | 125 | CPDF_Page* pPage = new CPDF_Page(pDoc, pPageDict, true); |
| 126 | pPage->ParseContent(); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 127 | #endif // PDF_ENABLE_XFA |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 128 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 129 | return pPage; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 130 | } |
| 131 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 132 | DLLEXPORT int STDCALL FPDFPage_GetRotation(FPDF_PAGE page) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 133 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 134 | if (!IsPageObject(pPage)) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 135 | return -1; |
Lei Zhang | 997de61 | 2015-11-04 18:17:53 -0800 | [diff] [blame] | 136 | |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 137 | CPDF_Dictionary* pDict = pPage->m_pFormDict; |
Lei Zhang | 997de61 | 2015-11-04 18:17:53 -0800 | [diff] [blame] | 138 | while (pDict) { |
| 139 | if (pDict->KeyExist("Rotate")) { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 140 | CPDF_Object* pRotateObj = pDict->GetObjectFor("Rotate")->GetDirect(); |
Lei Zhang | 997de61 | 2015-11-04 18:17:53 -0800 | [diff] [blame] | 141 | return pRotateObj ? pRotateObj->GetInteger() / 90 : 0; |
| 142 | } |
| 143 | if (!pDict->KeyExist("Parent")) |
| 144 | break; |
| 145 | |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 146 | pDict = ToDictionary(pDict->GetObjectFor("Parent")->GetDirect()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 147 | } |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 148 | |
Lei Zhang | 997de61 | 2015-11-04 18:17:53 -0800 | [diff] [blame] | 149 | return 0; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 150 | } |
| 151 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 152 | DLLEXPORT void STDCALL FPDFPage_InsertObject(FPDF_PAGE page, |
| 153 | FPDF_PAGEOBJECT page_obj) { |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 154 | CPDF_PageObject* pPageObj = reinterpret_cast<CPDF_PageObject*>(page_obj); |
Lei Zhang | 997de61 | 2015-11-04 18:17:53 -0800 | [diff] [blame] | 155 | if (!pPageObj) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 156 | return; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 157 | |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 158 | std::unique_ptr<CPDF_PageObject> pPageObjHolder(pPageObj); |
| 159 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
| 160 | if (!IsPageObject(pPage)) |
| 161 | return; |
Tom Sepez | 2398d89 | 2016-02-17 16:46:26 -0800 | [diff] [blame] | 162 | |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 163 | pPage->GetPageObjectList()->push_back(std::move(pPageObjHolder)); |
Wei Li | 7cf13c9 | 2016-02-19 11:53:03 -0800 | [diff] [blame] | 164 | switch (pPageObj->GetType()) { |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 165 | case CPDF_PageObject::TEXT: { |
| 166 | break; |
| 167 | } |
| 168 | case CPDF_PageObject::PATH: { |
Wei Li | 7cf13c9 | 2016-02-19 11:53:03 -0800 | [diff] [blame] | 169 | CPDF_PathObject* pPathObj = pPageObj->AsPath(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 170 | pPathObj->CalcBoundingBox(); |
| 171 | break; |
| 172 | } |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 173 | case CPDF_PageObject::IMAGE: { |
Wei Li | 7cf13c9 | 2016-02-19 11:53:03 -0800 | [diff] [blame] | 174 | CPDF_ImageObject* pImageObj = pPageObj->AsImage(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 175 | pImageObj->CalcBoundingBox(); |
| 176 | break; |
| 177 | } |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 178 | case CPDF_PageObject::SHADING: { |
Wei Li | 7cf13c9 | 2016-02-19 11:53:03 -0800 | [diff] [blame] | 179 | CPDF_ShadingObject* pShadingObj = pPageObj->AsShading(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 180 | pShadingObj->CalcBoundingBox(); |
| 181 | break; |
| 182 | } |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 183 | case CPDF_PageObject::FORM: { |
Wei Li | 7cf13c9 | 2016-02-19 11:53:03 -0800 | [diff] [blame] | 184 | CPDF_FormObject* pFormObj = pPageObj->AsForm(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 185 | pFormObj->CalcBoundingBox(); |
| 186 | break; |
| 187 | } |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 188 | default: { |
| 189 | ASSERT(false); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 190 | break; |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 191 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 192 | } |
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 int STDCALL FPDFPage_CountObject(FPDF_PAGE page) { |
Tom Sepez | bf59a07 | 2015-10-21 14:07:23 -0700 | [diff] [blame] | 196 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 197 | if (!IsPageObject(pPage)) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 198 | return -1; |
Tom Sepez | 2398d89 | 2016-02-17 16:46:26 -0800 | [diff] [blame] | 199 | return pdfium::CollectionSize<int>(*pPage->GetPageObjectList()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 200 | } |
| 201 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 202 | DLLEXPORT FPDF_PAGEOBJECT STDCALL FPDFPage_GetObject(FPDF_PAGE page, |
| 203 | int index) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 204 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 205 | if (!IsPageObject(pPage)) |
Tom Sepez | 2398d89 | 2016-02-17 16:46:26 -0800 | [diff] [blame] | 206 | return nullptr; |
Tom Sepez | 2398d89 | 2016-02-17 16:46:26 -0800 | [diff] [blame] | 207 | return pPage->GetPageObjectList()->GetPageObjectByIndex(index); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 208 | } |
| 209 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 210 | DLLEXPORT FPDF_BOOL STDCALL FPDFPage_HasTransparency(FPDF_PAGE page) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 211 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
| 212 | return pPage && pPage->BackgroundAlphaNeeded(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 213 | } |
| 214 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 215 | DLLEXPORT FPDF_BOOL STDCALL |
| 216 | FPDFPageObj_HasTransparency(FPDF_PAGEOBJECT pageObject) { |
| 217 | if (!pageObject) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 218 | return false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 219 | |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 220 | CPDF_PageObject* pPageObj = reinterpret_cast<CPDF_PageObject*>(pageObject); |
tsepez | bbee445 | 2016-09-02 15:22:00 -0700 | [diff] [blame] | 221 | int blend_type = pPageObj->m_GeneralState.GetBlendType(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 222 | if (blend_type != FXDIB_BLEND_NORMAL) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 223 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 224 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 225 | CPDF_Dictionary* pSMaskDict = |
tsepez | bbee445 | 2016-09-02 15:22:00 -0700 | [diff] [blame] | 226 | ToDictionary(pPageObj->m_GeneralState.GetSoftMask()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 227 | if (pSMaskDict) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 228 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 229 | |
tsepez | bbee445 | 2016-09-02 15:22:00 -0700 | [diff] [blame] | 230 | if (pPageObj->m_GeneralState.GetFillAlpha() != 1.0f) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 231 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 232 | |
tsepez | bbee445 | 2016-09-02 15:22:00 -0700 | [diff] [blame] | 233 | if (pPageObj->IsPath() && pPageObj->m_GeneralState.GetStrokeAlpha() != 1.0f) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 234 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 235 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 236 | |
Wei Li | 7cf13c9 | 2016-02-19 11:53:03 -0800 | [diff] [blame] | 237 | if (pPageObj->IsForm()) { |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 238 | const CPDF_Form* pForm = pPageObj->AsForm()->form(); |
| 239 | if (pForm) { |
| 240 | int trans = pForm->m_Transparency; |
| 241 | if ((trans & PDFTRANS_ISOLATED) || (trans & PDFTRANS_GROUP)) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 242 | return true; |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 243 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 244 | } |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 245 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 246 | return false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 247 | } |
| 248 | |
Miklos Vajna | 1423319 | 2017-04-03 16:02:39 +0200 | [diff] [blame^] | 249 | DLLEXPORT int STDCALL FPDFPageObj_GetType(FPDF_PAGEOBJECT pageObject) { |
| 250 | if (!pageObject) |
| 251 | return FPDF_PAGEOBJ_UNKNOWN; |
| 252 | |
| 253 | CPDF_PageObject* pPageObj = reinterpret_cast<CPDF_PageObject*>(pageObject); |
| 254 | return pPageObj->GetType(); |
| 255 | } |
| 256 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 257 | DLLEXPORT FPDF_BOOL STDCALL FPDFPage_GenerateContent(FPDF_PAGE page) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 258 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 259 | if (!IsPageObject(pPage)) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 260 | return false; |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 261 | |
Tom Sepez | e19e06e | 2016-01-21 10:49:56 -0800 | [diff] [blame] | 262 | CPDF_PageContentGenerator CG(pPage); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 263 | CG.GenerateContent(); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 264 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | DLLEXPORT void STDCALL FPDFPageObj_Transform(FPDF_PAGEOBJECT page_object, |
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) { |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 274 | CPDF_PageObject* pPageObj = reinterpret_cast<CPDF_PageObject*>(page_object); |
Lei Zhang | 997de61 | 2015-11-04 18:17:53 -0800 | [diff] [blame] | 275 | if (!pPageObj) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 276 | return; |
Lei Zhang | cb78ef5 | 2015-10-02 10:10:49 -0700 | [diff] [blame] | 277 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 278 | CFX_Matrix matrix((float)a, (float)b, (float)c, (float)d, (float)e, (float)f); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 279 | pPageObj->Transform(matrix); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 280 | } |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 281 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 282 | DLLEXPORT void STDCALL FPDFPage_TransformAnnots(FPDF_PAGE page, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 283 | double a, |
| 284 | double b, |
| 285 | double c, |
| 286 | double d, |
| 287 | double e, |
| 288 | double f) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 289 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 290 | if (!pPage) |
| 291 | return; |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 292 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 293 | CPDF_AnnotList AnnotList(pPage); |
Lei Zhang | 1b700c3 | 2015-10-30 23:55:35 -0700 | [diff] [blame] | 294 | for (size_t i = 0; i < AnnotList.Count(); ++i) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 295 | CPDF_Annot* pAnnot = AnnotList.GetAt(i); |
tsepez | 8021a64 | 2016-10-17 16:13:21 -0700 | [diff] [blame] | 296 | CFX_FloatRect rect = pAnnot->GetRect(); // transformAnnots Rectangle |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 297 | CFX_Matrix matrix((float)a, (float)b, (float)c, (float)d, (float)e, |
| 298 | (float)f); |
Dan Sinclair | 118a8e2 | 2017-02-09 10:16:07 -0500 | [diff] [blame] | 299 | matrix.TransformRect(rect); |
tsepez | 8021a64 | 2016-10-17 16:13:21 -0700 | [diff] [blame] | 300 | |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 301 | CPDF_Array* pRectArray = pAnnot->GetAnnotDict()->GetArrayFor("Rect"); |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 302 | if (!pRectArray) |
| 303 | pRectArray = pAnnot->GetAnnotDict()->SetNewFor<CPDF_Array>("Rect"); |
| 304 | |
tsepez | 8a3aa45 | 2016-11-16 12:26:06 -0800 | [diff] [blame] | 305 | pRectArray->SetNewAt<CPDF_Number>(0, rect.left); |
| 306 | pRectArray->SetNewAt<CPDF_Number>(1, rect.bottom); |
| 307 | pRectArray->SetNewAt<CPDF_Number>(2, rect.right); |
| 308 | pRectArray->SetNewAt<CPDF_Number>(3, rect.top); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 309 | |
Dan Sinclair | 85c8e7f | 2016-11-21 13:50:32 -0500 | [diff] [blame] | 310 | // TODO(unknown): Transform AP's rectangle |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 311 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 312 | } |
Bo Xu | 394010d | 2014-06-12 13:41:50 -0700 | [diff] [blame] | 313 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 314 | DLLEXPORT void STDCALL FPDFPage_SetRotation(FPDF_PAGE page, int rotate) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 315 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 316 | if (!IsPageObject(pPage)) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 317 | return; |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 318 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 319 | CPDF_Dictionary* pDict = pPage->m_pFormDict; |
| 320 | rotate %= 4; |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 321 | pDict->SetNewFor<CPDF_Number>("Rotate", rotate * 90); |
Nico Weber | 0ce77e3 | 2014-07-16 13:19:08 -0700 | [diff] [blame] | 322 | } |