blob: 6ed375807fccd7f57154ac5bb3cfce3aa39cadee [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"
Lei Zhangb45324b2017-05-22 17:05:40 -070029#include "third_party/base/logging.h"
Tom Sepez2398d892016-02-17 16:46:26 -080030#include "third_party/base/stl_util.h"
Tom Sepez40e9ff32015-11-30 12:39:54 -080031
Tom Sepez51da0932015-11-25 16:05:49 -080032#ifdef PDF_ENABLE_XFA
dsinclair521b7502016-11-02 13:02:28 -070033#include "fpdfsdk/fpdfxfa/cpdfxfa_context.h"
dsinclair4d29e782016-10-04 14:02:47 -070034#include "fpdfsdk/fpdfxfa/cpdfxfa_page.h"
Tom Sepez40e9ff32015-11-30 12:39:54 -080035#endif // PDF_ENABLE_XFA
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070036
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070037#if _FX_OS_ == _FX_ANDROID_
Dan Sinclair85c8e7f2016-11-21 13:50:32 -050038#include <time.h>
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070039#else
40#include <ctime>
41#endif
42
thestigc54bb432016-07-29 19:34:20 -070043namespace {
44
45static_assert(FPDF_PAGEOBJ_TEXT == CPDF_PageObject::TEXT,
46 "FPDF_PAGEOBJ_TEXT/CPDF_PageObject::TEXT mismatch");
47static_assert(FPDF_PAGEOBJ_PATH == CPDF_PageObject::PATH,
48 "FPDF_PAGEOBJ_PATH/CPDF_PageObject::PATH mismatch");
49static_assert(FPDF_PAGEOBJ_IMAGE == CPDF_PageObject::IMAGE,
50 "FPDF_PAGEOBJ_IMAGE/CPDF_PageObject::IMAGE mismatch");
51static_assert(FPDF_PAGEOBJ_SHADING == CPDF_PageObject::SHADING,
52 "FPDF_PAGEOBJ_SHADING/CPDF_PageObject::SHADING mismatch");
53static_assert(FPDF_PAGEOBJ_FORM == CPDF_PageObject::FORM,
54 "FPDF_PAGEOBJ_FORM/CPDF_PageObject::FORM mismatch");
55
56bool IsPageObject(CPDF_Page* pPage) {
57 if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type"))
58 return false;
59
dsinclair38fd8442016-09-15 10:15:32 -070060 CPDF_Object* pObject = pPage->m_pFormDict->GetObjectFor("Type")->GetDirect();
thestigc54bb432016-07-29 19:34:20 -070061 return pObject && !pObject->GetString().Compare("Page");
62}
63
64} // namespace
65
Nico Weber9d8ec5a2015-08-04 13:00:21 -070066DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_CreateNewDocument() {
Tom Sepezfe91c6c2017-05-16 15:33:20 -070067 auto pDoc = pdfium::MakeUnique<CPDF_Document>(nullptr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070068 pDoc->CreateNewDoc();
Tom Sepezfe91c6c2017-05-16 15:33:20 -070069
Nico Weber9d8ec5a2015-08-04 13:00:21 -070070 time_t currentTime;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070071 CFX_ByteString DateStr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070072 if (FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS)) {
Tom Sepezfe91c6c2017-05-16 15:33:20 -070073 if (time(&currentTime) != -1) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070074 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
Tom Sepezfe91c6c2017-05-16 15:33:20 -070083 CPDF_Dictionary* pInfoDict = pDoc->GetInfo();
Nico Weber9d8ec5a2015-08-04 13:00:21 -070084 if (pInfoDict) {
tsepez0e606b52016-11-18 16:22:41 -080085 if (FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS))
86 pInfoDict->SetNewFor<CPDF_String>("CreationDate", DateStr, false);
87 pInfoDict->SetNewFor<CPDF_String>("Creator", L"PDFium");
Nico Weber9d8ec5a2015-08-04 13:00:21 -070088 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070089
Tom Sepezfe91c6c2017-05-16 15:33:20 -070090 // Caller takes ownership of pDoc.
91 return FPDFDocumentFromCPDFDocument(pDoc.release());
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
Tom Sepez9792f162017-05-16 14:11:30 -0700121 auto pXFAPage = pdfium::MakeRetain<CPDFXFA_Page>(
122 static_cast<CPDFXFA_Context*>(document), page_index);
123 pXFAPage->LoadPDFPage(pPageDict);
Tom Sepezfe91c6c2017-05-16 15:33:20 -0700124 return pXFAPage.Leak(); // Caller takes ownership.
Tom Sepez40e9ff32015-11-30 12:39:54 -0800125#else // PDF_ENABLE_XFA
Tom Sepezfe91c6c2017-05-16 15:33:20 -0700126 auto pPage = pdfium::MakeUnique<CPDF_Page>(pDoc, pPageDict, true);
thestig5cc24652016-04-26 11:46:02 -0700127 pPage->ParseContent();
Tom Sepezfe91c6c2017-05-16 15:33:20 -0700128 return pPage.release(); // Caller takes ownership.
Tom Sepez9792f162017-05-16 14:11:30 -0700129#endif // PDF_ENABLE_XFA
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);
Tom Sepezfe91c6c2017-05-16 15:33:20 -0700134 return IsPageObject(pPage) ? pPage->GetPageRotation() : -1;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700135}
136
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700137DLLEXPORT void STDCALL FPDFPage_InsertObject(FPDF_PAGE page,
138 FPDF_PAGEOBJECT page_obj) {
Nicolas Pena46abb662017-05-17 17:23:22 -0400139 CPDF_PageObject* pPageObj = static_cast<CPDF_PageObject*>(page_obj);
Lei Zhang997de612015-11-04 18:17:53 -0800140 if (!pPageObj)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700141 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700142
thestigc54bb432016-07-29 19:34:20 -0700143 std::unique_ptr<CPDF_PageObject> pPageObjHolder(pPageObj);
144 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
145 if (!IsPageObject(pPage))
146 return;
Tom Sepez2398d892016-02-17 16:46:26 -0800147
thestigc54bb432016-07-29 19:34:20 -0700148 pPage->GetPageObjectList()->push_back(std::move(pPageObjHolder));
Wei Li7cf13c92016-02-19 11:53:03 -0800149 switch (pPageObj->GetType()) {
thestigc54bb432016-07-29 19:34:20 -0700150 case CPDF_PageObject::TEXT: {
151 break;
152 }
153 case CPDF_PageObject::PATH: {
Wei Li7cf13c92016-02-19 11:53:03 -0800154 CPDF_PathObject* pPathObj = pPageObj->AsPath();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700155 pPathObj->CalcBoundingBox();
156 break;
157 }
thestigc54bb432016-07-29 19:34:20 -0700158 case CPDF_PageObject::IMAGE: {
Wei Li7cf13c92016-02-19 11:53:03 -0800159 CPDF_ImageObject* pImageObj = pPageObj->AsImage();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700160 pImageObj->CalcBoundingBox();
161 break;
162 }
thestigc54bb432016-07-29 19:34:20 -0700163 case CPDF_PageObject::SHADING: {
Wei Li7cf13c92016-02-19 11:53:03 -0800164 CPDF_ShadingObject* pShadingObj = pPageObj->AsShading();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700165 pShadingObj->CalcBoundingBox();
166 break;
167 }
thestigc54bb432016-07-29 19:34:20 -0700168 case CPDF_PageObject::FORM: {
Wei Li7cf13c92016-02-19 11:53:03 -0800169 CPDF_FormObject* pFormObj = pPageObj->AsForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700170 pFormObj->CalcBoundingBox();
171 break;
172 }
thestigc54bb432016-07-29 19:34:20 -0700173 default: {
Lei Zhangb45324b2017-05-22 17:05:40 -0700174 NOTREACHED();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700175 break;
thestigc54bb432016-07-29 19:34:20 -0700176 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700177 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700178}
179
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700180DLLEXPORT int STDCALL FPDFPage_CountObject(FPDF_PAGE page) {
Tom Sepezbf59a072015-10-21 14:07:23 -0700181 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
thestigc54bb432016-07-29 19:34:20 -0700182 if (!IsPageObject(pPage))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700183 return -1;
Tom Sepez2398d892016-02-17 16:46:26 -0800184 return pdfium::CollectionSize<int>(*pPage->GetPageObjectList());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700185}
186
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700187DLLEXPORT FPDF_PAGEOBJECT STDCALL FPDFPage_GetObject(FPDF_PAGE page,
188 int index) {
Tom Sepezdb0be962015-10-16 14:00:21 -0700189 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
thestigc54bb432016-07-29 19:34:20 -0700190 if (!IsPageObject(pPage))
Tom Sepez2398d892016-02-17 16:46:26 -0800191 return nullptr;
Tom Sepez2398d892016-02-17 16:46:26 -0800192 return pPage->GetPageObjectList()->GetPageObjectByIndex(index);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700193}
194
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700195DLLEXPORT FPDF_BOOL STDCALL FPDFPage_HasTransparency(FPDF_PAGE page) {
Tom Sepezdb0be962015-10-16 14:00:21 -0700196 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
197 return pPage && pPage->BackgroundAlphaNeeded();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700198}
199
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700200DLLEXPORT FPDF_BOOL STDCALL
201FPDFPageObj_HasTransparency(FPDF_PAGEOBJECT pageObject) {
202 if (!pageObject)
tsepez4cf55152016-11-02 14:37:54 -0700203 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700204
Nicolas Pena46abb662017-05-17 17:23:22 -0400205 CPDF_PageObject* pPageObj = static_cast<CPDF_PageObject*>(pageObject);
tsepezbbee4452016-09-02 15:22:00 -0700206 int blend_type = pPageObj->m_GeneralState.GetBlendType();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700207 if (blend_type != FXDIB_BLEND_NORMAL)
tsepez4cf55152016-11-02 14:37:54 -0700208 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700209
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700210 CPDF_Dictionary* pSMaskDict =
tsepezbbee4452016-09-02 15:22:00 -0700211 ToDictionary(pPageObj->m_GeneralState.GetSoftMask());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700212 if (pSMaskDict)
tsepez4cf55152016-11-02 14:37:54 -0700213 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700214
tsepezbbee4452016-09-02 15:22:00 -0700215 if (pPageObj->m_GeneralState.GetFillAlpha() != 1.0f)
tsepez4cf55152016-11-02 14:37:54 -0700216 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700217
tsepezbbee4452016-09-02 15:22:00 -0700218 if (pPageObj->IsPath() && pPageObj->m_GeneralState.GetStrokeAlpha() != 1.0f) {
tsepez4cf55152016-11-02 14:37:54 -0700219 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700220 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700221
Wei Li7cf13c92016-02-19 11:53:03 -0800222 if (pPageObj->IsForm()) {
thestigc54bb432016-07-29 19:34:20 -0700223 const CPDF_Form* pForm = pPageObj->AsForm()->form();
224 if (pForm) {
225 int trans = pForm->m_Transparency;
226 if ((trans & PDFTRANS_ISOLATED) || (trans & PDFTRANS_GROUP))
tsepez4cf55152016-11-02 14:37:54 -0700227 return true;
thestigc54bb432016-07-29 19:34:20 -0700228 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700229 }
thestigc54bb432016-07-29 19:34:20 -0700230
tsepez4cf55152016-11-02 14:37:54 -0700231 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700232}
233
Miklos Vajna14233192017-04-03 16:02:39 +0200234DLLEXPORT int STDCALL FPDFPageObj_GetType(FPDF_PAGEOBJECT pageObject) {
235 if (!pageObject)
236 return FPDF_PAGEOBJ_UNKNOWN;
237
Nicolas Pena46abb662017-05-17 17:23:22 -0400238 CPDF_PageObject* pPageObj = static_cast<CPDF_PageObject*>(pageObject);
Miklos Vajna14233192017-04-03 16:02:39 +0200239 return pPageObj->GetType();
240}
241
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700242DLLEXPORT FPDF_BOOL STDCALL FPDFPage_GenerateContent(FPDF_PAGE page) {
Tom Sepezdb0be962015-10-16 14:00:21 -0700243 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
thestigc54bb432016-07-29 19:34:20 -0700244 if (!IsPageObject(pPage))
tsepez4cf55152016-11-02 14:37:54 -0700245 return false;
thestigc54bb432016-07-29 19:34:20 -0700246
Tom Sepeze19e06e2016-01-21 10:49:56 -0800247 CPDF_PageContentGenerator CG(pPage);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700248 CG.GenerateContent();
tsepez4cf55152016-11-02 14:37:54 -0700249 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700250}
251
252DLLEXPORT void STDCALL FPDFPageObj_Transform(FPDF_PAGEOBJECT page_object,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700253 double a,
254 double b,
255 double c,
256 double d,
257 double e,
258 double f) {
Nicolas Pena46abb662017-05-17 17:23:22 -0400259 CPDF_PageObject* pPageObj = static_cast<CPDF_PageObject*>(page_object);
Lei Zhang997de612015-11-04 18:17:53 -0800260 if (!pPageObj)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700261 return;
Lei Zhangcb78ef52015-10-02 10:10:49 -0700262
Dan Sinclair05df0752017-03-14 14:43:42 -0400263 CFX_Matrix matrix((float)a, (float)b, (float)c, (float)d, (float)e, (float)f);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700264 pPageObj->Transform(matrix);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700265}
thestigc54bb432016-07-29 19:34:20 -0700266
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700267DLLEXPORT void STDCALL FPDFPage_TransformAnnots(FPDF_PAGE page,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700268 double a,
269 double b,
270 double c,
271 double d,
272 double e,
273 double f) {
Tom Sepezdb0be962015-10-16 14:00:21 -0700274 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700275 if (!pPage)
276 return;
thestigc54bb432016-07-29 19:34:20 -0700277
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700278 CPDF_AnnotList AnnotList(pPage);
Lei Zhang1b700c32015-10-30 23:55:35 -0700279 for (size_t i = 0; i < AnnotList.Count(); ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700280 CPDF_Annot* pAnnot = AnnotList.GetAt(i);
tsepez8021a642016-10-17 16:13:21 -0700281 CFX_FloatRect rect = pAnnot->GetRect(); // transformAnnots Rectangle
Dan Sinclair05df0752017-03-14 14:43:42 -0400282 CFX_Matrix matrix((float)a, (float)b, (float)c, (float)d, (float)e,
283 (float)f);
Dan Sinclair118a8e22017-02-09 10:16:07 -0500284 matrix.TransformRect(rect);
tsepez8021a642016-10-17 16:13:21 -0700285
dsinclair38fd8442016-09-15 10:15:32 -0700286 CPDF_Array* pRectArray = pAnnot->GetAnnotDict()->GetArrayFor("Rect");
tsepez0e606b52016-11-18 16:22:41 -0800287 if (!pRectArray)
288 pRectArray = pAnnot->GetAnnotDict()->SetNewFor<CPDF_Array>("Rect");
289
tsepez8a3aa452016-11-16 12:26:06 -0800290 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-Malek3f3b45c2014-05-23 17:28:10 -0700294
Dan Sinclair85c8e7f2016-11-21 13:50:32 -0500295 // TODO(unknown): Transform AP's rectangle
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700296 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700297}
Bo Xu394010d2014-06-12 13:41:50 -0700298
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700299DLLEXPORT void STDCALL FPDFPage_SetRotation(FPDF_PAGE page, int rotate) {
Tom Sepezdb0be962015-10-16 14:00:21 -0700300 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
thestigc54bb432016-07-29 19:34:20 -0700301 if (!IsPageObject(pPage))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700302 return;
thestigc54bb432016-07-29 19:34:20 -0700303
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700304 rotate %= 4;
Tom Sepez4cb82ee2017-05-22 15:15:30 -0700305 pPage->m_pFormDict->SetNewFor<CPDF_Number>("Rotate", rotate * 90);
Nico Weber0ce77e32014-07-16 13:19:08 -0700306}