blob: 91b966c384a7ee2f729dec82a21ef07518a37be5 [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
wileyryae858aa42017-05-31 14:49:05 -050064void CalcBoundingBox(CPDF_PageObject* pPageObj) {
65 switch (pPageObj->GetType()) {
66 case CPDF_PageObject::TEXT: {
67 break;
68 }
69 case CPDF_PageObject::PATH: {
70 CPDF_PathObject* pPathObj = pPageObj->AsPath();
71 pPathObj->CalcBoundingBox();
72 break;
73 }
74 case CPDF_PageObject::IMAGE: {
75 CPDF_ImageObject* pImageObj = pPageObj->AsImage();
76 pImageObj->CalcBoundingBox();
77 break;
78 }
79 case CPDF_PageObject::SHADING: {
80 CPDF_ShadingObject* pShadingObj = pPageObj->AsShading();
81 pShadingObj->CalcBoundingBox();
82 break;
83 }
84 case CPDF_PageObject::FORM: {
85 CPDF_FormObject* pFormObj = pPageObj->AsForm();
86 pFormObj->CalcBoundingBox();
87 break;
88 }
89 default: {
90 NOTREACHED();
91 break;
92 }
93 }
94}
95
thestigc54bb432016-07-29 19:34:20 -070096} // namespace
97
Henrique Nakashima7e805d12017-08-10 15:13:19 +000098DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_CreateNewDocument() {
Tom Sepezfe91c6c2017-05-16 15:33:20 -070099 auto pDoc = pdfium::MakeUnique<CPDF_Document>(nullptr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700100 pDoc->CreateNewDoc();
Tom Sepezfe91c6c2017-05-16 15:33:20 -0700101
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700102 time_t currentTime;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700103 CFX_ByteString DateStr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700104 if (FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS)) {
Tom Sepezfe91c6c2017-05-16 15:33:20 -0700105 if (time(&currentTime) != -1) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700106 tm* pTM = localtime(&currentTime);
107 if (pTM) {
108 DateStr.Format("D:%04d%02d%02d%02d%02d%02d", pTM->tm_year + 1900,
109 pTM->tm_mon + 1, pTM->tm_mday, pTM->tm_hour, pTM->tm_min,
110 pTM->tm_sec);
111 }
112 }
113 }
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700114
Tom Sepezfe91c6c2017-05-16 15:33:20 -0700115 CPDF_Dictionary* pInfoDict = pDoc->GetInfo();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700116 if (pInfoDict) {
tsepez0e606b52016-11-18 16:22:41 -0800117 if (FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS))
118 pInfoDict->SetNewFor<CPDF_String>("CreationDate", DateStr, false);
119 pInfoDict->SetNewFor<CPDF_String>("Creator", L"PDFium");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700120 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700121
Tom Sepezfe91c6c2017-05-16 15:33:20 -0700122 // Caller takes ownership of pDoc.
123 return FPDFDocumentFromCPDFDocument(pDoc.release());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700124}
125
Henrique Nakashima7e805d12017-08-10 15:13:19 +0000126DLLEXPORT void STDCALL FPDFPage_Delete(FPDF_DOCUMENT document, int page_index) {
Tom Sepez744da702016-03-15 12:43:09 -0700127 if (UnderlyingDocumentType* pDoc = UnderlyingFromFPDFDocument(document))
128 pDoc->DeletePage(page_index);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700129}
130
Henrique Nakashima7e805d12017-08-10 15:13:19 +0000131DLLEXPORT FPDF_PAGE STDCALL FPDFPage_New(FPDF_DOCUMENT document,
132 int page_index,
133 double width,
134 double height) {
Tom Sepez471a1032015-10-15 16:17:18 -0700135 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
136 if (!pDoc)
137 return nullptr;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700138
Lei Zhang85f019a2017-03-17 15:14:19 -0700139 page_index = pdfium::clamp(page_index, 0, pDoc->GetPageCount());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700140 CPDF_Dictionary* pPageDict = pDoc->CreateNewPage(page_index);
141 if (!pPageDict)
thestig1cd352e2016-06-07 17:53:06 -0700142 return nullptr;
thestigc54bb432016-07-29 19:34:20 -0700143
tsepez0e606b52016-11-18 16:22:41 -0800144 CPDF_Array* pMediaBoxArray = pPageDict->SetNewFor<CPDF_Array>("MediaBox");
tsepez8a3aa452016-11-16 12:26:06 -0800145 pMediaBoxArray->AddNew<CPDF_Number>(0);
146 pMediaBoxArray->AddNew<CPDF_Number>(0);
Dan Sinclair05df0752017-03-14 14:43:42 -0400147 pMediaBoxArray->AddNew<CPDF_Number>(static_cast<float>(width));
148 pMediaBoxArray->AddNew<CPDF_Number>(static_cast<float>(height));
tsepez0e606b52016-11-18 16:22:41 -0800149 pPageDict->SetNewFor<CPDF_Number>("Rotate", 0);
150 pPageDict->SetNewFor<CPDF_Dictionary>("Resources");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700151
Tom Sepez40e9ff32015-11-30 12:39:54 -0800152#ifdef PDF_ENABLE_XFA
Tom Sepez9792f162017-05-16 14:11:30 -0700153 auto pXFAPage = pdfium::MakeRetain<CPDFXFA_Page>(
154 static_cast<CPDFXFA_Context*>(document), page_index);
155 pXFAPage->LoadPDFPage(pPageDict);
Tom Sepezfe91c6c2017-05-16 15:33:20 -0700156 return pXFAPage.Leak(); // Caller takes ownership.
Tom Sepez40e9ff32015-11-30 12:39:54 -0800157#else // PDF_ENABLE_XFA
Tom Sepezfe91c6c2017-05-16 15:33:20 -0700158 auto pPage = pdfium::MakeUnique<CPDF_Page>(pDoc, pPageDict, true);
thestig5cc24652016-04-26 11:46:02 -0700159 pPage->ParseContent();
Tom Sepezfe91c6c2017-05-16 15:33:20 -0700160 return pPage.release(); // Caller takes ownership.
Tom Sepez9792f162017-05-16 14:11:30 -0700161#endif // PDF_ENABLE_XFA
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700162}
163
Henrique Nakashima7e805d12017-08-10 15:13:19 +0000164DLLEXPORT int STDCALL FPDFPage_GetRotation(FPDF_PAGE page) {
Tom Sepezdb0be962015-10-16 14:00:21 -0700165 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
Tom Sepezfe91c6c2017-05-16 15:33:20 -0700166 return IsPageObject(pPage) ? pPage->GetPageRotation() : -1;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700167}
168
Henrique Nakashima7e805d12017-08-10 15:13:19 +0000169DLLEXPORT void STDCALL FPDFPage_InsertObject(FPDF_PAGE page,
170 FPDF_PAGEOBJECT page_obj) {
Jane Liu1a084022017-06-29 19:47:12 -0400171 CPDF_PageObject* pPageObj = CPDFPageObjectFromFPDFPageObject(page_obj);
Lei Zhang997de612015-11-04 18:17:53 -0800172 if (!pPageObj)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700173 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700174
thestigc54bb432016-07-29 19:34:20 -0700175 std::unique_ptr<CPDF_PageObject> pPageObjHolder(pPageObj);
176 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
177 if (!IsPageObject(pPage))
178 return;
wileyryae858aa42017-05-31 14:49:05 -0500179 pPageObj->SetDirty(true);
thestigc54bb432016-07-29 19:34:20 -0700180 pPage->GetPageObjectList()->push_back(std::move(pPageObjHolder));
wileyryae858aa42017-05-31 14:49:05 -0500181 CalcBoundingBox(pPageObj);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700182}
183
Henrique Nakashima7e805d12017-08-10 15:13:19 +0000184DLLEXPORT int STDCALL FPDFPage_CountObject(FPDF_PAGE page) {
Tom Sepezbf59a072015-10-21 14:07:23 -0700185 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
thestigc54bb432016-07-29 19:34:20 -0700186 if (!IsPageObject(pPage))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700187 return -1;
Tom Sepez2398d892016-02-17 16:46:26 -0800188 return pdfium::CollectionSize<int>(*pPage->GetPageObjectList());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700189}
190
Henrique Nakashima7e805d12017-08-10 15:13:19 +0000191DLLEXPORT FPDF_PAGEOBJECT STDCALL FPDFPage_GetObject(FPDF_PAGE page,
192 int index) {
Tom Sepezdb0be962015-10-16 14:00:21 -0700193 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
thestigc54bb432016-07-29 19:34:20 -0700194 if (!IsPageObject(pPage))
Tom Sepez2398d892016-02-17 16:46:26 -0800195 return nullptr;
Tom Sepez2398d892016-02-17 16:46:26 -0800196 return pPage->GetPageObjectList()->GetPageObjectByIndex(index);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700197}
198
Henrique Nakashima7e805d12017-08-10 15:13:19 +0000199DLLEXPORT FPDF_BOOL STDCALL FPDFPage_HasTransparency(FPDF_PAGE page) {
Tom Sepezdb0be962015-10-16 14:00:21 -0700200 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
201 return pPage && pPage->BackgroundAlphaNeeded();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700202}
203
Henrique Nakashima7e805d12017-08-10 15:13:19 +0000204DLLEXPORT void STDCALL FPDFPageObj_Destroy(FPDF_PAGEOBJECT page_obj) {
Jane Liu2e5f0ae2017-08-08 15:23:27 -0400205 delete CPDFPageObjectFromFPDFPageObject(page_obj);
206}
207
Henrique Nakashima7e805d12017-08-10 15:13:19 +0000208DLLEXPORT FPDF_BOOL STDCALL
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700209FPDFPageObj_HasTransparency(FPDF_PAGEOBJECT pageObject) {
210 if (!pageObject)
tsepez4cf55152016-11-02 14:37:54 -0700211 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700212
Jane Liu1a084022017-06-29 19:47:12 -0400213 CPDF_PageObject* pPageObj = CPDFPageObjectFromFPDFPageObject(pageObject);
tsepezbbee4452016-09-02 15:22:00 -0700214 int blend_type = pPageObj->m_GeneralState.GetBlendType();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700215 if (blend_type != FXDIB_BLEND_NORMAL)
tsepez4cf55152016-11-02 14:37:54 -0700216 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700217
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700218 CPDF_Dictionary* pSMaskDict =
tsepezbbee4452016-09-02 15:22:00 -0700219 ToDictionary(pPageObj->m_GeneralState.GetSoftMask());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700220 if (pSMaskDict)
tsepez4cf55152016-11-02 14:37:54 -0700221 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700222
tsepezbbee4452016-09-02 15:22:00 -0700223 if (pPageObj->m_GeneralState.GetFillAlpha() != 1.0f)
tsepez4cf55152016-11-02 14:37:54 -0700224 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700225
tsepezbbee4452016-09-02 15:22:00 -0700226 if (pPageObj->IsPath() && pPageObj->m_GeneralState.GetStrokeAlpha() != 1.0f) {
tsepez4cf55152016-11-02 14:37:54 -0700227 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700228 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700229
Wei Li7cf13c92016-02-19 11:53:03 -0800230 if (pPageObj->IsForm()) {
thestigc54bb432016-07-29 19:34:20 -0700231 const CPDF_Form* pForm = pPageObj->AsForm()->form();
232 if (pForm) {
233 int trans = pForm->m_Transparency;
234 if ((trans & PDFTRANS_ISOLATED) || (trans & PDFTRANS_GROUP))
tsepez4cf55152016-11-02 14:37:54 -0700235 return true;
thestigc54bb432016-07-29 19:34:20 -0700236 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700237 }
thestigc54bb432016-07-29 19:34:20 -0700238
tsepez4cf55152016-11-02 14:37:54 -0700239 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700240}
241
Henrique Nakashima7e805d12017-08-10 15:13:19 +0000242DLLEXPORT int STDCALL FPDFPageObj_GetType(FPDF_PAGEOBJECT pageObject) {
Miklos Vajna14233192017-04-03 16:02:39 +0200243 if (!pageObject)
244 return FPDF_PAGEOBJ_UNKNOWN;
245
Jane Liu1a084022017-06-29 19:47:12 -0400246 CPDF_PageObject* pPageObj = CPDFPageObjectFromFPDFPageObject(pageObject);
Miklos Vajna14233192017-04-03 16:02:39 +0200247 return pPageObj->GetType();
248}
249
Henrique Nakashima7e805d12017-08-10 15:13:19 +0000250DLLEXPORT FPDF_BOOL STDCALL FPDFPage_GenerateContent(FPDF_PAGE page) {
Tom Sepezdb0be962015-10-16 14:00:21 -0700251 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
thestigc54bb432016-07-29 19:34:20 -0700252 if (!IsPageObject(pPage))
tsepez4cf55152016-11-02 14:37:54 -0700253 return false;
thestigc54bb432016-07-29 19:34:20 -0700254
Tom Sepeze19e06e2016-01-21 10:49:56 -0800255 CPDF_PageContentGenerator CG(pPage);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700256 CG.GenerateContent();
tsepez4cf55152016-11-02 14:37:54 -0700257 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700258}
259
Henrique Nakashima7e805d12017-08-10 15:13:19 +0000260DLLEXPORT void STDCALL FPDFPageObj_Transform(FPDF_PAGEOBJECT page_object,
261 double a,
262 double b,
263 double c,
264 double d,
265 double e,
266 double f) {
Jane Liu1a084022017-06-29 19:47:12 -0400267 CPDF_PageObject* pPageObj = CPDFPageObjectFromFPDFPageObject(page_object);
Lei Zhang997de612015-11-04 18:17:53 -0800268 if (!pPageObj)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700269 return;
Lei Zhangcb78ef52015-10-02 10:10:49 -0700270
Dan Sinclair05df0752017-03-14 14:43:42 -0400271 CFX_Matrix matrix((float)a, (float)b, (float)c, (float)d, (float)e, (float)f);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700272 pPageObj->Transform(matrix);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700273}
thestigc54bb432016-07-29 19:34:20 -0700274
Henrique Nakashima7e805d12017-08-10 15:13:19 +0000275DLLEXPORT void STDCALL FPDFPageObj_SetBlendMode(FPDF_PAGEOBJECT page_object,
276 FPDF_BYTESTRING blend_mode) {
Jane Liu1a084022017-06-29 19:47:12 -0400277 CPDF_PageObject* pPageObj = CPDFPageObjectFromFPDFPageObject(page_object);
wileyrya06bbdef2017-05-26 15:20:23 -0500278 if (!pPageObj)
279 return;
280
281 pPageObj->m_GeneralState.SetBlendMode(blend_mode);
wileyryae858aa42017-05-31 14:49:05 -0500282 pPageObj->SetDirty(true);
wileyrya06bbdef2017-05-26 15:20:23 -0500283}
284
Henrique Nakashima7e805d12017-08-10 15:13:19 +0000285DLLEXPORT void STDCALL FPDFPage_TransformAnnots(FPDF_PAGE page,
286 double a,
287 double b,
288 double c,
289 double d,
290 double e,
291 double f) {
Tom Sepezdb0be962015-10-16 14:00:21 -0700292 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700293 if (!pPage)
294 return;
thestigc54bb432016-07-29 19:34:20 -0700295
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700296 CPDF_AnnotList AnnotList(pPage);
Lei Zhang1b700c32015-10-30 23:55:35 -0700297 for (size_t i = 0; i < AnnotList.Count(); ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700298 CPDF_Annot* pAnnot = AnnotList.GetAt(i);
tsepez8021a642016-10-17 16:13:21 -0700299 CFX_FloatRect rect = pAnnot->GetRect(); // transformAnnots Rectangle
Dan Sinclair05df0752017-03-14 14:43:42 -0400300 CFX_Matrix matrix((float)a, (float)b, (float)c, (float)d, (float)e,
301 (float)f);
Dan Sinclair118a8e22017-02-09 10:16:07 -0500302 matrix.TransformRect(rect);
tsepez8021a642016-10-17 16:13:21 -0700303
Lei Zhang59c1ac02017-06-09 11:04:41 -0700304 CPDF_Dictionary* pAnnotDict = pAnnot->GetAnnotDict();
305 CPDF_Array* pRectArray = pAnnotDict->GetArrayFor("Rect");
Jane Liueda65252017-06-07 11:31:27 -0400306 if (pRectArray)
Lei Zhang59c1ac02017-06-09 11:04:41 -0700307 pRectArray->Clear();
Jane Liueda65252017-06-07 11:31:27 -0400308 else
Lei Zhang59c1ac02017-06-09 11:04:41 -0700309 pRectArray = pAnnotDict->SetNewFor<CPDF_Array>("Rect");
tsepez0e606b52016-11-18 16:22:41 -0800310
Jane Liueda65252017-06-07 11:31:27 -0400311 pRectArray->AddNew<CPDF_Number>(rect.left);
312 pRectArray->AddNew<CPDF_Number>(rect.bottom);
313 pRectArray->AddNew<CPDF_Number>(rect.right);
314 pRectArray->AddNew<CPDF_Number>(rect.top);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700315
Dan Sinclair85c8e7f2016-11-21 13:50:32 -0500316 // TODO(unknown): Transform AP's rectangle
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700317 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700318}
Bo Xu394010d2014-06-12 13:41:50 -0700319
Henrique Nakashima7e805d12017-08-10 15:13:19 +0000320DLLEXPORT void STDCALL FPDFPage_SetRotation(FPDF_PAGE page, int rotate) {
Tom Sepezdb0be962015-10-16 14:00:21 -0700321 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
thestigc54bb432016-07-29 19:34:20 -0700322 if (!IsPageObject(pPage))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700323 return;
thestigc54bb432016-07-29 19:34:20 -0700324
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700325 rotate %= 4;
Tom Sepez4cb82ee2017-05-22 15:15:30 -0700326 pPage->m_pFormDict->SetNewFor<CPDF_Number>("Rotate", rotate * 90);
Nico Weber0ce77e32014-07-16 13:19:08 -0700327}
wileyrya864e9fb2017-05-26 11:38:14 -0500328
329FPDF_BOOL FPDFPageObj_SetFillColor(FPDF_PAGEOBJECT page_object,
330 unsigned int R,
331 unsigned int G,
332 unsigned int B,
333 unsigned int A) {
334 if (!page_object || R > 255 || G > 255 || B > 255 || A > 255)
335 return false;
336
337 float rgb[3] = {R / 255.f, G / 255.f, B / 255.f};
Jane Liu1a084022017-06-29 19:47:12 -0400338 auto* pPageObj = CPDFPageObjectFromFPDFPageObject(page_object);
wileyrya864e9fb2017-05-26 11:38:14 -0500339 pPageObj->m_GeneralState.SetFillAlpha(A / 255.f);
340 pPageObj->m_ColorState.SetFillColor(
341 CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB), rgb, 3);
wileyryae858aa42017-05-31 14:49:05 -0500342 pPageObj->SetDirty(true);
wileyrya864e9fb2017-05-26 11:38:14 -0500343 return true;
344}
wileyryaf1697fa2017-05-26 12:27:40 -0500345
Henrique Nakashima7e805d12017-08-10 15:13:19 +0000346DLLEXPORT FPDF_BOOL STDCALL FPDFPageObj_GetBounds(FPDF_PAGEOBJECT pageObject,
347 float* left,
348 float* bottom,
349 float* right,
350 float* top) {
wileyryaf1697fa2017-05-26 12:27:40 -0500351 if (!pageObject)
352 return false;
353
Jane Liu1a084022017-06-29 19:47:12 -0400354 CPDF_PageObject* pPageObj = CPDFPageObjectFromFPDFPageObject(pageObject);
wileyryaf1697fa2017-05-26 12:27:40 -0500355 CFX_FloatRect bbox = pPageObj->GetRect();
356 *left = bbox.left;
357 *bottom = bbox.bottom;
358 *right = bbox.right;
359 *top = bbox.top;
360 return true;
361}