blob: 0d0dac4964d2df7b9681fdd366407fa28ec913f7 [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"
dsinclaircac704d2016-07-28 12:59:09 -070022#include "core/fpdfdoc/include/cpdf_annot.h"
23#include "core/fpdfdoc/include/cpdf_annotlist.h"
Tom Sepez40e9ff32015-11-30 12:39:54 -080024#include "fpdfsdk/include/fsdk_define.h"
25#include "public/fpdf_formfill.h"
Tom Sepez2398d892016-02-17 16:46:26 -080026#include "third_party/base/stl_util.h"
Tom Sepez40e9ff32015-11-30 12:39:54 -080027
Tom Sepez51da0932015-11-25 16:05:49 -080028#ifdef PDF_ENABLE_XFA
dsinclair89bdd082016-04-06 10:47:54 -070029#include "fpdfsdk/fpdfxfa/include/fpdfxfa_app.h"
30#include "fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h"
31#include "fpdfsdk/fpdfxfa/include/fpdfxfa_page.h"
Tom Sepez40e9ff32015-11-30 12:39:54 -080032#endif // PDF_ENABLE_XFA
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070033
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070034#if _FX_OS_ == _FX_ANDROID_
35#include "time.h"
36#else
37#include <ctime>
38#endif
39
Nico Weber9d8ec5a2015-08-04 13:00:21 -070040DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_CreateNewDocument() {
thestig931bf372016-04-26 22:24:30 -070041 CPDF_Document* pDoc = new CPDF_Document(nullptr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070042 pDoc->CreateNewDoc();
43 time_t currentTime;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070044
Nico Weber9d8ec5a2015-08-04 13:00:21 -070045 CFX_ByteString DateStr;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070046
Nico Weber9d8ec5a2015-08-04 13:00:21 -070047 if (FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS)) {
48 if (-1 != time(&currentTime)) {
49 tm* pTM = localtime(&currentTime);
50 if (pTM) {
51 DateStr.Format("D:%04d%02d%02d%02d%02d%02d", pTM->tm_year + 1900,
52 pTM->tm_mon + 1, pTM->tm_mday, pTM->tm_hour, pTM->tm_min,
53 pTM->tm_sec);
54 }
55 }
56 }
Tom Sepezbdeeb8a2015-05-27 12:25:00 -070057
thestig1cd352e2016-06-07 17:53:06 -070058 CPDF_Dictionary* pInfoDict = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070059 pInfoDict = pDoc->GetInfo();
60 if (pInfoDict) {
61 if (FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS))
Lei Zhang4880d1a2015-12-18 17:05:11 -080062 pInfoDict->SetAt("CreationDate", new CPDF_String(DateStr, FALSE));
Tom Sepezae51c812015-08-05 12:34:06 -070063 pInfoDict->SetAt("Creator", new CPDF_String(L"PDFium"));
Nico Weber9d8ec5a2015-08-04 13:00:21 -070064 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070065
Tom Sepezbf59a072015-10-21 14:07:23 -070066 return FPDFDocumentFromCPDFDocument(pDoc);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070067}
68
Nico Weber9d8ec5a2015-08-04 13:00:21 -070069DLLEXPORT void STDCALL FPDFPage_Delete(FPDF_DOCUMENT document, int page_index) {
Tom Sepez744da702016-03-15 12:43:09 -070070 if (UnderlyingDocumentType* pDoc = UnderlyingFromFPDFDocument(document))
71 pDoc->DeletePage(page_index);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070072}
73
Nico Weber9d8ec5a2015-08-04 13:00:21 -070074DLLEXPORT FPDF_PAGE STDCALL FPDFPage_New(FPDF_DOCUMENT document,
75 int page_index,
76 double width,
77 double height) {
Tom Sepez471a1032015-10-15 16:17:18 -070078 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
79 if (!pDoc)
80 return nullptr;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070081
Nico Weber9d8ec5a2015-08-04 13:00:21 -070082 if (page_index < 0)
83 page_index = 0;
84 if (pDoc->GetPageCount() < page_index)
85 page_index = pDoc->GetPageCount();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070086
Nico Weber9d8ec5a2015-08-04 13:00:21 -070087 CPDF_Dictionary* pPageDict = pDoc->CreateNewPage(page_index);
88 if (!pPageDict)
thestig1cd352e2016-06-07 17:53:06 -070089 return nullptr;
Tom Sepezae51c812015-08-05 12:34:06 -070090 CPDF_Array* pMediaBoxArray = new CPDF_Array;
91 pMediaBoxArray->Add(new CPDF_Number(0));
92 pMediaBoxArray->Add(new CPDF_Number(0));
93 pMediaBoxArray->Add(new CPDF_Number(FX_FLOAT(width)));
94 pMediaBoxArray->Add(new CPDF_Number(FX_FLOAT(height)));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070095
Nico Weber9d8ec5a2015-08-04 13:00:21 -070096 pPageDict->SetAt("MediaBox", pMediaBoxArray);
Tom Sepezae51c812015-08-05 12:34:06 -070097 pPageDict->SetAt("Rotate", new CPDF_Number(0));
98 pPageDict->SetAt("Resources", new CPDF_Dictionary);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070099
Tom Sepez40e9ff32015-11-30 12:39:54 -0800100#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700101 CPDFXFA_Page* pPage =
Tom Sepezae51c812015-08-05 12:34:06 -0700102 new CPDFXFA_Page((CPDFXFA_Document*)document, page_index);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700103 pPage->LoadPDFPage(pPageDict);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800104#else // PDF_ENABLE_XFA
thestig5cc24652016-04-26 11:46:02 -0700105 CPDF_Page* pPage = new CPDF_Page(pDoc, pPageDict, true);
106 pPage->ParseContent();
Tom Sepez40e9ff32015-11-30 12:39:54 -0800107#endif // PDF_ENABLE_XFA
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700108
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700109 return pPage;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700110}
111
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700112DLLEXPORT int STDCALL FPDFPage_GetRotation(FPDF_PAGE page) {
Tom Sepezdb0be962015-10-16 14:00:21 -0700113 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700114 if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") ||
tsepezbd567552016-03-29 14:51:50 -0700115 !pPage->m_pFormDict->GetObjectBy("Type")->GetDirect() ||
116 pPage->m_pFormDict->GetObjectBy("Type")->GetDirect()->GetString().Compare(
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700117 "Page")) {
118 return -1;
119 }
120 CPDF_Dictionary* pDict = pPage->m_pFormDict;
Lei Zhang997de612015-11-04 18:17:53 -0800121 if (!pDict)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700122 return -1;
Lei Zhang997de612015-11-04 18:17:53 -0800123
124 while (pDict) {
125 if (pDict->KeyExist("Rotate")) {
tsepezbd567552016-03-29 14:51:50 -0700126 CPDF_Object* pRotateObj = pDict->GetObjectBy("Rotate")->GetDirect();
Lei Zhang997de612015-11-04 18:17:53 -0800127 return pRotateObj ? pRotateObj->GetInteger() / 90 : 0;
128 }
129 if (!pDict->KeyExist("Parent"))
130 break;
131
tsepezbd567552016-03-29 14:51:50 -0700132 pDict = ToDictionary(pDict->GetObjectBy("Parent")->GetDirect());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700133 }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700134
Lei Zhang997de612015-11-04 18:17:53 -0800135 return 0;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700136}
137
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700138DLLEXPORT void STDCALL FPDFPage_InsertObject(FPDF_PAGE page,
139 FPDF_PAGEOBJECT page_obj) {
Tom Sepezdb0be962015-10-16 14:00:21 -0700140 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700141 if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") ||
tsepezbd567552016-03-29 14:51:50 -0700142 !pPage->m_pFormDict->GetObjectBy("Type")->GetDirect() ||
143 pPage->m_pFormDict->GetObjectBy("Type")->GetDirect()->GetString().Compare(
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700144 "Page")) {
145 return;
146 }
147 CPDF_PageObject* pPageObj = (CPDF_PageObject*)page_obj;
Lei Zhang997de612015-11-04 18:17:53 -0800148 if (!pPageObj)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700149 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700150
Tom Sepez2398d892016-02-17 16:46:26 -0800151 pPage->GetPageObjectList()->push_back(
152 std::unique_ptr<CPDF_PageObject>(pPageObj));
153
Wei Li7cf13c92016-02-19 11:53:03 -0800154 switch (pPageObj->GetType()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700155 case FPDF_PAGEOBJ_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 }
160 case FPDF_PAGEOBJ_TEXT: {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700161 break;
162 }
163 case FPDF_PAGEOBJ_IMAGE: {
Wei Li7cf13c92016-02-19 11:53:03 -0800164 CPDF_ImageObject* pImageObj = pPageObj->AsImage();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700165 pImageObj->CalcBoundingBox();
166 break;
167 }
168 case FPDF_PAGEOBJ_SHADING: {
Wei Li7cf13c92016-02-19 11:53:03 -0800169 CPDF_ShadingObject* pShadingObj = pPageObj->AsShading();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700170 pShadingObj->CalcBoundingBox();
171 break;
172 }
173 case FPDF_PAGEOBJ_FORM: {
Wei Li7cf13c92016-02-19 11:53:03 -0800174 CPDF_FormObject* pFormObj = pPageObj->AsForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700175 pFormObj->CalcBoundingBox();
176 break;
177 }
178 default:
179 break;
180 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700181}
182
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700183DLLEXPORT int STDCALL FPDFPage_CountObject(FPDF_PAGE page) {
Tom Sepezbf59a072015-10-21 14:07:23 -0700184 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700185 if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") ||
tsepezbd567552016-03-29 14:51:50 -0700186 !pPage->m_pFormDict->GetObjectBy("Type")->GetDirect() ||
187 pPage->m_pFormDict->GetObjectBy("Type")->GetDirect()->GetString().Compare(
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700188 "Page")) {
189 return -1;
190 }
Tom Sepez2398d892016-02-17 16:46:26 -0800191 return pdfium::CollectionSize<int>(*pPage->GetPageObjectList());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700192}
193
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700194DLLEXPORT FPDF_PAGEOBJECT STDCALL FPDFPage_GetObject(FPDF_PAGE page,
195 int index) {
Tom Sepezdb0be962015-10-16 14:00:21 -0700196 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700197 if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") ||
tsepezbd567552016-03-29 14:51:50 -0700198 pPage->m_pFormDict->GetObjectBy("Type")->GetDirect()->GetString().Compare(
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700199 "Page")) {
Tom Sepez2398d892016-02-17 16:46:26 -0800200 return nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700201 }
Tom Sepez2398d892016-02-17 16:46:26 -0800202 return pPage->GetPageObjectList()->GetPageObjectByIndex(index);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700203}
204
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700205DLLEXPORT FPDF_BOOL STDCALL FPDFPage_HasTransparency(FPDF_PAGE page) {
Tom Sepezdb0be962015-10-16 14:00:21 -0700206 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
207 return pPage && pPage->BackgroundAlphaNeeded();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700208}
209
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700210DLLEXPORT FPDF_BOOL STDCALL
211FPDFPageObj_HasTransparency(FPDF_PAGEOBJECT pageObject) {
212 if (!pageObject)
213 return FALSE;
214 CPDF_PageObject* pPageObj = (CPDF_PageObject*)pageObject;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700215
tsepez7d2a8d92016-06-08 11:51:23 -0700216 const CPDF_GeneralStateData* pGeneralState =
217 pPageObj->m_GeneralState.GetObject();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700218 int blend_type =
219 pGeneralState ? pGeneralState->m_BlendType : FXDIB_BLEND_NORMAL;
220 if (blend_type != FXDIB_BLEND_NORMAL)
221 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700222
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700223 CPDF_Dictionary* pSMaskDict =
thestig1cd352e2016-06-07 17:53:06 -0700224 pGeneralState ? ToDictionary(pGeneralState->m_pSoftMask) : nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700225 if (pSMaskDict)
226 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700227
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700228 if (pGeneralState && pGeneralState->m_FillAlpha != 1.0f)
229 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700230
Wei Li7cf13c92016-02-19 11:53:03 -0800231 if (pPageObj->IsPath()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700232 if (pGeneralState && pGeneralState->m_StrokeAlpha != 1.0f)
233 return TRUE;
234 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700235
Wei Li7cf13c92016-02-19 11:53:03 -0800236 if (pPageObj->IsForm()) {
237 CPDF_FormObject* pFormObj = pPageObj->AsForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700238 if (pFormObj->m_pForm &&
239 (pFormObj->m_pForm->m_Transparency & PDFTRANS_ISOLATED))
240 return TRUE;
241 if (pFormObj->m_pForm &&
242 (!(pFormObj->m_pForm->m_Transparency & PDFTRANS_ISOLATED) &&
243 (pFormObj->m_pForm->m_Transparency & PDFTRANS_GROUP)))
244 return TRUE;
245 }
246 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);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700251 if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") ||
tsepezbd567552016-03-29 14:51:50 -0700252 !pPage->m_pFormDict->GetObjectBy("Type")->GetDirect() ||
253 pPage->m_pFormDict->GetObjectBy("Type")->GetDirect()->GetString().Compare(
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700254 "Page")) {
255 return FALSE;
256 }
Tom Sepeze19e06e2016-01-21 10:49:56 -0800257 CPDF_PageContentGenerator CG(pPage);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700258 CG.GenerateContent();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700259
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700260 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700261}
262
263DLLEXPORT void STDCALL FPDFPageObj_Transform(FPDF_PAGEOBJECT page_object,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700264 double a,
265 double b,
266 double c,
267 double d,
268 double e,
269 double f) {
270 CPDF_PageObject* pPageObj = (CPDF_PageObject*)page_object;
Lei Zhang997de612015-11-04 18:17:53 -0800271 if (!pPageObj)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700272 return;
Lei Zhangcb78ef52015-10-02 10:10:49 -0700273
Tom Sepez60d909e2015-12-10 15:34:55 -0800274 CFX_Matrix matrix((FX_FLOAT)a, (FX_FLOAT)b, (FX_FLOAT)c, (FX_FLOAT)d,
275 (FX_FLOAT)e, (FX_FLOAT)f);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700276 pPageObj->Transform(matrix);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700277}
278DLLEXPORT void STDCALL FPDFPage_TransformAnnots(FPDF_PAGE page,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700279 double a,
280 double b,
281 double c,
282 double d,
283 double e,
284 double f) {
Tom Sepezdb0be962015-10-16 14:00:21 -0700285 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700286 if (!pPage)
287 return;
288 CPDF_AnnotList AnnotList(pPage);
Lei Zhang1b700c32015-10-30 23:55:35 -0700289 for (size_t i = 0; i < AnnotList.Count(); ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700290 CPDF_Annot* pAnnot = AnnotList.GetAt(i);
291 // transformAnnots Rectangle
Tom Sepez281a9ea2016-02-26 14:24:28 -0800292 CFX_FloatRect rect;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700293 pAnnot->GetRect(rect);
Tom Sepez60d909e2015-12-10 15:34:55 -0800294 CFX_Matrix matrix((FX_FLOAT)a, (FX_FLOAT)b, (FX_FLOAT)c, (FX_FLOAT)d,
295 (FX_FLOAT)e, (FX_FLOAT)f);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700296 rect.Transform(&matrix);
thestig1cd352e2016-06-07 17:53:06 -0700297 CPDF_Array* pRectArray = pAnnot->GetAnnotDict()->GetArrayBy("Rect");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700298 if (!pRectArray)
Lei Zhang4880d1a2015-12-18 17:05:11 -0800299 pRectArray = new CPDF_Array;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700300 pRectArray->SetAt(0, new CPDF_Number(rect.left));
301 pRectArray->SetAt(1, new CPDF_Number(rect.bottom));
302 pRectArray->SetAt(2, new CPDF_Number(rect.right));
303 pRectArray->SetAt(3, new CPDF_Number(rect.top));
304 pAnnot->GetAnnotDict()->SetAt("Rect", pRectArray);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700305
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700306 // Transform AP's rectangle
307 // To Do
308 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700309}
Bo Xu394010d2014-06-12 13:41:50 -0700310
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700311DLLEXPORT void STDCALL FPDFPage_SetRotation(FPDF_PAGE page, int rotate) {
Tom Sepezdb0be962015-10-16 14:00:21 -0700312 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700313 if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") ||
tsepezbd567552016-03-29 14:51:50 -0700314 !pPage->m_pFormDict->GetObjectBy("Type")->GetDirect() ||
315 pPage->m_pFormDict->GetObjectBy("Type")->GetDirect()->GetString().Compare(
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700316 "Page")) {
317 return;
318 }
319 CPDF_Dictionary* pDict = pPage->m_pFormDict;
320 rotate %= 4;
Bo Xu394010d2014-06-12 13:41:50 -0700321
Tom Sepezae51c812015-08-05 12:34:06 -0700322 pDict->SetAt("Rotate", new CPDF_Number(rotate * 90));
Nico Weber0ce77e32014-07-16 13:19:08 -0700323}