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