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; |
rbpotter | ce8e51e | 2017-04-28 12:42:47 -0700 | [diff] [blame] | 136 | return pPage->GetPageRotation(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 137 | } |
| 138 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 139 | DLLEXPORT void STDCALL FPDFPage_InsertObject(FPDF_PAGE page, |
| 140 | FPDF_PAGEOBJECT page_obj) { |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 141 | CPDF_PageObject* pPageObj = reinterpret_cast<CPDF_PageObject*>(page_obj); |
Lei Zhang | 997de61 | 2015-11-04 18:17:53 -0800 | [diff] [blame] | 142 | if (!pPageObj) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 143 | return; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 144 | |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 145 | std::unique_ptr<CPDF_PageObject> pPageObjHolder(pPageObj); |
| 146 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
| 147 | if (!IsPageObject(pPage)) |
| 148 | return; |
Tom Sepez | 2398d89 | 2016-02-17 16:46:26 -0800 | [diff] [blame] | 149 | |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 150 | pPage->GetPageObjectList()->push_back(std::move(pPageObjHolder)); |
Wei Li | 7cf13c9 | 2016-02-19 11:53:03 -0800 | [diff] [blame] | 151 | switch (pPageObj->GetType()) { |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 152 | case CPDF_PageObject::TEXT: { |
| 153 | break; |
| 154 | } |
| 155 | case CPDF_PageObject::PATH: { |
Wei Li | 7cf13c9 | 2016-02-19 11:53:03 -0800 | [diff] [blame] | 156 | CPDF_PathObject* pPathObj = pPageObj->AsPath(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 157 | pPathObj->CalcBoundingBox(); |
| 158 | break; |
| 159 | } |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 160 | case CPDF_PageObject::IMAGE: { |
Wei Li | 7cf13c9 | 2016-02-19 11:53:03 -0800 | [diff] [blame] | 161 | CPDF_ImageObject* pImageObj = pPageObj->AsImage(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 162 | pImageObj->CalcBoundingBox(); |
| 163 | break; |
| 164 | } |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 165 | case CPDF_PageObject::SHADING: { |
Wei Li | 7cf13c9 | 2016-02-19 11:53:03 -0800 | [diff] [blame] | 166 | CPDF_ShadingObject* pShadingObj = pPageObj->AsShading(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 167 | pShadingObj->CalcBoundingBox(); |
| 168 | break; |
| 169 | } |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 170 | case CPDF_PageObject::FORM: { |
Wei Li | 7cf13c9 | 2016-02-19 11:53:03 -0800 | [diff] [blame] | 171 | CPDF_FormObject* pFormObj = pPageObj->AsForm(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 172 | pFormObj->CalcBoundingBox(); |
| 173 | break; |
| 174 | } |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 175 | default: { |
| 176 | ASSERT(false); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 177 | break; |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 178 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 179 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 180 | } |
| 181 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 182 | DLLEXPORT int STDCALL FPDFPage_CountObject(FPDF_PAGE page) { |
Tom Sepez | bf59a07 | 2015-10-21 14:07:23 -0700 | [diff] [blame] | 183 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 184 | if (!IsPageObject(pPage)) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 185 | return -1; |
Tom Sepez | 2398d89 | 2016-02-17 16:46:26 -0800 | [diff] [blame] | 186 | return pdfium::CollectionSize<int>(*pPage->GetPageObjectList()); |
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_PAGEOBJECT STDCALL FPDFPage_GetObject(FPDF_PAGE page, |
| 190 | int index) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 191 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 192 | if (!IsPageObject(pPage)) |
Tom Sepez | 2398d89 | 2016-02-17 16:46:26 -0800 | [diff] [blame] | 193 | return nullptr; |
Tom Sepez | 2398d89 | 2016-02-17 16:46:26 -0800 | [diff] [blame] | 194 | return pPage->GetPageObjectList()->GetPageObjectByIndex(index); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 195 | } |
| 196 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 197 | DLLEXPORT FPDF_BOOL STDCALL FPDFPage_HasTransparency(FPDF_PAGE page) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 198 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
| 199 | return pPage && pPage->BackgroundAlphaNeeded(); |
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_BOOL STDCALL |
| 203 | FPDFPageObj_HasTransparency(FPDF_PAGEOBJECT pageObject) { |
| 204 | if (!pageObject) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 205 | return false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 206 | |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 207 | CPDF_PageObject* pPageObj = reinterpret_cast<CPDF_PageObject*>(pageObject); |
tsepez | bbee445 | 2016-09-02 15:22:00 -0700 | [diff] [blame] | 208 | int blend_type = pPageObj->m_GeneralState.GetBlendType(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 209 | if (blend_type != FXDIB_BLEND_NORMAL) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 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 = |
tsepez | bbee445 | 2016-09-02 15:22:00 -0700 | [diff] [blame] | 213 | ToDictionary(pPageObj->m_GeneralState.GetSoftMask()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 214 | if (pSMaskDict) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 215 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 216 | |
tsepez | bbee445 | 2016-09-02 15:22:00 -0700 | [diff] [blame] | 217 | if (pPageObj->m_GeneralState.GetFillAlpha() != 1.0f) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 218 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 219 | |
tsepez | bbee445 | 2016-09-02 15:22:00 -0700 | [diff] [blame] | 220 | if (pPageObj->IsPath() && pPageObj->m_GeneralState.GetStrokeAlpha() != 1.0f) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 221 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 222 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 223 | |
Wei Li | 7cf13c9 | 2016-02-19 11:53:03 -0800 | [diff] [blame] | 224 | if (pPageObj->IsForm()) { |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 225 | const CPDF_Form* pForm = pPageObj->AsForm()->form(); |
| 226 | if (pForm) { |
| 227 | int trans = pForm->m_Transparency; |
| 228 | if ((trans & PDFTRANS_ISOLATED) || (trans & PDFTRANS_GROUP)) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 229 | return true; |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 230 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 231 | } |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 232 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 233 | return false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 234 | } |
| 235 | |
Miklos Vajna | 1423319 | 2017-04-03 16:02:39 +0200 | [diff] [blame] | 236 | DLLEXPORT int STDCALL FPDFPageObj_GetType(FPDF_PAGEOBJECT pageObject) { |
| 237 | if (!pageObject) |
| 238 | return FPDF_PAGEOBJ_UNKNOWN; |
| 239 | |
| 240 | CPDF_PageObject* pPageObj = reinterpret_cast<CPDF_PageObject*>(pageObject); |
| 241 | return pPageObj->GetType(); |
| 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); |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 246 | if (!IsPageObject(pPage)) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 247 | return false; |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 248 | |
Tom Sepez | e19e06e | 2016-01-21 10:49:56 -0800 | [diff] [blame] | 249 | CPDF_PageContentGenerator CG(pPage); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 250 | CG.GenerateContent(); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 251 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | DLLEXPORT void STDCALL FPDFPageObj_Transform(FPDF_PAGEOBJECT page_object, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 255 | double a, |
| 256 | double b, |
| 257 | double c, |
| 258 | double d, |
| 259 | double e, |
| 260 | double f) { |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 261 | CPDF_PageObject* pPageObj = reinterpret_cast<CPDF_PageObject*>(page_object); |
Lei Zhang | 997de61 | 2015-11-04 18:17:53 -0800 | [diff] [blame] | 262 | if (!pPageObj) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 263 | return; |
Lei Zhang | cb78ef5 | 2015-10-02 10:10:49 -0700 | [diff] [blame] | 264 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 265 | 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] | 266 | pPageObj->Transform(matrix); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 267 | } |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 268 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 269 | DLLEXPORT void STDCALL FPDFPage_TransformAnnots(FPDF_PAGE page, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 270 | double a, |
| 271 | double b, |
| 272 | double c, |
| 273 | double d, |
| 274 | double e, |
| 275 | double f) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 276 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 277 | if (!pPage) |
| 278 | return; |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 279 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 280 | CPDF_AnnotList AnnotList(pPage); |
Lei Zhang | 1b700c3 | 2015-10-30 23:55:35 -0700 | [diff] [blame] | 281 | for (size_t i = 0; i < AnnotList.Count(); ++i) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 282 | CPDF_Annot* pAnnot = AnnotList.GetAt(i); |
tsepez | 8021a64 | 2016-10-17 16:13:21 -0700 | [diff] [blame] | 283 | CFX_FloatRect rect = pAnnot->GetRect(); // transformAnnots Rectangle |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 284 | CFX_Matrix matrix((float)a, (float)b, (float)c, (float)d, (float)e, |
| 285 | (float)f); |
Dan Sinclair | 118a8e2 | 2017-02-09 10:16:07 -0500 | [diff] [blame] | 286 | matrix.TransformRect(rect); |
tsepez | 8021a64 | 2016-10-17 16:13:21 -0700 | [diff] [blame] | 287 | |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 288 | CPDF_Array* pRectArray = pAnnot->GetAnnotDict()->GetArrayFor("Rect"); |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 289 | if (!pRectArray) |
| 290 | pRectArray = pAnnot->GetAnnotDict()->SetNewFor<CPDF_Array>("Rect"); |
| 291 | |
tsepez | 8a3aa45 | 2016-11-16 12:26:06 -0800 | [diff] [blame] | 292 | pRectArray->SetNewAt<CPDF_Number>(0, rect.left); |
| 293 | pRectArray->SetNewAt<CPDF_Number>(1, rect.bottom); |
| 294 | pRectArray->SetNewAt<CPDF_Number>(2, rect.right); |
| 295 | pRectArray->SetNewAt<CPDF_Number>(3, rect.top); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 296 | |
Dan Sinclair | 85c8e7f | 2016-11-21 13:50:32 -0500 | [diff] [blame] | 297 | // TODO(unknown): Transform AP's rectangle |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 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); |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 303 | if (!IsPageObject(pPage)) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 304 | return; |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 305 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 306 | CPDF_Dictionary* pDict = pPage->m_pFormDict; |
| 307 | rotate %= 4; |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 308 | pDict->SetNewFor<CPDF_Number>("Rotate", rotate * 90); |
Nico Weber | 0ce77e3 | 2014-07-16 13:19:08 -0700 | [diff] [blame] | 309 | } |