blob: 7b55e4d99de00c8685a69a4e00c99febfa69506e [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_
Dan Sinclair85c8e7f2016-11-21 13:50:32 -050037#include <time.h>
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070038#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) {
tsepez0e606b52016-11-18 16:22:41 -080086 if (FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS))
87 pInfoDict->SetNewFor<CPDF_String>("CreationDate", DateStr, false);
88 pInfoDict->SetNewFor<CPDF_String>("Creator", 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
Lei Zhang85f019a2017-03-17 15:14:19 -0700107 page_index = pdfium::clamp(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
tsepez0e606b52016-11-18 16:22:41 -0800112 CPDF_Array* pMediaBoxArray = pPageDict->SetNewFor<CPDF_Array>("MediaBox");
tsepez8a3aa452016-11-16 12:26:06 -0800113 pMediaBoxArray->AddNew<CPDF_Number>(0);
114 pMediaBoxArray->AddNew<CPDF_Number>(0);
Dan Sinclair05df0752017-03-14 14:43:42 -0400115 pMediaBoxArray->AddNew<CPDF_Number>(static_cast<float>(width));
116 pMediaBoxArray->AddNew<CPDF_Number>(static_cast<float>(height));
tsepez0e606b52016-11-18 16:22:41 -0800117 pPageDict->SetNewFor<CPDF_Number>("Rotate", 0);
118 pPageDict->SetNewFor<CPDF_Dictionary>("Resources");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700119
Tom Sepez40e9ff32015-11-30 12:39:54 -0800120#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700121 CPDFXFA_Page* pPage =
dsinclair521b7502016-11-02 13:02:28 -0700122 new CPDFXFA_Page(static_cast<CPDFXFA_Context*>(document), page_index);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700123 pPage->LoadPDFPage(pPageDict);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800124#else // PDF_ENABLE_XFA
thestig5cc24652016-04-26 11:46:02 -0700125 CPDF_Page* pPage = new CPDF_Page(pDoc, pPageDict, true);
126 pPage->ParseContent();
Tom Sepez40e9ff32015-11-30 12:39:54 -0800127#endif // PDF_ENABLE_XFA
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700128
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700129 return pPage;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700130}
131
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700132DLLEXPORT int STDCALL FPDFPage_GetRotation(FPDF_PAGE page) {
Tom Sepezdb0be962015-10-16 14:00:21 -0700133 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
thestigc54bb432016-07-29 19:34:20 -0700134 if (!IsPageObject(pPage))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700135 return -1;
Lei Zhang997de612015-11-04 18:17:53 -0800136
thestigc54bb432016-07-29 19:34:20 -0700137 CPDF_Dictionary* pDict = pPage->m_pFormDict;
Lei Zhang997de612015-11-04 18:17:53 -0800138 while (pDict) {
139 if (pDict->KeyExist("Rotate")) {
dsinclair38fd8442016-09-15 10:15:32 -0700140 CPDF_Object* pRotateObj = pDict->GetObjectFor("Rotate")->GetDirect();
Lei Zhang997de612015-11-04 18:17:53 -0800141 return pRotateObj ? pRotateObj->GetInteger() / 90 : 0;
142 }
143 if (!pDict->KeyExist("Parent"))
144 break;
145
dsinclair38fd8442016-09-15 10:15:32 -0700146 pDict = ToDictionary(pDict->GetObjectFor("Parent")->GetDirect());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700147 }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700148
Lei Zhang997de612015-11-04 18:17:53 -0800149 return 0;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700150}
151
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700152DLLEXPORT void STDCALL FPDFPage_InsertObject(FPDF_PAGE page,
153 FPDF_PAGEOBJECT page_obj) {
thestigc54bb432016-07-29 19:34:20 -0700154 CPDF_PageObject* pPageObj = reinterpret_cast<CPDF_PageObject*>(page_obj);
Lei Zhang997de612015-11-04 18:17:53 -0800155 if (!pPageObj)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700156 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700157
thestigc54bb432016-07-29 19:34:20 -0700158 std::unique_ptr<CPDF_PageObject> pPageObjHolder(pPageObj);
159 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
160 if (!IsPageObject(pPage))
161 return;
Tom Sepez2398d892016-02-17 16:46:26 -0800162
thestigc54bb432016-07-29 19:34:20 -0700163 pPage->GetPageObjectList()->push_back(std::move(pPageObjHolder));
Wei Li7cf13c92016-02-19 11:53:03 -0800164 switch (pPageObj->GetType()) {
thestigc54bb432016-07-29 19:34:20 -0700165 case CPDF_PageObject::TEXT: {
166 break;
167 }
168 case CPDF_PageObject::PATH: {
Wei Li7cf13c92016-02-19 11:53:03 -0800169 CPDF_PathObject* pPathObj = pPageObj->AsPath();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700170 pPathObj->CalcBoundingBox();
171 break;
172 }
thestigc54bb432016-07-29 19:34:20 -0700173 case CPDF_PageObject::IMAGE: {
Wei Li7cf13c92016-02-19 11:53:03 -0800174 CPDF_ImageObject* pImageObj = pPageObj->AsImage();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700175 pImageObj->CalcBoundingBox();
176 break;
177 }
thestigc54bb432016-07-29 19:34:20 -0700178 case CPDF_PageObject::SHADING: {
Wei Li7cf13c92016-02-19 11:53:03 -0800179 CPDF_ShadingObject* pShadingObj = pPageObj->AsShading();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700180 pShadingObj->CalcBoundingBox();
181 break;
182 }
thestigc54bb432016-07-29 19:34:20 -0700183 case CPDF_PageObject::FORM: {
Wei Li7cf13c92016-02-19 11:53:03 -0800184 CPDF_FormObject* pFormObj = pPageObj->AsForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700185 pFormObj->CalcBoundingBox();
186 break;
187 }
thestigc54bb432016-07-29 19:34:20 -0700188 default: {
189 ASSERT(false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700190 break;
thestigc54bb432016-07-29 19:34:20 -0700191 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700192 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700193}
194
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700195DLLEXPORT int STDCALL FPDFPage_CountObject(FPDF_PAGE page) {
Tom Sepezbf59a072015-10-21 14:07:23 -0700196 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
thestigc54bb432016-07-29 19:34:20 -0700197 if (!IsPageObject(pPage))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700198 return -1;
Tom Sepez2398d892016-02-17 16:46:26 -0800199 return pdfium::CollectionSize<int>(*pPage->GetPageObjectList());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700200}
201
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700202DLLEXPORT FPDF_PAGEOBJECT STDCALL FPDFPage_GetObject(FPDF_PAGE page,
203 int index) {
Tom Sepezdb0be962015-10-16 14:00:21 -0700204 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
thestigc54bb432016-07-29 19:34:20 -0700205 if (!IsPageObject(pPage))
Tom Sepez2398d892016-02-17 16:46:26 -0800206 return nullptr;
Tom Sepez2398d892016-02-17 16:46:26 -0800207 return pPage->GetPageObjectList()->GetPageObjectByIndex(index);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700208}
209
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700210DLLEXPORT FPDF_BOOL STDCALL FPDFPage_HasTransparency(FPDF_PAGE page) {
Tom Sepezdb0be962015-10-16 14:00:21 -0700211 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
212 return pPage && pPage->BackgroundAlphaNeeded();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700213}
214
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700215DLLEXPORT FPDF_BOOL STDCALL
216FPDFPageObj_HasTransparency(FPDF_PAGEOBJECT pageObject) {
217 if (!pageObject)
tsepez4cf55152016-11-02 14:37:54 -0700218 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700219
thestigc54bb432016-07-29 19:34:20 -0700220 CPDF_PageObject* pPageObj = reinterpret_cast<CPDF_PageObject*>(pageObject);
tsepezbbee4452016-09-02 15:22:00 -0700221 int blend_type = pPageObj->m_GeneralState.GetBlendType();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700222 if (blend_type != FXDIB_BLEND_NORMAL)
tsepez4cf55152016-11-02 14:37:54 -0700223 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700224
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700225 CPDF_Dictionary* pSMaskDict =
tsepezbbee4452016-09-02 15:22:00 -0700226 ToDictionary(pPageObj->m_GeneralState.GetSoftMask());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700227 if (pSMaskDict)
tsepez4cf55152016-11-02 14:37:54 -0700228 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700229
tsepezbbee4452016-09-02 15:22:00 -0700230 if (pPageObj->m_GeneralState.GetFillAlpha() != 1.0f)
tsepez4cf55152016-11-02 14:37:54 -0700231 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700232
tsepezbbee4452016-09-02 15:22:00 -0700233 if (pPageObj->IsPath() && pPageObj->m_GeneralState.GetStrokeAlpha() != 1.0f) {
tsepez4cf55152016-11-02 14:37:54 -0700234 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700235 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700236
Wei Li7cf13c92016-02-19 11:53:03 -0800237 if (pPageObj->IsForm()) {
thestigc54bb432016-07-29 19:34:20 -0700238 const CPDF_Form* pForm = pPageObj->AsForm()->form();
239 if (pForm) {
240 int trans = pForm->m_Transparency;
241 if ((trans & PDFTRANS_ISOLATED) || (trans & PDFTRANS_GROUP))
tsepez4cf55152016-11-02 14:37:54 -0700242 return true;
thestigc54bb432016-07-29 19:34:20 -0700243 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700244 }
thestigc54bb432016-07-29 19:34:20 -0700245
tsepez4cf55152016-11-02 14:37:54 -0700246 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700247}
248
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700249DLLEXPORT FPDF_BOOL STDCALL FPDFPage_GenerateContent(FPDF_PAGE page) {
Tom Sepezdb0be962015-10-16 14:00:21 -0700250 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
thestigc54bb432016-07-29 19:34:20 -0700251 if (!IsPageObject(pPage))
tsepez4cf55152016-11-02 14:37:54 -0700252 return false;
thestigc54bb432016-07-29 19:34:20 -0700253
Tom Sepeze19e06e2016-01-21 10:49:56 -0800254 CPDF_PageContentGenerator CG(pPage);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700255 CG.GenerateContent();
tsepez4cf55152016-11-02 14:37:54 -0700256 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700257}
258
259DLLEXPORT void STDCALL FPDFPageObj_Transform(FPDF_PAGEOBJECT page_object,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700260 double a,
261 double b,
262 double c,
263 double d,
264 double e,
265 double f) {
thestigc54bb432016-07-29 19:34:20 -0700266 CPDF_PageObject* pPageObj = reinterpret_cast<CPDF_PageObject*>(page_object);
Lei Zhang997de612015-11-04 18:17:53 -0800267 if (!pPageObj)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700268 return;
Lei Zhangcb78ef52015-10-02 10:10:49 -0700269
Dan Sinclair05df0752017-03-14 14:43:42 -0400270 CFX_Matrix matrix((float)a, (float)b, (float)c, (float)d, (float)e, (float)f);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700271 pPageObj->Transform(matrix);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700272}
thestigc54bb432016-07-29 19:34:20 -0700273
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700274DLLEXPORT void STDCALL FPDFPage_TransformAnnots(FPDF_PAGE page,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700275 double a,
276 double b,
277 double c,
278 double d,
279 double e,
280 double f) {
Tom Sepezdb0be962015-10-16 14:00:21 -0700281 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700282 if (!pPage)
283 return;
thestigc54bb432016-07-29 19:34:20 -0700284
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700285 CPDF_AnnotList AnnotList(pPage);
Lei Zhang1b700c32015-10-30 23:55:35 -0700286 for (size_t i = 0; i < AnnotList.Count(); ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700287 CPDF_Annot* pAnnot = AnnotList.GetAt(i);
tsepez8021a642016-10-17 16:13:21 -0700288 CFX_FloatRect rect = pAnnot->GetRect(); // transformAnnots Rectangle
Dan Sinclair05df0752017-03-14 14:43:42 -0400289 CFX_Matrix matrix((float)a, (float)b, (float)c, (float)d, (float)e,
290 (float)f);
Dan Sinclair118a8e22017-02-09 10:16:07 -0500291 matrix.TransformRect(rect);
tsepez8021a642016-10-17 16:13:21 -0700292
dsinclair38fd8442016-09-15 10:15:32 -0700293 CPDF_Array* pRectArray = pAnnot->GetAnnotDict()->GetArrayFor("Rect");
tsepez0e606b52016-11-18 16:22:41 -0800294 if (!pRectArray)
295 pRectArray = pAnnot->GetAnnotDict()->SetNewFor<CPDF_Array>("Rect");
296
tsepez8a3aa452016-11-16 12:26:06 -0800297 pRectArray->SetNewAt<CPDF_Number>(0, rect.left);
298 pRectArray->SetNewAt<CPDF_Number>(1, rect.bottom);
299 pRectArray->SetNewAt<CPDF_Number>(2, rect.right);
300 pRectArray->SetNewAt<CPDF_Number>(3, rect.top);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700301
Dan Sinclair85c8e7f2016-11-21 13:50:32 -0500302 // TODO(unknown): Transform AP's rectangle
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700303 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700304}
Bo Xu394010d2014-06-12 13:41:50 -0700305
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700306DLLEXPORT void STDCALL FPDFPage_SetRotation(FPDF_PAGE page, int rotate) {
Tom Sepezdb0be962015-10-16 14:00:21 -0700307 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
thestigc54bb432016-07-29 19:34:20 -0700308 if (!IsPageObject(pPage))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700309 return;
thestigc54bb432016-07-29 19:34:20 -0700310
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700311 CPDF_Dictionary* pDict = pPage->m_pFormDict;
312 rotate %= 4;
tsepez0e606b52016-11-18 16:22:41 -0800313 pDict->SetNewFor<CPDF_Number>("Rotate", rotate * 90);
Nico Weber0ce77e32014-07-16 13:19:08 -0700314}