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