blob: be9ae67be416ac328cd86c3e3de23955fd91c621 [file] [log] [blame]
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001// 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 Zhanga6d9f0e2015-06-13 00:48:38 -07004
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
Lei Zhangb4e7f302015-11-06 15:52:32 -08007#include "public/fpdf_edit.h"
8
thestigc54bb432016-07-29 19:34:20 -07009#include <algorithm>
10#include <memory>
11#include <utility>
12
dsinclair24154352016-10-04 11:01:48 -070013#include "core/fpdfapi/edit/cpdf_pagecontentgenerator.h"
dsinclair41872fa2016-10-04 11:29:35 -070014#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"
dsinclair488b7ad2016-10-04 11:55:50 -070021#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"
dsinclair1727aee2016-09-29 13:12:56 -070025#include "core/fpdfdoc/cpdf_annot.h"
26#include "core/fpdfdoc/cpdf_annotlist.h"
dsinclair114e46a2016-09-29 17:18:21 -070027#include "fpdfsdk/fsdk_define.h"
Tom Sepez40e9ff32015-11-30 12:39:54 -080028#include "public/fpdf_formfill.h"
Tom Sepez2398d892016-02-17 16:46:26 -080029#include "third_party/base/stl_util.h"
Tom Sepez40e9ff32015-11-30 12:39:54 -080030
Tom Sepez51da0932015-11-25 16:05:49 -080031#ifdef PDF_ENABLE_XFA
dsinclair521b7502016-11-02 13:02:28 -070032#include "fpdfsdk/fpdfxfa/cpdfxfa_context.h"
dsinclair4d29e782016-10-04 14:02:47 -070033#include "fpdfsdk/fpdfxfa/cpdfxfa_page.h"
Tom Sepez40e9ff32015-11-30 12:39:54 -080034#endif // PDF_ENABLE_XFA
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070035
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070036#if _FX_OS_ == _FX_ANDROID_
37#include "time.h"
38#else
39#include <ctime>
40#endif
41
thestigc54bb432016-07-29 19:34:20 -070042namespace {
43
44static_assert(FPDF_PAGEOBJ_TEXT == CPDF_PageObject::TEXT,
45 "FPDF_PAGEOBJ_TEXT/CPDF_PageObject::TEXT mismatch");
46static_assert(FPDF_PAGEOBJ_PATH == CPDF_PageObject::PATH,
47 "FPDF_PAGEOBJ_PATH/CPDF_PageObject::PATH mismatch");
48static_assert(FPDF_PAGEOBJ_IMAGE == CPDF_PageObject::IMAGE,
49 "FPDF_PAGEOBJ_IMAGE/CPDF_PageObject::IMAGE mismatch");
50static_assert(FPDF_PAGEOBJ_SHADING == CPDF_PageObject::SHADING,
51 "FPDF_PAGEOBJ_SHADING/CPDF_PageObject::SHADING mismatch");
52static_assert(FPDF_PAGEOBJ_FORM == CPDF_PageObject::FORM,
53 "FPDF_PAGEOBJ_FORM/CPDF_PageObject::FORM mismatch");
54
55bool IsPageObject(CPDF_Page* pPage) {
56 if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type"))
57 return false;
58
dsinclair38fd8442016-09-15 10:15:32 -070059 CPDF_Object* pObject = pPage->m_pFormDict->GetObjectFor("Type")->GetDirect();
thestigc54bb432016-07-29 19:34:20 -070060 return pObject && !pObject->GetString().Compare("Page");
61}
62
63} // namespace
64
Nico Weber9d8ec5a2015-08-04 13:00:21 -070065DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_CreateNewDocument() {
thestig931bf372016-04-26 22:24:30 -070066 CPDF_Document* pDoc = new CPDF_Document(nullptr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070067 pDoc->CreateNewDoc();
68 time_t currentTime;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070069
Nico Weber9d8ec5a2015-08-04 13:00:21 -070070 CFX_ByteString DateStr;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070071
Nico Weber9d8ec5a2015-08-04 13:00:21 -070072 if (FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS)) {
73 if (-1 != time(&currentTime)) {
74 tm* pTM = localtime(&currentTime);
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 Sepezbdeeb8a2015-05-27 12:25:00 -070082
thestig1cd352e2016-06-07 17:53:06 -070083 CPDF_Dictionary* pInfoDict = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070084 pInfoDict = pDoc->GetInfo();
85 if (pInfoDict) {
86 if (FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS))
dsinclair38fd8442016-09-15 10:15:32 -070087 pInfoDict->SetFor("CreationDate", new CPDF_String(DateStr, FALSE));
88 pInfoDict->SetFor("Creator", new CPDF_String(L"PDFium"));
Nico Weber9d8ec5a2015-08-04 13:00:21 -070089 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070090
Tom Sepezbf59a072015-10-21 14:07:23 -070091 return FPDFDocumentFromCPDFDocument(pDoc);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070092}
93
Nico Weber9d8ec5a2015-08-04 13:00:21 -070094DLLEXPORT void STDCALL FPDFPage_Delete(FPDF_DOCUMENT document, int page_index) {
Tom Sepez744da702016-03-15 12:43:09 -070095 if (UnderlyingDocumentType* pDoc = UnderlyingFromFPDFDocument(document))
96 pDoc->DeletePage(page_index);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070097}
98
Nico Weber9d8ec5a2015-08-04 13:00:21 -070099DLLEXPORT FPDF_PAGE STDCALL FPDFPage_New(FPDF_DOCUMENT document,
100 int page_index,
101 double width,
102 double height) {
Tom Sepez471a1032015-10-15 16:17:18 -0700103 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
104 if (!pDoc)
105 return nullptr;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700106
thestigc54bb432016-07-29 19:34:20 -0700107 page_index = std::min(std::max(page_index, 0), pDoc->GetPageCount());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700108 CPDF_Dictionary* pPageDict = pDoc->CreateNewPage(page_index);
109 if (!pPageDict)
thestig1cd352e2016-06-07 17:53:06 -0700110 return nullptr;
thestigc54bb432016-07-29 19:34:20 -0700111
Tom Sepezae51c812015-08-05 12:34:06 -0700112 CPDF_Array* pMediaBoxArray = new CPDF_Array;
113 pMediaBoxArray->Add(new CPDF_Number(0));
114 pMediaBoxArray->Add(new CPDF_Number(0));
115 pMediaBoxArray->Add(new CPDF_Number(FX_FLOAT(width)));
116 pMediaBoxArray->Add(new CPDF_Number(FX_FLOAT(height)));
dsinclair38fd8442016-09-15 10:15:32 -0700117 pPageDict->SetFor("MediaBox", pMediaBoxArray);
118 pPageDict->SetFor("Rotate", new CPDF_Number(0));
tsepez698c5712016-09-28 16:47:07 -0700119 pPageDict->SetFor("Resources",
120 new CPDF_Dictionary(pDoc->GetByteStringPool()));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700121
Tom Sepez40e9ff32015-11-30 12:39:54 -0800122#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700123 CPDFXFA_Page* pPage =
dsinclair521b7502016-11-02 13:02:28 -0700124 new CPDFXFA_Page(static_cast<CPDFXFA_Context*>(document), page_index);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700125 pPage->LoadPDFPage(pPageDict);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800126#else // PDF_ENABLE_XFA
thestig5cc24652016-04-26 11:46:02 -0700127 CPDF_Page* pPage = new CPDF_Page(pDoc, pPageDict, true);
128 pPage->ParseContent();
Tom Sepez40e9ff32015-11-30 12:39:54 -0800129#endif // PDF_ENABLE_XFA
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700130
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700131 return pPage;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700132}
133
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700134DLLEXPORT int STDCALL FPDFPage_GetRotation(FPDF_PAGE page) {
Tom Sepezdb0be962015-10-16 14:00:21 -0700135 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
thestigc54bb432016-07-29 19:34:20 -0700136 if (!IsPageObject(pPage))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700137 return -1;
Lei Zhang997de612015-11-04 18:17:53 -0800138
thestigc54bb432016-07-29 19:34:20 -0700139 CPDF_Dictionary* pDict = pPage->m_pFormDict;
Lei Zhang997de612015-11-04 18:17:53 -0800140 while (pDict) {
141 if (pDict->KeyExist("Rotate")) {
dsinclair38fd8442016-09-15 10:15:32 -0700142 CPDF_Object* pRotateObj = pDict->GetObjectFor("Rotate")->GetDirect();
Lei Zhang997de612015-11-04 18:17:53 -0800143 return pRotateObj ? pRotateObj->GetInteger() / 90 : 0;
144 }
145 if (!pDict->KeyExist("Parent"))
146 break;
147
dsinclair38fd8442016-09-15 10:15:32 -0700148 pDict = ToDictionary(pDict->GetObjectFor("Parent")->GetDirect());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700149 }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700150
Lei Zhang997de612015-11-04 18:17:53 -0800151 return 0;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700152}
153
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700154DLLEXPORT void STDCALL FPDFPage_InsertObject(FPDF_PAGE page,
155 FPDF_PAGEOBJECT page_obj) {
thestigc54bb432016-07-29 19:34:20 -0700156 CPDF_PageObject* pPageObj = reinterpret_cast<CPDF_PageObject*>(page_obj);
Lei Zhang997de612015-11-04 18:17:53 -0800157 if (!pPageObj)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700158 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700159
thestigc54bb432016-07-29 19:34:20 -0700160 std::unique_ptr<CPDF_PageObject> pPageObjHolder(pPageObj);
161 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
162 if (!IsPageObject(pPage))
163 return;
Tom Sepez2398d892016-02-17 16:46:26 -0800164
thestigc54bb432016-07-29 19:34:20 -0700165 pPage->GetPageObjectList()->push_back(std::move(pPageObjHolder));
Wei Li7cf13c92016-02-19 11:53:03 -0800166 switch (pPageObj->GetType()) {
thestigc54bb432016-07-29 19:34:20 -0700167 case CPDF_PageObject::TEXT: {
168 break;
169 }
170 case CPDF_PageObject::PATH: {
Wei Li7cf13c92016-02-19 11:53:03 -0800171 CPDF_PathObject* pPathObj = pPageObj->AsPath();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700172 pPathObj->CalcBoundingBox();
173 break;
174 }
thestigc54bb432016-07-29 19:34:20 -0700175 case CPDF_PageObject::IMAGE: {
Wei Li7cf13c92016-02-19 11:53:03 -0800176 CPDF_ImageObject* pImageObj = pPageObj->AsImage();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700177 pImageObj->CalcBoundingBox();
178 break;
179 }
thestigc54bb432016-07-29 19:34:20 -0700180 case CPDF_PageObject::SHADING: {
Wei Li7cf13c92016-02-19 11:53:03 -0800181 CPDF_ShadingObject* pShadingObj = pPageObj->AsShading();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700182 pShadingObj->CalcBoundingBox();
183 break;
184 }
thestigc54bb432016-07-29 19:34:20 -0700185 case CPDF_PageObject::FORM: {
Wei Li7cf13c92016-02-19 11:53:03 -0800186 CPDF_FormObject* pFormObj = pPageObj->AsForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700187 pFormObj->CalcBoundingBox();
188 break;
189 }
thestigc54bb432016-07-29 19:34:20 -0700190 default: {
191 ASSERT(false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700192 break;
thestigc54bb432016-07-29 19:34:20 -0700193 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700194 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700195}
196
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700197DLLEXPORT int STDCALL FPDFPage_CountObject(FPDF_PAGE page) {
Tom Sepezbf59a072015-10-21 14:07:23 -0700198 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
thestigc54bb432016-07-29 19:34:20 -0700199 if (!IsPageObject(pPage))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700200 return -1;
Tom Sepez2398d892016-02-17 16:46:26 -0800201 return pdfium::CollectionSize<int>(*pPage->GetPageObjectList());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700202}
203
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700204DLLEXPORT FPDF_PAGEOBJECT STDCALL FPDFPage_GetObject(FPDF_PAGE page,
205 int index) {
Tom Sepezdb0be962015-10-16 14:00:21 -0700206 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
thestigc54bb432016-07-29 19:34:20 -0700207 if (!IsPageObject(pPage))
Tom Sepez2398d892016-02-17 16:46:26 -0800208 return nullptr;
Tom Sepez2398d892016-02-17 16:46:26 -0800209 return pPage->GetPageObjectList()->GetPageObjectByIndex(index);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700210}
211
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700212DLLEXPORT FPDF_BOOL STDCALL FPDFPage_HasTransparency(FPDF_PAGE page) {
Tom Sepezdb0be962015-10-16 14:00:21 -0700213 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
214 return pPage && pPage->BackgroundAlphaNeeded();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700215}
216
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700217DLLEXPORT FPDF_BOOL STDCALL
218FPDFPageObj_HasTransparency(FPDF_PAGEOBJECT pageObject) {
219 if (!pageObject)
220 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700221
thestigc54bb432016-07-29 19:34:20 -0700222 CPDF_PageObject* pPageObj = reinterpret_cast<CPDF_PageObject*>(pageObject);
tsepezbbee4452016-09-02 15:22:00 -0700223 int blend_type = pPageObj->m_GeneralState.GetBlendType();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700224 if (blend_type != FXDIB_BLEND_NORMAL)
225 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700226
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700227 CPDF_Dictionary* pSMaskDict =
tsepezbbee4452016-09-02 15:22:00 -0700228 ToDictionary(pPageObj->m_GeneralState.GetSoftMask());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700229 if (pSMaskDict)
230 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700231
tsepezbbee4452016-09-02 15:22:00 -0700232 if (pPageObj->m_GeneralState.GetFillAlpha() != 1.0f)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700233 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700234
tsepezbbee4452016-09-02 15:22:00 -0700235 if (pPageObj->IsPath() && pPageObj->m_GeneralState.GetStrokeAlpha() != 1.0f) {
thestigc54bb432016-07-29 19:34:20 -0700236 return TRUE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700237 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700238
Wei Li7cf13c92016-02-19 11:53:03 -0800239 if (pPageObj->IsForm()) {
thestigc54bb432016-07-29 19:34:20 -0700240 const CPDF_Form* pForm = pPageObj->AsForm()->form();
241 if (pForm) {
242 int trans = pForm->m_Transparency;
243 if ((trans & PDFTRANS_ISOLATED) || (trans & PDFTRANS_GROUP))
244 return TRUE;
245 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700246 }
thestigc54bb432016-07-29 19:34:20 -0700247
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700248 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700249}
250
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700251DLLEXPORT FPDF_BOOL STDCALL FPDFPage_GenerateContent(FPDF_PAGE page) {
Tom Sepezdb0be962015-10-16 14:00:21 -0700252 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
thestigc54bb432016-07-29 19:34:20 -0700253 if (!IsPageObject(pPage))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700254 return FALSE;
thestigc54bb432016-07-29 19:34:20 -0700255
Tom Sepeze19e06e2016-01-21 10:49:56 -0800256 CPDF_PageContentGenerator CG(pPage);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700257 CG.GenerateContent();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700258 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700259}
260
261DLLEXPORT void STDCALL FPDFPageObj_Transform(FPDF_PAGEOBJECT page_object,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700262 double a,
263 double b,
264 double c,
265 double d,
266 double e,
267 double f) {
thestigc54bb432016-07-29 19:34:20 -0700268 CPDF_PageObject* pPageObj = reinterpret_cast<CPDF_PageObject*>(page_object);
Lei Zhang997de612015-11-04 18:17:53 -0800269 if (!pPageObj)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700270 return;
Lei Zhangcb78ef52015-10-02 10:10:49 -0700271
Tom Sepez60d909e2015-12-10 15:34:55 -0800272 CFX_Matrix matrix((FX_FLOAT)a, (FX_FLOAT)b, (FX_FLOAT)c, (FX_FLOAT)d,
273 (FX_FLOAT)e, (FX_FLOAT)f);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700274 pPageObj->Transform(matrix);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700275}
thestigc54bb432016-07-29 19:34:20 -0700276
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700277DLLEXPORT void STDCALL FPDFPage_TransformAnnots(FPDF_PAGE page,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700278 double a,
279 double b,
280 double c,
281 double d,
282 double e,
283 double f) {
Tom Sepezdb0be962015-10-16 14:00:21 -0700284 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700285 if (!pPage)
286 return;
thestigc54bb432016-07-29 19:34:20 -0700287
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700288 CPDF_AnnotList AnnotList(pPage);
Lei Zhang1b700c32015-10-30 23:55:35 -0700289 for (size_t i = 0; i < AnnotList.Count(); ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700290 CPDF_Annot* pAnnot = AnnotList.GetAt(i);
tsepez8021a642016-10-17 16:13:21 -0700291 CFX_FloatRect rect = pAnnot->GetRect(); // transformAnnots Rectangle
Tom Sepez60d909e2015-12-10 15:34:55 -0800292 CFX_Matrix matrix((FX_FLOAT)a, (FX_FLOAT)b, (FX_FLOAT)c, (FX_FLOAT)d,
293 (FX_FLOAT)e, (FX_FLOAT)f);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700294 rect.Transform(&matrix);
tsepez8021a642016-10-17 16:13:21 -0700295
dsinclair38fd8442016-09-15 10:15:32 -0700296 CPDF_Array* pRectArray = pAnnot->GetAnnotDict()->GetArrayFor("Rect");
tsepez8021a642016-10-17 16:13:21 -0700297 if (!pRectArray) {
Lei Zhang4880d1a2015-12-18 17:05:11 -0800298 pRectArray = new CPDF_Array;
tsepez8021a642016-10-17 16:13:21 -0700299 pAnnot->GetAnnotDict()->SetFor("Rect", pRectArray);
300 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700301 pRectArray->SetAt(0, new CPDF_Number(rect.left));
302 pRectArray->SetAt(1, new CPDF_Number(rect.bottom));
303 pRectArray->SetAt(2, new CPDF_Number(rect.right));
304 pRectArray->SetAt(3, new CPDF_Number(rect.top));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700305
tsepez8021a642016-10-17 16:13:21 -0700306 // TODO: Transform AP's rectangle
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700307 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700308}
Bo Xu394010d2014-06-12 13:41:50 -0700309
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700310DLLEXPORT void STDCALL FPDFPage_SetRotation(FPDF_PAGE page, int rotate) {
Tom Sepezdb0be962015-10-16 14:00:21 -0700311 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
thestigc54bb432016-07-29 19:34:20 -0700312 if (!IsPageObject(pPage))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700313 return;
thestigc54bb432016-07-29 19:34:20 -0700314
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700315 CPDF_Dictionary* pDict = pPage->m_pFormDict;
316 rotate %= 4;
dsinclair38fd8442016-09-15 10:15:32 -0700317 pDict->SetFor("Rotate", new CPDF_Number(rotate * 90));
Nico Weber0ce77e32014-07-16 13:19:08 -0700318}