blob: 0daa45903746fc525a07008a8eece9591e1d34f3 [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
Dan Sinclair455a4192016-03-16 09:48:56 -040013#include "core/fpdfapi/fpdf_edit/include/cpdf_pagecontentgenerator.h"
14#include "core/fpdfapi/fpdf_page/include/cpdf_form.h"
Dan Sinclair584b1e62016-03-21 09:15:45 -040015#include "core/fpdfapi/fpdf_page/include/cpdf_formobject.h"
16#include "core/fpdfapi/fpdf_page/include/cpdf_generalstatedata.h"
17#include "core/fpdfapi/fpdf_page/include/cpdf_imageobject.h"
Dan Sinclair455a4192016-03-16 09:48:56 -040018#include "core/fpdfapi/fpdf_page/include/cpdf_page.h"
Dan Sinclair584b1e62016-03-21 09:15:45 -040019#include "core/fpdfapi/fpdf_page/include/cpdf_pageobject.h"
20#include "core/fpdfapi/fpdf_page/include/cpdf_pathobject.h"
21#include "core/fpdfapi/fpdf_page/include/cpdf_shadingobject.h"
Dan Sinclairaa403d32016-03-15 14:57:22 -040022#include "core/fpdfapi/fpdf_parser/include/cpdf_array.h"
23#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
24#include "core/fpdfapi/fpdf_parser/include/cpdf_number.h"
25#include "core/fpdfapi/fpdf_parser/include/cpdf_string.h"
dsinclaircac704d2016-07-28 12:59:09 -070026#include "core/fpdfdoc/include/cpdf_annot.h"
27#include "core/fpdfdoc/include/cpdf_annotlist.h"
Tom Sepez40e9ff32015-11-30 12:39:54 -080028#include "fpdfsdk/include/fsdk_define.h"
29#include "public/fpdf_formfill.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
dsinclair89bdd082016-04-06 10:47:54 -070033#include "fpdfsdk/fpdfxfa/include/fpdfxfa_app.h"
34#include "fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h"
35#include "fpdfsdk/fpdfxfa/include/fpdfxfa_page.h"
Tom Sepez40e9ff32015-11-30 12:39:54 -080036#endif // PDF_ENABLE_XFA
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070037
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070038#if _FX_OS_ == _FX_ANDROID_
39#include "time.h"
40#else
41#include <ctime>
42#endif
43
thestigc54bb432016-07-29 19:34:20 -070044namespace {
45
46static_assert(FPDF_PAGEOBJ_TEXT == CPDF_PageObject::TEXT,
47 "FPDF_PAGEOBJ_TEXT/CPDF_PageObject::TEXT mismatch");
48static_assert(FPDF_PAGEOBJ_PATH == CPDF_PageObject::PATH,
49 "FPDF_PAGEOBJ_PATH/CPDF_PageObject::PATH mismatch");
50static_assert(FPDF_PAGEOBJ_IMAGE == CPDF_PageObject::IMAGE,
51 "FPDF_PAGEOBJ_IMAGE/CPDF_PageObject::IMAGE mismatch");
52static_assert(FPDF_PAGEOBJ_SHADING == CPDF_PageObject::SHADING,
53 "FPDF_PAGEOBJ_SHADING/CPDF_PageObject::SHADING mismatch");
54static_assert(FPDF_PAGEOBJ_FORM == CPDF_PageObject::FORM,
55 "FPDF_PAGEOBJ_FORM/CPDF_PageObject::FORM mismatch");
56
57bool IsPageObject(CPDF_Page* pPage) {
58 if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type"))
59 return false;
60
61 CPDF_Object* pObject = pPage->m_pFormDict->GetObjectBy("Type")->GetDirect();
62 return pObject && !pObject->GetString().Compare("Page");
63}
64
65} // namespace
66
Nico Weber9d8ec5a2015-08-04 13:00:21 -070067DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_CreateNewDocument() {
thestig931bf372016-04-26 22:24:30 -070068 CPDF_Document* pDoc = new CPDF_Document(nullptr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070069 pDoc->CreateNewDoc();
70 time_t currentTime;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070071
Nico Weber9d8ec5a2015-08-04 13:00:21 -070072 CFX_ByteString DateStr;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070073
Nico Weber9d8ec5a2015-08-04 13:00:21 -070074 if (FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS)) {
75 if (-1 != time(&currentTime)) {
76 tm* pTM = localtime(&currentTime);
77 if (pTM) {
78 DateStr.Format("D:%04d%02d%02d%02d%02d%02d", pTM->tm_year + 1900,
79 pTM->tm_mon + 1, pTM->tm_mday, pTM->tm_hour, pTM->tm_min,
80 pTM->tm_sec);
81 }
82 }
83 }
Tom Sepezbdeeb8a2015-05-27 12:25:00 -070084
thestig1cd352e2016-06-07 17:53:06 -070085 CPDF_Dictionary* pInfoDict = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070086 pInfoDict = pDoc->GetInfo();
87 if (pInfoDict) {
88 if (FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS))
Lei Zhang4880d1a2015-12-18 17:05:11 -080089 pInfoDict->SetAt("CreationDate", new CPDF_String(DateStr, FALSE));
Tom Sepezae51c812015-08-05 12:34:06 -070090 pInfoDict->SetAt("Creator", new CPDF_String(L"PDFium"));
Nico Weber9d8ec5a2015-08-04 13:00:21 -070091 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070092
Tom Sepezbf59a072015-10-21 14:07:23 -070093 return FPDFDocumentFromCPDFDocument(pDoc);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070094}
95
Nico Weber9d8ec5a2015-08-04 13:00:21 -070096DLLEXPORT void STDCALL FPDFPage_Delete(FPDF_DOCUMENT document, int page_index) {
Tom Sepez744da702016-03-15 12:43:09 -070097 if (UnderlyingDocumentType* pDoc = UnderlyingFromFPDFDocument(document))
98 pDoc->DeletePage(page_index);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070099}
100
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700101DLLEXPORT FPDF_PAGE STDCALL FPDFPage_New(FPDF_DOCUMENT document,
102 int page_index,
103 double width,
104 double height) {
Tom Sepez471a1032015-10-15 16:17:18 -0700105 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
106 if (!pDoc)
107 return nullptr;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700108
thestigc54bb432016-07-29 19:34:20 -0700109 page_index = std::min(std::max(page_index, 0), pDoc->GetPageCount());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700110 CPDF_Dictionary* pPageDict = pDoc->CreateNewPage(page_index);
111 if (!pPageDict)
thestig1cd352e2016-06-07 17:53:06 -0700112 return nullptr;
thestigc54bb432016-07-29 19:34:20 -0700113
Tom Sepezae51c812015-08-05 12:34:06 -0700114 CPDF_Array* pMediaBoxArray = new CPDF_Array;
115 pMediaBoxArray->Add(new CPDF_Number(0));
116 pMediaBoxArray->Add(new CPDF_Number(0));
117 pMediaBoxArray->Add(new CPDF_Number(FX_FLOAT(width)));
118 pMediaBoxArray->Add(new CPDF_Number(FX_FLOAT(height)));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700119
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700120 pPageDict->SetAt("MediaBox", pMediaBoxArray);
Tom Sepezae51c812015-08-05 12:34:06 -0700121 pPageDict->SetAt("Rotate", new CPDF_Number(0));
122 pPageDict->SetAt("Resources", new CPDF_Dictionary);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700123
Tom Sepez40e9ff32015-11-30 12:39:54 -0800124#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700125 CPDFXFA_Page* pPage =
Tom Sepezae51c812015-08-05 12:34:06 -0700126 new CPDFXFA_Page((CPDFXFA_Document*)document, page_index);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700127 pPage->LoadPDFPage(pPageDict);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800128#else // PDF_ENABLE_XFA
thestig5cc24652016-04-26 11:46:02 -0700129 CPDF_Page* pPage = new CPDF_Page(pDoc, pPageDict, true);
130 pPage->ParseContent();
Tom Sepez40e9ff32015-11-30 12:39:54 -0800131#endif // PDF_ENABLE_XFA
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700132
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700133 return pPage;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700134}
135
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700136DLLEXPORT int STDCALL FPDFPage_GetRotation(FPDF_PAGE page) {
Tom Sepezdb0be962015-10-16 14:00:21 -0700137 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
thestigc54bb432016-07-29 19:34:20 -0700138 if (!IsPageObject(pPage))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700139 return -1;
Lei Zhang997de612015-11-04 18:17:53 -0800140
thestigc54bb432016-07-29 19:34:20 -0700141 CPDF_Dictionary* pDict = pPage->m_pFormDict;
Lei Zhang997de612015-11-04 18:17:53 -0800142 while (pDict) {
143 if (pDict->KeyExist("Rotate")) {
tsepezbd567552016-03-29 14:51:50 -0700144 CPDF_Object* pRotateObj = pDict->GetObjectBy("Rotate")->GetDirect();
Lei Zhang997de612015-11-04 18:17:53 -0800145 return pRotateObj ? pRotateObj->GetInteger() / 90 : 0;
146 }
147 if (!pDict->KeyExist("Parent"))
148 break;
149
tsepezbd567552016-03-29 14:51:50 -0700150 pDict = ToDictionary(pDict->GetObjectBy("Parent")->GetDirect());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700151 }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700152
Lei Zhang997de612015-11-04 18:17:53 -0800153 return 0;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700154}
155
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700156DLLEXPORT void STDCALL FPDFPage_InsertObject(FPDF_PAGE page,
157 FPDF_PAGEOBJECT page_obj) {
thestigc54bb432016-07-29 19:34:20 -0700158 CPDF_PageObject* pPageObj = reinterpret_cast<CPDF_PageObject*>(page_obj);
Lei Zhang997de612015-11-04 18:17:53 -0800159 if (!pPageObj)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700160 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700161
thestigc54bb432016-07-29 19:34:20 -0700162 std::unique_ptr<CPDF_PageObject> pPageObjHolder(pPageObj);
163 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
164 if (!IsPageObject(pPage))
165 return;
Tom Sepez2398d892016-02-17 16:46:26 -0800166
thestigc54bb432016-07-29 19:34:20 -0700167 pPage->GetPageObjectList()->push_back(std::move(pPageObjHolder));
Wei Li7cf13c92016-02-19 11:53:03 -0800168 switch (pPageObj->GetType()) {
thestigc54bb432016-07-29 19:34:20 -0700169 case CPDF_PageObject::TEXT: {
170 break;
171 }
172 case CPDF_PageObject::PATH: {
Wei Li7cf13c92016-02-19 11:53:03 -0800173 CPDF_PathObject* pPathObj = pPageObj->AsPath();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700174 pPathObj->CalcBoundingBox();
175 break;
176 }
thestigc54bb432016-07-29 19:34:20 -0700177 case CPDF_PageObject::IMAGE: {
Wei Li7cf13c92016-02-19 11:53:03 -0800178 CPDF_ImageObject* pImageObj = pPageObj->AsImage();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700179 pImageObj->CalcBoundingBox();
180 break;
181 }
thestigc54bb432016-07-29 19:34:20 -0700182 case CPDF_PageObject::SHADING: {
Wei Li7cf13c92016-02-19 11:53:03 -0800183 CPDF_ShadingObject* pShadingObj = pPageObj->AsShading();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700184 pShadingObj->CalcBoundingBox();
185 break;
186 }
thestigc54bb432016-07-29 19:34:20 -0700187 case CPDF_PageObject::FORM: {
Wei Li7cf13c92016-02-19 11:53:03 -0800188 CPDF_FormObject* pFormObj = pPageObj->AsForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700189 pFormObj->CalcBoundingBox();
190 break;
191 }
thestigc54bb432016-07-29 19:34:20 -0700192 default: {
193 ASSERT(false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700194 break;
thestigc54bb432016-07-29 19:34:20 -0700195 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700196 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700197}
198
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700199DLLEXPORT int STDCALL FPDFPage_CountObject(FPDF_PAGE page) {
Tom Sepezbf59a072015-10-21 14:07:23 -0700200 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
thestigc54bb432016-07-29 19:34:20 -0700201 if (!IsPageObject(pPage))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700202 return -1;
Tom Sepez2398d892016-02-17 16:46:26 -0800203 return pdfium::CollectionSize<int>(*pPage->GetPageObjectList());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700204}
205
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700206DLLEXPORT FPDF_PAGEOBJECT STDCALL FPDFPage_GetObject(FPDF_PAGE page,
207 int index) {
Tom Sepezdb0be962015-10-16 14:00:21 -0700208 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
thestigc54bb432016-07-29 19:34:20 -0700209 if (!IsPageObject(pPage))
Tom Sepez2398d892016-02-17 16:46:26 -0800210 return nullptr;
Tom Sepez2398d892016-02-17 16:46:26 -0800211 return pPage->GetPageObjectList()->GetPageObjectByIndex(index);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700212}
213
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700214DLLEXPORT FPDF_BOOL STDCALL FPDFPage_HasTransparency(FPDF_PAGE page) {
Tom Sepezdb0be962015-10-16 14:00:21 -0700215 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
216 return pPage && pPage->BackgroundAlphaNeeded();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700217}
218
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700219DLLEXPORT FPDF_BOOL STDCALL
220FPDFPageObj_HasTransparency(FPDF_PAGEOBJECT pageObject) {
221 if (!pageObject)
222 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700223
thestigc54bb432016-07-29 19:34:20 -0700224 CPDF_PageObject* pPageObj = reinterpret_cast<CPDF_PageObject*>(pageObject);
tsepez7d2a8d92016-06-08 11:51:23 -0700225 const CPDF_GeneralStateData* pGeneralState =
226 pPageObj->m_GeneralState.GetObject();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700227 int blend_type =
228 pGeneralState ? pGeneralState->m_BlendType : FXDIB_BLEND_NORMAL;
229 if (blend_type != FXDIB_BLEND_NORMAL)
230 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700231
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700232 CPDF_Dictionary* pSMaskDict =
thestig1cd352e2016-06-07 17:53:06 -0700233 pGeneralState ? ToDictionary(pGeneralState->m_pSoftMask) : nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700234 if (pSMaskDict)
235 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700236
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700237 if (pGeneralState && pGeneralState->m_FillAlpha != 1.0f)
238 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700239
thestigc54bb432016-07-29 19:34:20 -0700240 if (pPageObj->IsPath() && pGeneralState &&
241 pGeneralState->m_StrokeAlpha != 1.0f) {
242 return TRUE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700243 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700244
Wei Li7cf13c92016-02-19 11:53:03 -0800245 if (pPageObj->IsForm()) {
thestigc54bb432016-07-29 19:34:20 -0700246 const CPDF_Form* pForm = pPageObj->AsForm()->form();
247 if (pForm) {
248 int trans = pForm->m_Transparency;
249 if ((trans & PDFTRANS_ISOLATED) || (trans & PDFTRANS_GROUP))
250 return TRUE;
251 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700252 }
thestigc54bb432016-07-29 19:34:20 -0700253
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700254 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700255}
256
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700257DLLEXPORT FPDF_BOOL STDCALL FPDFPage_GenerateContent(FPDF_PAGE page) {
Tom Sepezdb0be962015-10-16 14:00:21 -0700258 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
thestigc54bb432016-07-29 19:34:20 -0700259 if (!IsPageObject(pPage))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700260 return FALSE;
thestigc54bb432016-07-29 19:34:20 -0700261
Tom Sepeze19e06e2016-01-21 10:49:56 -0800262 CPDF_PageContentGenerator CG(pPage);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700263 CG.GenerateContent();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700264 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700265}
266
267DLLEXPORT void STDCALL FPDFPageObj_Transform(FPDF_PAGEOBJECT page_object,
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) {
thestigc54bb432016-07-29 19:34:20 -0700274 CPDF_PageObject* pPageObj = reinterpret_cast<CPDF_PageObject*>(page_object);
Lei Zhang997de612015-11-04 18:17:53 -0800275 if (!pPageObj)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700276 return;
Lei Zhangcb78ef52015-10-02 10:10:49 -0700277
Tom Sepez60d909e2015-12-10 15:34:55 -0800278 CFX_Matrix matrix((FX_FLOAT)a, (FX_FLOAT)b, (FX_FLOAT)c, (FX_FLOAT)d,
279 (FX_FLOAT)e, (FX_FLOAT)f);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700280 pPageObj->Transform(matrix);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700281}
thestigc54bb432016-07-29 19:34:20 -0700282
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700283DLLEXPORT void STDCALL FPDFPage_TransformAnnots(FPDF_PAGE page,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700284 double a,
285 double b,
286 double c,
287 double d,
288 double e,
289 double f) {
Tom Sepezdb0be962015-10-16 14:00:21 -0700290 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700291 if (!pPage)
292 return;
thestigc54bb432016-07-29 19:34:20 -0700293
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700294 CPDF_AnnotList AnnotList(pPage);
Lei Zhang1b700c32015-10-30 23:55:35 -0700295 for (size_t i = 0; i < AnnotList.Count(); ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700296 CPDF_Annot* pAnnot = AnnotList.GetAt(i);
297 // transformAnnots Rectangle
Tom Sepez281a9ea2016-02-26 14:24:28 -0800298 CFX_FloatRect rect;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700299 pAnnot->GetRect(rect);
Tom Sepez60d909e2015-12-10 15:34:55 -0800300 CFX_Matrix matrix((FX_FLOAT)a, (FX_FLOAT)b, (FX_FLOAT)c, (FX_FLOAT)d,
301 (FX_FLOAT)e, (FX_FLOAT)f);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700302 rect.Transform(&matrix);
thestig1cd352e2016-06-07 17:53:06 -0700303 CPDF_Array* pRectArray = pAnnot->GetAnnotDict()->GetArrayBy("Rect");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700304 if (!pRectArray)
Lei Zhang4880d1a2015-12-18 17:05:11 -0800305 pRectArray = new CPDF_Array;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700306 pRectArray->SetAt(0, new CPDF_Number(rect.left));
307 pRectArray->SetAt(1, new CPDF_Number(rect.bottom));
308 pRectArray->SetAt(2, new CPDF_Number(rect.right));
309 pRectArray->SetAt(3, new CPDF_Number(rect.top));
310 pAnnot->GetAnnotDict()->SetAt("Rect", pRectArray);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700311
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700312 // Transform AP's rectangle
313 // To Do
314 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700315}
Bo Xu394010d2014-06-12 13:41:50 -0700316
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700317DLLEXPORT void STDCALL FPDFPage_SetRotation(FPDF_PAGE page, int rotate) {
Tom Sepezdb0be962015-10-16 14:00:21 -0700318 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
thestigc54bb432016-07-29 19:34:20 -0700319 if (!IsPageObject(pPage))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700320 return;
thestigc54bb432016-07-29 19:34:20 -0700321
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700322 CPDF_Dictionary* pDict = pPage->m_pFormDict;
323 rotate %= 4;
Tom Sepezae51c812015-08-05 12:34:06 -0700324 pDict->SetAt("Rotate", new CPDF_Number(rotate * 90));
Nico Weber0ce77e32014-07-16 13:19:08 -0700325}