blob: 72148b8e6d8a5878c39c188b06f013b9023fd396 [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
Dan Sinclair455a4192016-03-16 09:48:56 -04009#include "core/fpdfapi/fpdf_edit/include/cpdf_pagecontentgenerator.h"
10#include "core/fpdfapi/fpdf_page/include/cpdf_form.h"
Dan Sinclair584b1e62016-03-21 09:15:45 -040011#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 Sinclair455a4192016-03-16 09:48:56 -040014#include "core/fpdfapi/fpdf_page/include/cpdf_page.h"
Dan Sinclair584b1e62016-03-21 09:15:45 -040015#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 Sinclairaa403d32016-03-15 14:57:22 -040018#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 Sepez40e9ff32015-11-30 12:39:54 -080022#include "fpdfsdk/include/fsdk_define.h"
23#include "public/fpdf_formfill.h"
Tom Sepez2398d892016-02-17 16:46:26 -080024#include "third_party/base/stl_util.h"
Tom Sepez40e9ff32015-11-30 12:39:54 -080025
Tom Sepez51da0932015-11-25 16:05:49 -080026#ifdef PDF_ENABLE_XFA
Lei Zhang875b9c92016-01-08 13:51:10 -080027#include "fpdfsdk/include/fpdfxfa/fpdfxfa_app.h"
28#include "fpdfsdk/include/fpdfxfa/fpdfxfa_doc.h"
29#include "fpdfsdk/include/fpdfxfa/fpdfxfa_page.h"
Tom Sepez40e9ff32015-11-30 12:39:54 -080030#endif // PDF_ENABLE_XFA
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070031
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070032#if _FX_OS_ == _FX_ANDROID_
33#include "time.h"
34#else
35#include <ctime>
36#endif
37
Nico Weber9d8ec5a2015-08-04 13:00:21 -070038DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_CreateNewDocument() {
Tom Sepezae51c812015-08-05 12:34:06 -070039 CPDF_Document* pDoc = new CPDF_Document;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070040 pDoc->CreateNewDoc();
41 time_t currentTime;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070042
Nico Weber9d8ec5a2015-08-04 13:00:21 -070043 CFX_ByteString DateStr;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070044
Nico Weber9d8ec5a2015-08-04 13:00:21 -070045 if (FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS)) {
46 if (-1 != time(&currentTime)) {
47 tm* pTM = localtime(&currentTime);
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 Sepezbdeeb8a2015-05-27 12:25:00 -070055
Nico Weber9d8ec5a2015-08-04 13:00:21 -070056 CPDF_Dictionary* pInfoDict = NULL;
57 pInfoDict = pDoc->GetInfo();
58 if (pInfoDict) {
59 if (FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS))
Lei Zhang4880d1a2015-12-18 17:05:11 -080060 pInfoDict->SetAt("CreationDate", new CPDF_String(DateStr, FALSE));
Tom Sepezae51c812015-08-05 12:34:06 -070061 pInfoDict->SetAt("Creator", new CPDF_String(L"PDFium"));
Nico Weber9d8ec5a2015-08-04 13:00:21 -070062 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070063
Tom Sepezbf59a072015-10-21 14:07:23 -070064 return FPDFDocumentFromCPDFDocument(pDoc);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070065}
66
Nico Weber9d8ec5a2015-08-04 13:00:21 -070067DLLEXPORT void STDCALL FPDFPage_Delete(FPDF_DOCUMENT document, int page_index) {
Tom Sepez744da702016-03-15 12:43:09 -070068 if (UnderlyingDocumentType* pDoc = UnderlyingFromFPDFDocument(document))
69 pDoc->DeletePage(page_index);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070070}
71
Nico Weber9d8ec5a2015-08-04 13:00:21 -070072DLLEXPORT FPDF_PAGE STDCALL FPDFPage_New(FPDF_DOCUMENT document,
73 int page_index,
74 double width,
75 double height) {
Tom Sepez471a1032015-10-15 16:17:18 -070076 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
77 if (!pDoc)
78 return nullptr;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070079
Nico Weber9d8ec5a2015-08-04 13:00:21 -070080 if (page_index < 0)
81 page_index = 0;
82 if (pDoc->GetPageCount() < page_index)
83 page_index = pDoc->GetPageCount();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070084
Nico Weber9d8ec5a2015-08-04 13:00:21 -070085 CPDF_Dictionary* pPageDict = pDoc->CreateNewPage(page_index);
86 if (!pPageDict)
87 return NULL;
Tom Sepezae51c812015-08-05 12:34:06 -070088 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-Malek3f3b45c2014-05-23 17:28:10 -070093
Nico Weber9d8ec5a2015-08-04 13:00:21 -070094 pPageDict->SetAt("MediaBox", pMediaBoxArray);
Tom Sepezae51c812015-08-05 12:34:06 -070095 pPageDict->SetAt("Rotate", new CPDF_Number(0));
96 pPageDict->SetAt("Resources", new CPDF_Dictionary);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070097
Tom Sepez40e9ff32015-11-30 12:39:54 -080098#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -070099 CPDFXFA_Page* pPage =
Tom Sepezae51c812015-08-05 12:34:06 -0700100 new CPDFXFA_Page((CPDFXFA_Document*)document, page_index);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700101 pPage->LoadPDFPage(pPageDict);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800102#else // PDF_ENABLE_XFA
103 CPDF_Page* pPage = new CPDF_Page;
104 pPage->Load(pDoc, pPageDict);
Tom Sepezb5b2a912016-01-21 11:04:37 -0800105 pPage->ParseContent(nullptr);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800106#endif // PDF_ENABLE_XFA
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700107
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700108 return pPage;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700109}
110
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700111DLLEXPORT int STDCALL FPDFPage_GetRotation(FPDF_PAGE page) {
Tom Sepezdb0be962015-10-16 14:00:21 -0700112 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700113 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 Zhang997de612015-11-04 18:17:53 -0800120 if (!pDict)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700121 return -1;
Lei Zhang997de612015-11-04 18:17:53 -0800122
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 Weber9d8ec5a2015-08-04 13:00:21 -0700132 }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700133
Lei Zhang997de612015-11-04 18:17:53 -0800134 return 0;
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) {
Tom Sepezdb0be962015-10-16 14:00:21 -0700139 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700140 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 Zhang997de612015-11-04 18:17:53 -0800147 if (!pPageObj)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700148 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700149
Tom Sepez2398d892016-02-17 16:46:26 -0800150 pPage->GetPageObjectList()->push_back(
151 std::unique_ptr<CPDF_PageObject>(pPageObj));
152
Wei Li7cf13c92016-02-19 11:53:03 -0800153 switch (pPageObj->GetType()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700154 case FPDF_PAGEOBJ_PATH: {
Wei Li7cf13c92016-02-19 11:53:03 -0800155 CPDF_PathObject* pPathObj = pPageObj->AsPath();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700156 pPathObj->CalcBoundingBox();
157 break;
158 }
159 case FPDF_PAGEOBJ_TEXT: {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700160 break;
161 }
162 case FPDF_PAGEOBJ_IMAGE: {
Wei Li7cf13c92016-02-19 11:53:03 -0800163 CPDF_ImageObject* pImageObj = pPageObj->AsImage();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700164 pImageObj->CalcBoundingBox();
165 break;
166 }
167 case FPDF_PAGEOBJ_SHADING: {
Wei Li7cf13c92016-02-19 11:53:03 -0800168 CPDF_ShadingObject* pShadingObj = pPageObj->AsShading();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700169 pShadingObj->CalcBoundingBox();
170 break;
171 }
172 case FPDF_PAGEOBJ_FORM: {
Wei Li7cf13c92016-02-19 11:53:03 -0800173 CPDF_FormObject* pFormObj = pPageObj->AsForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700174 pFormObj->CalcBoundingBox();
175 break;
176 }
177 default:
178 break;
179 }
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);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700184 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 Sepez2398d892016-02-17 16:46:26 -0800190 return pdfium::CollectionSize<int>(*pPage->GetPageObjectList());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700191}
192
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700193DLLEXPORT FPDF_PAGEOBJECT STDCALL FPDFPage_GetObject(FPDF_PAGE page,
194 int index) {
Tom Sepezdb0be962015-10-16 14:00:21 -0700195 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700196 if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") ||
197 pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare(
198 "Page")) {
Tom Sepez2398d892016-02-17 16:46:26 -0800199 return nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700200 }
Tom Sepez2398d892016-02-17 16:46:26 -0800201 return pPage->GetPageObjectList()->GetPageObjectByIndex(index);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700202}
203
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700204DLLEXPORT FPDF_BOOL STDCALL FPDFPage_HasTransparency(FPDF_PAGE page) {
Tom Sepezdb0be962015-10-16 14:00:21 -0700205 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
206 return pPage && pPage->BackgroundAlphaNeeded();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700207}
208
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700209DLLEXPORT FPDF_BOOL STDCALL
210FPDFPageObj_HasTransparency(FPDF_PAGEOBJECT pageObject) {
211 if (!pageObject)
212 return FALSE;
213 CPDF_PageObject* pPageObj = (CPDF_PageObject*)pageObject;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700214
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700215 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-Malek3f3b45c2014-05-23 17:28:10 -0700220
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700221 CPDF_Dictionary* pSMaskDict =
Dan Sinclairf1251c12015-10-20 16:24:45 -0400222 pGeneralState ? ToDictionary(pGeneralState->m_pSoftMask) : NULL;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700223 if (pSMaskDict)
224 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700225
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700226 if (pGeneralState && pGeneralState->m_FillAlpha != 1.0f)
227 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700228
Wei Li7cf13c92016-02-19 11:53:03 -0800229 if (pPageObj->IsPath()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700230 if (pGeneralState && pGeneralState->m_StrokeAlpha != 1.0f)
231 return TRUE;
232 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700233
Wei Li7cf13c92016-02-19 11:53:03 -0800234 if (pPageObj->IsForm()) {
235 CPDF_FormObject* pFormObj = pPageObj->AsForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700236 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-Malek3f3b45c2014-05-23 17:28:10 -0700245}
246
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700247DLLEXPORT FPDF_BOOL STDCALL FPDFPage_GenerateContent(FPDF_PAGE page) {
Tom Sepezdb0be962015-10-16 14:00:21 -0700248 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700249 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 Sepeze19e06e2016-01-21 10:49:56 -0800255 CPDF_PageContentGenerator CG(pPage);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700256 CG.GenerateContent();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700257
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) {
268 CPDF_PageObject* pPageObj = (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}
276DLLEXPORT void STDCALL FPDFPage_TransformAnnots(FPDF_PAGE page,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700277 double a,
278 double b,
279 double c,
280 double d,
281 double e,
282 double f) {
Tom Sepezdb0be962015-10-16 14:00:21 -0700283 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700284 if (!pPage)
285 return;
286 CPDF_AnnotList AnnotList(pPage);
Lei Zhang1b700c32015-10-30 23:55:35 -0700287 for (size_t i = 0; i < AnnotList.Count(); ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700288 CPDF_Annot* pAnnot = AnnotList.GetAt(i);
289 // transformAnnots Rectangle
Tom Sepez281a9ea2016-02-26 14:24:28 -0800290 CFX_FloatRect rect;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700291 pAnnot->GetRect(rect);
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);
295 CPDF_Array* pRectArray = NULL;
Wei Li9b761132016-01-29 15:44:20 -0800296 pRectArray = pAnnot->GetAnnotDict()->GetArrayBy("Rect");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700297 if (!pRectArray)
Lei Zhang4880d1a2015-12-18 17:05:11 -0800298 pRectArray = new CPDF_Array;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700299 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-Malek3f3b45c2014-05-23 17:28:10 -0700304
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700305 // Transform AP's rectangle
306 // To Do
307 }
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);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700312 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 Xu394010d2014-06-12 13:41:50 -0700320
Tom Sepezae51c812015-08-05 12:34:06 -0700321 pDict->SetAt("Rotate", new CPDF_Number(rotate * 90));
Nico Weber0ce77e32014-07-16 13:19:08 -0700322}