blob: 66ff02814123a6aad0527ce00ad0d3cb394ff13a [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
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);
124 return pXFAPage.Leak();
Tom Sepez40e9ff32015-11-30 12:39:54 -0800125#else // PDF_ENABLE_XFA
thestig5cc24652016-04-26 11:46:02 -0700126 CPDF_Page* pPage = new CPDF_Page(pDoc, pPageDict, true);
127 pPage->ParseContent();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700128 return pPage;
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);
thestigc54bb432016-07-29 19:34:20 -0700134 if (!IsPageObject(pPage))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700135 return -1;
rbpotterce8e51e2017-04-28 12:42:47 -0700136 return pPage->GetPageRotation();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700137}
138
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700139DLLEXPORT void STDCALL FPDFPage_InsertObject(FPDF_PAGE page,
140 FPDF_PAGEOBJECT page_obj) {
thestigc54bb432016-07-29 19:34:20 -0700141 CPDF_PageObject* pPageObj = reinterpret_cast<CPDF_PageObject*>(page_obj);
Lei Zhang997de612015-11-04 18:17:53 -0800142 if (!pPageObj)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700143 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700144
thestigc54bb432016-07-29 19:34:20 -0700145 std::unique_ptr<CPDF_PageObject> pPageObjHolder(pPageObj);
146 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
147 if (!IsPageObject(pPage))
148 return;
Tom Sepez2398d892016-02-17 16:46:26 -0800149
thestigc54bb432016-07-29 19:34:20 -0700150 pPage->GetPageObjectList()->push_back(std::move(pPageObjHolder));
Wei Li7cf13c92016-02-19 11:53:03 -0800151 switch (pPageObj->GetType()) {
thestigc54bb432016-07-29 19:34:20 -0700152 case CPDF_PageObject::TEXT: {
153 break;
154 }
155 case CPDF_PageObject::PATH: {
Wei Li7cf13c92016-02-19 11:53:03 -0800156 CPDF_PathObject* pPathObj = pPageObj->AsPath();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700157 pPathObj->CalcBoundingBox();
158 break;
159 }
thestigc54bb432016-07-29 19:34:20 -0700160 case CPDF_PageObject::IMAGE: {
Wei Li7cf13c92016-02-19 11:53:03 -0800161 CPDF_ImageObject* pImageObj = pPageObj->AsImage();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700162 pImageObj->CalcBoundingBox();
163 break;
164 }
thestigc54bb432016-07-29 19:34:20 -0700165 case CPDF_PageObject::SHADING: {
Wei Li7cf13c92016-02-19 11:53:03 -0800166 CPDF_ShadingObject* pShadingObj = pPageObj->AsShading();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700167 pShadingObj->CalcBoundingBox();
168 break;
169 }
thestigc54bb432016-07-29 19:34:20 -0700170 case CPDF_PageObject::FORM: {
Wei Li7cf13c92016-02-19 11:53:03 -0800171 CPDF_FormObject* pFormObj = pPageObj->AsForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700172 pFormObj->CalcBoundingBox();
173 break;
174 }
thestigc54bb432016-07-29 19:34:20 -0700175 default: {
176 ASSERT(false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700177 break;
thestigc54bb432016-07-29 19:34:20 -0700178 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700179 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700180}
181
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700182DLLEXPORT int STDCALL FPDFPage_CountObject(FPDF_PAGE page) {
Tom Sepezbf59a072015-10-21 14:07:23 -0700183 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
thestigc54bb432016-07-29 19:34:20 -0700184 if (!IsPageObject(pPage))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700185 return -1;
Tom Sepez2398d892016-02-17 16:46:26 -0800186 return pdfium::CollectionSize<int>(*pPage->GetPageObjectList());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700187}
188
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700189DLLEXPORT FPDF_PAGEOBJECT STDCALL FPDFPage_GetObject(FPDF_PAGE page,
190 int index) {
Tom Sepezdb0be962015-10-16 14:00:21 -0700191 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
thestigc54bb432016-07-29 19:34:20 -0700192 if (!IsPageObject(pPage))
Tom Sepez2398d892016-02-17 16:46:26 -0800193 return nullptr;
Tom Sepez2398d892016-02-17 16:46:26 -0800194 return pPage->GetPageObjectList()->GetPageObjectByIndex(index);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700195}
196
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700197DLLEXPORT FPDF_BOOL STDCALL FPDFPage_HasTransparency(FPDF_PAGE page) {
Tom Sepezdb0be962015-10-16 14:00:21 -0700198 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
199 return pPage && pPage->BackgroundAlphaNeeded();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700200}
201
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700202DLLEXPORT FPDF_BOOL STDCALL
203FPDFPageObj_HasTransparency(FPDF_PAGEOBJECT pageObject) {
204 if (!pageObject)
tsepez4cf55152016-11-02 14:37:54 -0700205 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700206
thestigc54bb432016-07-29 19:34:20 -0700207 CPDF_PageObject* pPageObj = reinterpret_cast<CPDF_PageObject*>(pageObject);
tsepezbbee4452016-09-02 15:22:00 -0700208 int blend_type = pPageObj->m_GeneralState.GetBlendType();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700209 if (blend_type != FXDIB_BLEND_NORMAL)
tsepez4cf55152016-11-02 14:37:54 -0700210 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700211
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700212 CPDF_Dictionary* pSMaskDict =
tsepezbbee4452016-09-02 15:22:00 -0700213 ToDictionary(pPageObj->m_GeneralState.GetSoftMask());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700214 if (pSMaskDict)
tsepez4cf55152016-11-02 14:37:54 -0700215 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700216
tsepezbbee4452016-09-02 15:22:00 -0700217 if (pPageObj->m_GeneralState.GetFillAlpha() != 1.0f)
tsepez4cf55152016-11-02 14:37:54 -0700218 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700219
tsepezbbee4452016-09-02 15:22:00 -0700220 if (pPageObj->IsPath() && pPageObj->m_GeneralState.GetStrokeAlpha() != 1.0f) {
tsepez4cf55152016-11-02 14:37:54 -0700221 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700222 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700223
Wei Li7cf13c92016-02-19 11:53:03 -0800224 if (pPageObj->IsForm()) {
thestigc54bb432016-07-29 19:34:20 -0700225 const CPDF_Form* pForm = pPageObj->AsForm()->form();
226 if (pForm) {
227 int trans = pForm->m_Transparency;
228 if ((trans & PDFTRANS_ISOLATED) || (trans & PDFTRANS_GROUP))
tsepez4cf55152016-11-02 14:37:54 -0700229 return true;
thestigc54bb432016-07-29 19:34:20 -0700230 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700231 }
thestigc54bb432016-07-29 19:34:20 -0700232
tsepez4cf55152016-11-02 14:37:54 -0700233 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700234}
235
Miklos Vajna14233192017-04-03 16:02:39 +0200236DLLEXPORT int STDCALL FPDFPageObj_GetType(FPDF_PAGEOBJECT pageObject) {
237 if (!pageObject)
238 return FPDF_PAGEOBJ_UNKNOWN;
239
240 CPDF_PageObject* pPageObj = reinterpret_cast<CPDF_PageObject*>(pageObject);
241 return pPageObj->GetType();
242}
243
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700244DLLEXPORT FPDF_BOOL STDCALL FPDFPage_GenerateContent(FPDF_PAGE page) {
Tom Sepezdb0be962015-10-16 14:00:21 -0700245 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
thestigc54bb432016-07-29 19:34:20 -0700246 if (!IsPageObject(pPage))
tsepez4cf55152016-11-02 14:37:54 -0700247 return false;
thestigc54bb432016-07-29 19:34:20 -0700248
Tom Sepeze19e06e2016-01-21 10:49:56 -0800249 CPDF_PageContentGenerator CG(pPage);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700250 CG.GenerateContent();
tsepez4cf55152016-11-02 14:37:54 -0700251 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700252}
253
254DLLEXPORT void STDCALL FPDFPageObj_Transform(FPDF_PAGEOBJECT page_object,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700255 double a,
256 double b,
257 double c,
258 double d,
259 double e,
260 double f) {
thestigc54bb432016-07-29 19:34:20 -0700261 CPDF_PageObject* pPageObj = reinterpret_cast<CPDF_PageObject*>(page_object);
Lei Zhang997de612015-11-04 18:17:53 -0800262 if (!pPageObj)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700263 return;
Lei Zhangcb78ef52015-10-02 10:10:49 -0700264
Dan Sinclair05df0752017-03-14 14:43:42 -0400265 CFX_Matrix matrix((float)a, (float)b, (float)c, (float)d, (float)e, (float)f);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700266 pPageObj->Transform(matrix);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700267}
thestigc54bb432016-07-29 19:34:20 -0700268
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700269DLLEXPORT void STDCALL FPDFPage_TransformAnnots(FPDF_PAGE page,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700270 double a,
271 double b,
272 double c,
273 double d,
274 double e,
275 double f) {
Tom Sepezdb0be962015-10-16 14:00:21 -0700276 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700277 if (!pPage)
278 return;
thestigc54bb432016-07-29 19:34:20 -0700279
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700280 CPDF_AnnotList AnnotList(pPage);
Lei Zhang1b700c32015-10-30 23:55:35 -0700281 for (size_t i = 0; i < AnnotList.Count(); ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700282 CPDF_Annot* pAnnot = AnnotList.GetAt(i);
tsepez8021a642016-10-17 16:13:21 -0700283 CFX_FloatRect rect = pAnnot->GetRect(); // transformAnnots Rectangle
Dan Sinclair05df0752017-03-14 14:43:42 -0400284 CFX_Matrix matrix((float)a, (float)b, (float)c, (float)d, (float)e,
285 (float)f);
Dan Sinclair118a8e22017-02-09 10:16:07 -0500286 matrix.TransformRect(rect);
tsepez8021a642016-10-17 16:13:21 -0700287
dsinclair38fd8442016-09-15 10:15:32 -0700288 CPDF_Array* pRectArray = pAnnot->GetAnnotDict()->GetArrayFor("Rect");
tsepez0e606b52016-11-18 16:22:41 -0800289 if (!pRectArray)
290 pRectArray = pAnnot->GetAnnotDict()->SetNewFor<CPDF_Array>("Rect");
291
tsepez8a3aa452016-11-16 12:26:06 -0800292 pRectArray->SetNewAt<CPDF_Number>(0, rect.left);
293 pRectArray->SetNewAt<CPDF_Number>(1, rect.bottom);
294 pRectArray->SetNewAt<CPDF_Number>(2, rect.right);
295 pRectArray->SetNewAt<CPDF_Number>(3, rect.top);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700296
Dan Sinclair85c8e7f2016-11-21 13:50:32 -0500297 // TODO(unknown): Transform AP's rectangle
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700298 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700299}
Bo Xu394010d2014-06-12 13:41:50 -0700300
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700301DLLEXPORT void STDCALL FPDFPage_SetRotation(FPDF_PAGE page, int rotate) {
Tom Sepezdb0be962015-10-16 14:00:21 -0700302 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
thestigc54bb432016-07-29 19:34:20 -0700303 if (!IsPageObject(pPage))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700304 return;
thestigc54bb432016-07-29 19:34:20 -0700305
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700306 CPDF_Dictionary* pDict = pPage->m_pFormDict;
307 rotate %= 4;
tsepez0e606b52016-11-18 16:22:41 -0800308 pDict->SetNewFor<CPDF_Number>("Rotate", rotate * 90);
Nico Weber0ce77e32014-07-16 13:19:08 -0700309}