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" |
Lei Zhang | b45324b | 2017-05-22 17:05:40 -0700 | [diff] [blame] | 29 | #include "third_party/base/logging.h" |
Tom Sepez | 2398d89 | 2016-02-17 16:46:26 -0800 | [diff] [blame] | 30 | #include "third_party/base/stl_util.h" |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 31 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 32 | #ifdef PDF_ENABLE_XFA |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 33 | #include "fpdfsdk/fpdfxfa/cpdfxfa_context.h" |
dsinclair | 4d29e78 | 2016-10-04 14:02:47 -0700 | [diff] [blame] | 34 | #include "fpdfsdk/fpdfxfa/cpdfxfa_page.h" |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 35 | #endif // PDF_ENABLE_XFA |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 36 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 37 | #if _FX_OS_ == _FX_ANDROID_ |
Dan Sinclair | 85c8e7f | 2016-11-21 13:50:32 -0500 | [diff] [blame] | 38 | #include <time.h> |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 39 | #else |
| 40 | #include <ctime> |
| 41 | #endif |
| 42 | |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 43 | namespace { |
| 44 | |
| 45 | static_assert(FPDF_PAGEOBJ_TEXT == CPDF_PageObject::TEXT, |
| 46 | "FPDF_PAGEOBJ_TEXT/CPDF_PageObject::TEXT mismatch"); |
| 47 | static_assert(FPDF_PAGEOBJ_PATH == CPDF_PageObject::PATH, |
| 48 | "FPDF_PAGEOBJ_PATH/CPDF_PageObject::PATH mismatch"); |
| 49 | static_assert(FPDF_PAGEOBJ_IMAGE == CPDF_PageObject::IMAGE, |
| 50 | "FPDF_PAGEOBJ_IMAGE/CPDF_PageObject::IMAGE mismatch"); |
| 51 | static_assert(FPDF_PAGEOBJ_SHADING == CPDF_PageObject::SHADING, |
| 52 | "FPDF_PAGEOBJ_SHADING/CPDF_PageObject::SHADING mismatch"); |
| 53 | static_assert(FPDF_PAGEOBJ_FORM == CPDF_PageObject::FORM, |
| 54 | "FPDF_PAGEOBJ_FORM/CPDF_PageObject::FORM mismatch"); |
| 55 | |
| 56 | bool IsPageObject(CPDF_Page* pPage) { |
| 57 | if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type")) |
| 58 | return false; |
| 59 | |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 60 | CPDF_Object* pObject = pPage->m_pFormDict->GetObjectFor("Type")->GetDirect(); |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 61 | return pObject && !pObject->GetString().Compare("Page"); |
| 62 | } |
| 63 | |
wileyrya | e858aa4 | 2017-05-31 14:49:05 -0500 | [diff] [blame] | 64 | void CalcBoundingBox(CPDF_PageObject* pPageObj) { |
| 65 | switch (pPageObj->GetType()) { |
| 66 | case CPDF_PageObject::TEXT: { |
| 67 | break; |
| 68 | } |
| 69 | case CPDF_PageObject::PATH: { |
| 70 | CPDF_PathObject* pPathObj = pPageObj->AsPath(); |
| 71 | pPathObj->CalcBoundingBox(); |
| 72 | break; |
| 73 | } |
| 74 | case CPDF_PageObject::IMAGE: { |
| 75 | CPDF_ImageObject* pImageObj = pPageObj->AsImage(); |
| 76 | pImageObj->CalcBoundingBox(); |
| 77 | break; |
| 78 | } |
| 79 | case CPDF_PageObject::SHADING: { |
| 80 | CPDF_ShadingObject* pShadingObj = pPageObj->AsShading(); |
| 81 | pShadingObj->CalcBoundingBox(); |
| 82 | break; |
| 83 | } |
| 84 | case CPDF_PageObject::FORM: { |
| 85 | CPDF_FormObject* pFormObj = pPageObj->AsForm(); |
| 86 | pFormObj->CalcBoundingBox(); |
| 87 | break; |
| 88 | } |
| 89 | default: { |
| 90 | NOTREACHED(); |
| 91 | break; |
| 92 | } |
| 93 | } |
| 94 | } |
| 95 | |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 96 | } // namespace |
| 97 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 98 | FPDF_EXPORT FPDF_DOCUMENT FPDF_CALLCONV FPDF_CreateNewDocument() { |
Tom Sepez | fe91c6c | 2017-05-16 15:33:20 -0700 | [diff] [blame] | 99 | auto pDoc = pdfium::MakeUnique<CPDF_Document>(nullptr); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 100 | pDoc->CreateNewDoc(); |
Tom Sepez | fe91c6c | 2017-05-16 15:33:20 -0700 | [diff] [blame] | 101 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 102 | time_t currentTime; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 103 | CFX_ByteString DateStr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 104 | if (FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS)) { |
Tom Sepez | fe91c6c | 2017-05-16 15:33:20 -0700 | [diff] [blame] | 105 | if (time(¤tTime) != -1) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 106 | tm* pTM = localtime(¤tTime); |
| 107 | if (pTM) { |
| 108 | DateStr.Format("D:%04d%02d%02d%02d%02d%02d", pTM->tm_year + 1900, |
| 109 | pTM->tm_mon + 1, pTM->tm_mday, pTM->tm_hour, pTM->tm_min, |
| 110 | pTM->tm_sec); |
| 111 | } |
| 112 | } |
| 113 | } |
Tom Sepez | bdeeb8a | 2015-05-27 12:25:00 -0700 | [diff] [blame] | 114 | |
Tom Sepez | fe91c6c | 2017-05-16 15:33:20 -0700 | [diff] [blame] | 115 | CPDF_Dictionary* pInfoDict = pDoc->GetInfo(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 116 | if (pInfoDict) { |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 117 | if (FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS)) |
| 118 | pInfoDict->SetNewFor<CPDF_String>("CreationDate", DateStr, false); |
| 119 | pInfoDict->SetNewFor<CPDF_String>("Creator", L"PDFium"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 120 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 121 | |
Tom Sepez | fe91c6c | 2017-05-16 15:33:20 -0700 | [diff] [blame] | 122 | // Caller takes ownership of pDoc. |
| 123 | return FPDFDocumentFromCPDFDocument(pDoc.release()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 124 | } |
| 125 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 126 | FPDF_EXPORT void FPDF_CALLCONV FPDFPage_Delete(FPDF_DOCUMENT document, |
| 127 | int page_index) { |
Tom Sepez | 744da70 | 2016-03-15 12:43:09 -0700 | [diff] [blame] | 128 | if (UnderlyingDocumentType* pDoc = UnderlyingFromFPDFDocument(document)) |
| 129 | pDoc->DeletePage(page_index); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 130 | } |
| 131 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 132 | FPDF_EXPORT FPDF_PAGE FPDF_CALLCONV FPDFPage_New(FPDF_DOCUMENT document, |
| 133 | int page_index, |
| 134 | double width, |
| 135 | double height) { |
Tom Sepez | 471a103 | 2015-10-15 16:17:18 -0700 | [diff] [blame] | 136 | CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
| 137 | if (!pDoc) |
| 138 | return nullptr; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 139 | |
Lei Zhang | 85f019a | 2017-03-17 15:14:19 -0700 | [diff] [blame] | 140 | page_index = pdfium::clamp(page_index, 0, pDoc->GetPageCount()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 141 | CPDF_Dictionary* pPageDict = pDoc->CreateNewPage(page_index); |
| 142 | if (!pPageDict) |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 143 | return nullptr; |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 144 | |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 145 | CPDF_Array* pMediaBoxArray = pPageDict->SetNewFor<CPDF_Array>("MediaBox"); |
tsepez | 8a3aa45 | 2016-11-16 12:26:06 -0800 | [diff] [blame] | 146 | pMediaBoxArray->AddNew<CPDF_Number>(0); |
| 147 | pMediaBoxArray->AddNew<CPDF_Number>(0); |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 148 | pMediaBoxArray->AddNew<CPDF_Number>(static_cast<float>(width)); |
| 149 | pMediaBoxArray->AddNew<CPDF_Number>(static_cast<float>(height)); |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 150 | pPageDict->SetNewFor<CPDF_Number>("Rotate", 0); |
| 151 | pPageDict->SetNewFor<CPDF_Dictionary>("Resources"); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 152 | |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 153 | #ifdef PDF_ENABLE_XFA |
Tom Sepez | 9792f16 | 2017-05-16 14:11:30 -0700 | [diff] [blame] | 154 | auto pXFAPage = pdfium::MakeRetain<CPDFXFA_Page>( |
| 155 | static_cast<CPDFXFA_Context*>(document), page_index); |
| 156 | pXFAPage->LoadPDFPage(pPageDict); |
Tom Sepez | fe91c6c | 2017-05-16 15:33:20 -0700 | [diff] [blame] | 157 | return pXFAPage.Leak(); // Caller takes ownership. |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 158 | #else // PDF_ENABLE_XFA |
Tom Sepez | fe91c6c | 2017-05-16 15:33:20 -0700 | [diff] [blame] | 159 | auto pPage = pdfium::MakeUnique<CPDF_Page>(pDoc, pPageDict, true); |
thestig | 5cc2465 | 2016-04-26 11:46:02 -0700 | [diff] [blame] | 160 | pPage->ParseContent(); |
Tom Sepez | fe91c6c | 2017-05-16 15:33:20 -0700 | [diff] [blame] | 161 | return pPage.release(); // Caller takes ownership. |
Tom Sepez | 9792f16 | 2017-05-16 14:11:30 -0700 | [diff] [blame] | 162 | #endif // PDF_ENABLE_XFA |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 163 | } |
| 164 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 165 | FPDF_EXPORT int FPDF_CALLCONV FPDFPage_GetRotation(FPDF_PAGE page) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 166 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
Tom Sepez | fe91c6c | 2017-05-16 15:33:20 -0700 | [diff] [blame] | 167 | return IsPageObject(pPage) ? pPage->GetPageRotation() : -1; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 168 | } |
| 169 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 170 | FPDF_EXPORT void FPDF_CALLCONV FPDFPage_InsertObject(FPDF_PAGE page, |
| 171 | FPDF_PAGEOBJECT page_obj) { |
Jane Liu | 1a08402 | 2017-06-29 19:47:12 -0400 | [diff] [blame] | 172 | CPDF_PageObject* pPageObj = CPDFPageObjectFromFPDFPageObject(page_obj); |
Lei Zhang | 997de61 | 2015-11-04 18:17:53 -0800 | [diff] [blame] | 173 | if (!pPageObj) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 174 | return; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 175 | |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 176 | std::unique_ptr<CPDF_PageObject> pPageObjHolder(pPageObj); |
| 177 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
| 178 | if (!IsPageObject(pPage)) |
| 179 | return; |
wileyrya | e858aa4 | 2017-05-31 14:49:05 -0500 | [diff] [blame] | 180 | pPageObj->SetDirty(true); |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 181 | pPage->GetPageObjectList()->push_back(std::move(pPageObjHolder)); |
wileyrya | e858aa4 | 2017-05-31 14:49:05 -0500 | [diff] [blame] | 182 | CalcBoundingBox(pPageObj); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 183 | } |
| 184 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 185 | FPDF_EXPORT int FPDF_CALLCONV FPDFPage_CountObject(FPDF_PAGE page) { |
Tom Sepez | bf59a07 | 2015-10-21 14:07:23 -0700 | [diff] [blame] | 186 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 187 | if (!IsPageObject(pPage)) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 188 | return -1; |
Tom Sepez | 2398d89 | 2016-02-17 16:46:26 -0800 | [diff] [blame] | 189 | return pdfium::CollectionSize<int>(*pPage->GetPageObjectList()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 190 | } |
| 191 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 192 | FPDF_EXPORT FPDF_PAGEOBJECT FPDF_CALLCONV FPDFPage_GetObject(FPDF_PAGE page, |
| 193 | int index) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 194 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 195 | if (!IsPageObject(pPage)) |
Tom Sepez | 2398d89 | 2016-02-17 16:46:26 -0800 | [diff] [blame] | 196 | return nullptr; |
Tom Sepez | 2398d89 | 2016-02-17 16:46:26 -0800 | [diff] [blame] | 197 | return pPage->GetPageObjectList()->GetPageObjectByIndex(index); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 198 | } |
| 199 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 200 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPage_HasTransparency(FPDF_PAGE page) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 201 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
| 202 | return pPage && pPage->BackgroundAlphaNeeded(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 203 | } |
| 204 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 205 | FPDF_EXPORT void FPDF_CALLCONV FPDFPageObj_Destroy(FPDF_PAGEOBJECT page_obj) { |
Jane Liu | 2e5f0ae | 2017-08-08 15:23:27 -0400 | [diff] [blame] | 206 | delete CPDFPageObjectFromFPDFPageObject(page_obj); |
| 207 | } |
| 208 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 209 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 210 | FPDFPageObj_HasTransparency(FPDF_PAGEOBJECT pageObject) { |
| 211 | if (!pageObject) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 212 | return false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 213 | |
Jane Liu | 1a08402 | 2017-06-29 19:47:12 -0400 | [diff] [blame] | 214 | CPDF_PageObject* pPageObj = CPDFPageObjectFromFPDFPageObject(pageObject); |
tsepez | bbee445 | 2016-09-02 15:22:00 -0700 | [diff] [blame] | 215 | int blend_type = pPageObj->m_GeneralState.GetBlendType(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 216 | if (blend_type != FXDIB_BLEND_NORMAL) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 217 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 218 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 219 | CPDF_Dictionary* pSMaskDict = |
tsepez | bbee445 | 2016-09-02 15:22:00 -0700 | [diff] [blame] | 220 | ToDictionary(pPageObj->m_GeneralState.GetSoftMask()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 221 | if (pSMaskDict) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 222 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 223 | |
tsepez | bbee445 | 2016-09-02 15:22:00 -0700 | [diff] [blame] | 224 | if (pPageObj->m_GeneralState.GetFillAlpha() != 1.0f) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 225 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 226 | |
tsepez | bbee445 | 2016-09-02 15:22:00 -0700 | [diff] [blame] | 227 | if (pPageObj->IsPath() && pPageObj->m_GeneralState.GetStrokeAlpha() != 1.0f) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 228 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 229 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 230 | |
Wei Li | 7cf13c9 | 2016-02-19 11:53:03 -0800 | [diff] [blame] | 231 | if (pPageObj->IsForm()) { |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 232 | const CPDF_Form* pForm = pPageObj->AsForm()->form(); |
| 233 | if (pForm) { |
| 234 | int trans = pForm->m_Transparency; |
| 235 | if ((trans & PDFTRANS_ISOLATED) || (trans & PDFTRANS_GROUP)) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 236 | return true; |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 237 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 238 | } |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 239 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 240 | return false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 241 | } |
| 242 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 243 | FPDF_EXPORT int FPDF_CALLCONV FPDFPageObj_GetType(FPDF_PAGEOBJECT pageObject) { |
Miklos Vajna | 1423319 | 2017-04-03 16:02:39 +0200 | [diff] [blame] | 244 | if (!pageObject) |
| 245 | return FPDF_PAGEOBJ_UNKNOWN; |
| 246 | |
Jane Liu | 1a08402 | 2017-06-29 19:47:12 -0400 | [diff] [blame] | 247 | CPDF_PageObject* pPageObj = CPDFPageObjectFromFPDFPageObject(pageObject); |
Miklos Vajna | 1423319 | 2017-04-03 16:02:39 +0200 | [diff] [blame] | 248 | return pPageObj->GetType(); |
| 249 | } |
| 250 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 251 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPage_GenerateContent(FPDF_PAGE page) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 252 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 253 | if (!IsPageObject(pPage)) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 254 | return false; |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 255 | |
Tom Sepez | e19e06e | 2016-01-21 10:49:56 -0800 | [diff] [blame] | 256 | CPDF_PageContentGenerator CG(pPage); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 257 | CG.GenerateContent(); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 258 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 259 | } |
| 260 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 261 | FPDF_EXPORT void FPDF_CALLCONV |
| 262 | FPDFPageObj_Transform(FPDF_PAGEOBJECT page_object, |
| 263 | double a, |
| 264 | double b, |
| 265 | double c, |
| 266 | double d, |
| 267 | double e, |
| 268 | double f) { |
Jane Liu | 1a08402 | 2017-06-29 19:47:12 -0400 | [diff] [blame] | 269 | CPDF_PageObject* pPageObj = CPDFPageObjectFromFPDFPageObject(page_object); |
Lei Zhang | 997de61 | 2015-11-04 18:17:53 -0800 | [diff] [blame] | 270 | if (!pPageObj) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 271 | return; |
Lei Zhang | cb78ef5 | 2015-10-02 10:10:49 -0700 | [diff] [blame] | 272 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 273 | 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] | 274 | pPageObj->Transform(matrix); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 275 | } |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 276 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 277 | FPDF_EXPORT void FPDF_CALLCONV |
| 278 | FPDFPageObj_SetBlendMode(FPDF_PAGEOBJECT page_object, |
| 279 | FPDF_BYTESTRING blend_mode) { |
Jane Liu | 1a08402 | 2017-06-29 19:47:12 -0400 | [diff] [blame] | 280 | CPDF_PageObject* pPageObj = CPDFPageObjectFromFPDFPageObject(page_object); |
wileyrya | 06bbdef | 2017-05-26 15:20:23 -0500 | [diff] [blame] | 281 | if (!pPageObj) |
| 282 | return; |
| 283 | |
| 284 | pPageObj->m_GeneralState.SetBlendMode(blend_mode); |
wileyrya | e858aa4 | 2017-05-31 14:49:05 -0500 | [diff] [blame] | 285 | pPageObj->SetDirty(true); |
wileyrya | 06bbdef | 2017-05-26 15:20:23 -0500 | [diff] [blame] | 286 | } |
| 287 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 288 | FPDF_EXPORT void FPDF_CALLCONV FPDFPage_TransformAnnots(FPDF_PAGE page, |
| 289 | double a, |
| 290 | double b, |
| 291 | double c, |
| 292 | double d, |
| 293 | double e, |
| 294 | double f) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 295 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 296 | if (!pPage) |
| 297 | return; |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 298 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 299 | CPDF_AnnotList AnnotList(pPage); |
Lei Zhang | 1b700c3 | 2015-10-30 23:55:35 -0700 | [diff] [blame] | 300 | for (size_t i = 0; i < AnnotList.Count(); ++i) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 301 | CPDF_Annot* pAnnot = AnnotList.GetAt(i); |
tsepez | 8021a64 | 2016-10-17 16:13:21 -0700 | [diff] [blame] | 302 | CFX_FloatRect rect = pAnnot->GetRect(); // transformAnnots Rectangle |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 303 | CFX_Matrix matrix((float)a, (float)b, (float)c, (float)d, (float)e, |
| 304 | (float)f); |
Dan Sinclair | 118a8e2 | 2017-02-09 10:16:07 -0500 | [diff] [blame] | 305 | matrix.TransformRect(rect); |
tsepez | 8021a64 | 2016-10-17 16:13:21 -0700 | [diff] [blame] | 306 | |
Lei Zhang | 59c1ac0 | 2017-06-09 11:04:41 -0700 | [diff] [blame] | 307 | CPDF_Dictionary* pAnnotDict = pAnnot->GetAnnotDict(); |
| 308 | CPDF_Array* pRectArray = pAnnotDict->GetArrayFor("Rect"); |
Jane Liu | eda6525 | 2017-06-07 11:31:27 -0400 | [diff] [blame] | 309 | if (pRectArray) |
Lei Zhang | 59c1ac0 | 2017-06-09 11:04:41 -0700 | [diff] [blame] | 310 | pRectArray->Clear(); |
Jane Liu | eda6525 | 2017-06-07 11:31:27 -0400 | [diff] [blame] | 311 | else |
Lei Zhang | 59c1ac0 | 2017-06-09 11:04:41 -0700 | [diff] [blame] | 312 | pRectArray = pAnnotDict->SetNewFor<CPDF_Array>("Rect"); |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 313 | |
Jane Liu | eda6525 | 2017-06-07 11:31:27 -0400 | [diff] [blame] | 314 | pRectArray->AddNew<CPDF_Number>(rect.left); |
| 315 | pRectArray->AddNew<CPDF_Number>(rect.bottom); |
| 316 | pRectArray->AddNew<CPDF_Number>(rect.right); |
| 317 | pRectArray->AddNew<CPDF_Number>(rect.top); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 318 | |
Dan Sinclair | 85c8e7f | 2016-11-21 13:50:32 -0500 | [diff] [blame] | 319 | // TODO(unknown): Transform AP's rectangle |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 320 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 321 | } |
Bo Xu | 394010d | 2014-06-12 13:41:50 -0700 | [diff] [blame] | 322 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 323 | FPDF_EXPORT void FPDF_CALLCONV FPDFPage_SetRotation(FPDF_PAGE page, |
| 324 | int rotate) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 325 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 326 | if (!IsPageObject(pPage)) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 327 | return; |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 328 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 329 | rotate %= 4; |
Tom Sepez | 4cb82ee | 2017-05-22 15:15:30 -0700 | [diff] [blame] | 330 | pPage->m_pFormDict->SetNewFor<CPDF_Number>("Rotate", rotate * 90); |
Nico Weber | 0ce77e3 | 2014-07-16 13:19:08 -0700 | [diff] [blame] | 331 | } |
wileyrya | 864e9fb | 2017-05-26 11:38:14 -0500 | [diff] [blame] | 332 | |
| 333 | FPDF_BOOL FPDFPageObj_SetFillColor(FPDF_PAGEOBJECT page_object, |
| 334 | unsigned int R, |
| 335 | unsigned int G, |
| 336 | unsigned int B, |
| 337 | unsigned int A) { |
| 338 | if (!page_object || R > 255 || G > 255 || B > 255 || A > 255) |
| 339 | return false; |
| 340 | |
| 341 | float rgb[3] = {R / 255.f, G / 255.f, B / 255.f}; |
Jane Liu | 1a08402 | 2017-06-29 19:47:12 -0400 | [diff] [blame] | 342 | auto* pPageObj = CPDFPageObjectFromFPDFPageObject(page_object); |
wileyrya | 864e9fb | 2017-05-26 11:38:14 -0500 | [diff] [blame] | 343 | pPageObj->m_GeneralState.SetFillAlpha(A / 255.f); |
| 344 | pPageObj->m_ColorState.SetFillColor( |
| 345 | CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB), rgb, 3); |
wileyrya | e858aa4 | 2017-05-31 14:49:05 -0500 | [diff] [blame] | 346 | pPageObj->SetDirty(true); |
wileyrya | 864e9fb | 2017-05-26 11:38:14 -0500 | [diff] [blame] | 347 | return true; |
| 348 | } |
wileyrya | f1697fa | 2017-05-26 12:27:40 -0500 | [diff] [blame] | 349 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 350 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV |
| 351 | FPDFPageObj_GetBounds(FPDF_PAGEOBJECT pageObject, |
| 352 | float* left, |
| 353 | float* bottom, |
| 354 | float* right, |
| 355 | float* top) { |
wileyrya | f1697fa | 2017-05-26 12:27:40 -0500 | [diff] [blame] | 356 | if (!pageObject) |
| 357 | return false; |
| 358 | |
Jane Liu | 1a08402 | 2017-06-29 19:47:12 -0400 | [diff] [blame] | 359 | CPDF_PageObject* pPageObj = CPDFPageObjectFromFPDFPageObject(pageObject); |
wileyrya | f1697fa | 2017-05-26 12:27:40 -0500 | [diff] [blame] | 360 | CFX_FloatRect bbox = pPageObj->GetRect(); |
| 361 | *left = bbox.left; |
| 362 | *bottom = bbox.bottom; |
| 363 | *right = bbox.right; |
| 364 | *top = bbox.top; |
| 365 | return true; |
| 366 | } |