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 | |
| 64 | } // namespace |
| 65 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 66 | DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_CreateNewDocument() { |
Tom Sepez | fe91c6c | 2017-05-16 15:33:20 -0700 | [diff] [blame] | 67 | auto pDoc = pdfium::MakeUnique<CPDF_Document>(nullptr); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 68 | pDoc->CreateNewDoc(); |
Tom Sepez | fe91c6c | 2017-05-16 15:33:20 -0700 | [diff] [blame] | 69 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 70 | time_t currentTime; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 71 | CFX_ByteString DateStr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 72 | if (FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS)) { |
Tom Sepez | fe91c6c | 2017-05-16 15:33:20 -0700 | [diff] [blame] | 73 | if (time(¤tTime) != -1) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 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 | |
Tom Sepez | fe91c6c | 2017-05-16 15:33:20 -0700 | [diff] [blame] | 83 | CPDF_Dictionary* pInfoDict = pDoc->GetInfo(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 84 | if (pInfoDict) { |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 85 | if (FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS)) |
| 86 | pInfoDict->SetNewFor<CPDF_String>("CreationDate", DateStr, false); |
| 87 | pInfoDict->SetNewFor<CPDF_String>("Creator", L"PDFium"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 88 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 89 | |
Tom Sepez | fe91c6c | 2017-05-16 15:33:20 -0700 | [diff] [blame] | 90 | // Caller takes ownership of pDoc. |
| 91 | return FPDFDocumentFromCPDFDocument(pDoc.release()); |
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 |
Tom Sepez | 9792f16 | 2017-05-16 14:11:30 -0700 | [diff] [blame] | 121 | auto pXFAPage = pdfium::MakeRetain<CPDFXFA_Page>( |
| 122 | static_cast<CPDFXFA_Context*>(document), page_index); |
| 123 | pXFAPage->LoadPDFPage(pPageDict); |
Tom Sepez | fe91c6c | 2017-05-16 15:33:20 -0700 | [diff] [blame] | 124 | return pXFAPage.Leak(); // Caller takes ownership. |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 125 | #else // PDF_ENABLE_XFA |
Tom Sepez | fe91c6c | 2017-05-16 15:33:20 -0700 | [diff] [blame] | 126 | auto pPage = pdfium::MakeUnique<CPDF_Page>(pDoc, pPageDict, true); |
thestig | 5cc2465 | 2016-04-26 11:46:02 -0700 | [diff] [blame] | 127 | pPage->ParseContent(); |
Tom Sepez | fe91c6c | 2017-05-16 15:33:20 -0700 | [diff] [blame] | 128 | return pPage.release(); // Caller takes ownership. |
Tom Sepez | 9792f16 | 2017-05-16 14:11:30 -0700 | [diff] [blame] | 129 | #endif // PDF_ENABLE_XFA |
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); |
Tom Sepez | fe91c6c | 2017-05-16 15:33:20 -0700 | [diff] [blame] | 134 | return IsPageObject(pPage) ? pPage->GetPageRotation() : -1; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 135 | } |
| 136 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 137 | DLLEXPORT void STDCALL FPDFPage_InsertObject(FPDF_PAGE page, |
| 138 | FPDF_PAGEOBJECT page_obj) { |
Nicolas Pena | 46abb66 | 2017-05-17 17:23:22 -0400 | [diff] [blame] | 139 | CPDF_PageObject* pPageObj = static_cast<CPDF_PageObject*>(page_obj); |
Lei Zhang | 997de61 | 2015-11-04 18:17:53 -0800 | [diff] [blame] | 140 | if (!pPageObj) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 141 | return; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 142 | |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 143 | std::unique_ptr<CPDF_PageObject> pPageObjHolder(pPageObj); |
| 144 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
| 145 | if (!IsPageObject(pPage)) |
| 146 | return; |
Tom Sepez | 2398d89 | 2016-02-17 16:46:26 -0800 | [diff] [blame] | 147 | |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 148 | pPage->GetPageObjectList()->push_back(std::move(pPageObjHolder)); |
Wei Li | 7cf13c9 | 2016-02-19 11:53:03 -0800 | [diff] [blame] | 149 | switch (pPageObj->GetType()) { |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 150 | case CPDF_PageObject::TEXT: { |
| 151 | break; |
| 152 | } |
| 153 | case CPDF_PageObject::PATH: { |
Wei Li | 7cf13c9 | 2016-02-19 11:53:03 -0800 | [diff] [blame] | 154 | CPDF_PathObject* pPathObj = pPageObj->AsPath(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 155 | pPathObj->CalcBoundingBox(); |
| 156 | break; |
| 157 | } |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 158 | case CPDF_PageObject::IMAGE: { |
Wei Li | 7cf13c9 | 2016-02-19 11:53:03 -0800 | [diff] [blame] | 159 | CPDF_ImageObject* pImageObj = pPageObj->AsImage(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 160 | pImageObj->CalcBoundingBox(); |
| 161 | break; |
| 162 | } |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 163 | case CPDF_PageObject::SHADING: { |
Wei Li | 7cf13c9 | 2016-02-19 11:53:03 -0800 | [diff] [blame] | 164 | CPDF_ShadingObject* pShadingObj = pPageObj->AsShading(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 165 | pShadingObj->CalcBoundingBox(); |
| 166 | break; |
| 167 | } |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 168 | case CPDF_PageObject::FORM: { |
Wei Li | 7cf13c9 | 2016-02-19 11:53:03 -0800 | [diff] [blame] | 169 | CPDF_FormObject* pFormObj = pPageObj->AsForm(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 170 | pFormObj->CalcBoundingBox(); |
| 171 | break; |
| 172 | } |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 173 | default: { |
Lei Zhang | b45324b | 2017-05-22 17:05:40 -0700 | [diff] [blame^] | 174 | NOTREACHED(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 175 | break; |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 176 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 177 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 178 | } |
| 179 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 180 | DLLEXPORT int STDCALL FPDFPage_CountObject(FPDF_PAGE page) { |
Tom Sepez | bf59a07 | 2015-10-21 14:07:23 -0700 | [diff] [blame] | 181 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 182 | if (!IsPageObject(pPage)) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 183 | return -1; |
Tom Sepez | 2398d89 | 2016-02-17 16:46:26 -0800 | [diff] [blame] | 184 | return pdfium::CollectionSize<int>(*pPage->GetPageObjectList()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 185 | } |
| 186 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 187 | DLLEXPORT FPDF_PAGEOBJECT STDCALL FPDFPage_GetObject(FPDF_PAGE page, |
| 188 | int index) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 189 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 190 | if (!IsPageObject(pPage)) |
Tom Sepez | 2398d89 | 2016-02-17 16:46:26 -0800 | [diff] [blame] | 191 | return nullptr; |
Tom Sepez | 2398d89 | 2016-02-17 16:46:26 -0800 | [diff] [blame] | 192 | return pPage->GetPageObjectList()->GetPageObjectByIndex(index); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 193 | } |
| 194 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 195 | DLLEXPORT FPDF_BOOL STDCALL FPDFPage_HasTransparency(FPDF_PAGE page) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 196 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
| 197 | return pPage && pPage->BackgroundAlphaNeeded(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 198 | } |
| 199 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 200 | DLLEXPORT FPDF_BOOL STDCALL |
| 201 | FPDFPageObj_HasTransparency(FPDF_PAGEOBJECT pageObject) { |
| 202 | if (!pageObject) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 203 | return false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 204 | |
Nicolas Pena | 46abb66 | 2017-05-17 17:23:22 -0400 | [diff] [blame] | 205 | CPDF_PageObject* pPageObj = static_cast<CPDF_PageObject*>(pageObject); |
tsepez | bbee445 | 2016-09-02 15:22:00 -0700 | [diff] [blame] | 206 | int blend_type = pPageObj->m_GeneralState.GetBlendType(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 207 | if (blend_type != FXDIB_BLEND_NORMAL) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 208 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 209 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 210 | CPDF_Dictionary* pSMaskDict = |
tsepez | bbee445 | 2016-09-02 15:22:00 -0700 | [diff] [blame] | 211 | ToDictionary(pPageObj->m_GeneralState.GetSoftMask()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 212 | if (pSMaskDict) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 213 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 214 | |
tsepez | bbee445 | 2016-09-02 15:22:00 -0700 | [diff] [blame] | 215 | if (pPageObj->m_GeneralState.GetFillAlpha() != 1.0f) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 216 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 217 | |
tsepez | bbee445 | 2016-09-02 15:22:00 -0700 | [diff] [blame] | 218 | if (pPageObj->IsPath() && pPageObj->m_GeneralState.GetStrokeAlpha() != 1.0f) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 219 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 220 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 221 | |
Wei Li | 7cf13c9 | 2016-02-19 11:53:03 -0800 | [diff] [blame] | 222 | if (pPageObj->IsForm()) { |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 223 | const CPDF_Form* pForm = pPageObj->AsForm()->form(); |
| 224 | if (pForm) { |
| 225 | int trans = pForm->m_Transparency; |
| 226 | if ((trans & PDFTRANS_ISOLATED) || (trans & PDFTRANS_GROUP)) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 227 | return true; |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 228 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 229 | } |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 230 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 231 | return false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 232 | } |
| 233 | |
Miklos Vajna | 1423319 | 2017-04-03 16:02:39 +0200 | [diff] [blame] | 234 | DLLEXPORT int STDCALL FPDFPageObj_GetType(FPDF_PAGEOBJECT pageObject) { |
| 235 | if (!pageObject) |
| 236 | return FPDF_PAGEOBJ_UNKNOWN; |
| 237 | |
Nicolas Pena | 46abb66 | 2017-05-17 17:23:22 -0400 | [diff] [blame] | 238 | CPDF_PageObject* pPageObj = static_cast<CPDF_PageObject*>(pageObject); |
Miklos Vajna | 1423319 | 2017-04-03 16:02:39 +0200 | [diff] [blame] | 239 | return pPageObj->GetType(); |
| 240 | } |
| 241 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 242 | DLLEXPORT FPDF_BOOL STDCALL FPDFPage_GenerateContent(FPDF_PAGE page) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 243 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 244 | if (!IsPageObject(pPage)) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 245 | return false; |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 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(); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 249 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | DLLEXPORT void STDCALL FPDFPageObj_Transform(FPDF_PAGEOBJECT page_object, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 253 | double a, |
| 254 | double b, |
| 255 | double c, |
| 256 | double d, |
| 257 | double e, |
| 258 | double f) { |
Nicolas Pena | 46abb66 | 2017-05-17 17:23:22 -0400 | [diff] [blame] | 259 | CPDF_PageObject* pPageObj = static_cast<CPDF_PageObject*>(page_object); |
Lei Zhang | 997de61 | 2015-11-04 18:17:53 -0800 | [diff] [blame] | 260 | if (!pPageObj) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 261 | return; |
Lei Zhang | cb78ef5 | 2015-10-02 10:10:49 -0700 | [diff] [blame] | 262 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 263 | 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] | 264 | pPageObj->Transform(matrix); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 265 | } |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 266 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 267 | DLLEXPORT void STDCALL FPDFPage_TransformAnnots(FPDF_PAGE page, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 268 | double a, |
| 269 | double b, |
| 270 | double c, |
| 271 | double d, |
| 272 | double e, |
| 273 | double f) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 274 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 275 | if (!pPage) |
| 276 | return; |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 277 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 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); |
tsepez | 8021a64 | 2016-10-17 16:13:21 -0700 | [diff] [blame] | 281 | CFX_FloatRect rect = pAnnot->GetRect(); // transformAnnots Rectangle |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 282 | CFX_Matrix matrix((float)a, (float)b, (float)c, (float)d, (float)e, |
| 283 | (float)f); |
Dan Sinclair | 118a8e2 | 2017-02-09 10:16:07 -0500 | [diff] [blame] | 284 | matrix.TransformRect(rect); |
tsepez | 8021a64 | 2016-10-17 16:13:21 -0700 | [diff] [blame] | 285 | |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 286 | CPDF_Array* pRectArray = pAnnot->GetAnnotDict()->GetArrayFor("Rect"); |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 287 | if (!pRectArray) |
| 288 | pRectArray = pAnnot->GetAnnotDict()->SetNewFor<CPDF_Array>("Rect"); |
| 289 | |
tsepez | 8a3aa45 | 2016-11-16 12:26:06 -0800 | [diff] [blame] | 290 | pRectArray->SetNewAt<CPDF_Number>(0, rect.left); |
| 291 | pRectArray->SetNewAt<CPDF_Number>(1, rect.bottom); |
| 292 | pRectArray->SetNewAt<CPDF_Number>(2, rect.right); |
| 293 | pRectArray->SetNewAt<CPDF_Number>(3, rect.top); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 294 | |
Dan Sinclair | 85c8e7f | 2016-11-21 13:50:32 -0500 | [diff] [blame] | 295 | // TODO(unknown): Transform AP's rectangle |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 296 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 297 | } |
Bo Xu | 394010d | 2014-06-12 13:41:50 -0700 | [diff] [blame] | 298 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 299 | DLLEXPORT void STDCALL FPDFPage_SetRotation(FPDF_PAGE page, int rotate) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 300 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 301 | if (!IsPageObject(pPage)) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 302 | return; |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 303 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 304 | rotate %= 4; |
Tom Sepez | 4cb82ee | 2017-05-22 15:15:30 -0700 | [diff] [blame] | 305 | pPage->m_pFormDict->SetNewFor<CPDF_Number>("Rotate", rotate * 90); |
Nico Weber | 0ce77e3 | 2014-07-16 13:19:08 -0700 | [diff] [blame] | 306 | } |