Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(262)

Side by Side Diff: fpdfsdk/fpdfeditpage.cpp

Issue 2195643002: Simplify some FPDF edit functions. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« fpdfsdk/fpdfeditimg.cpp ('K') | « fpdfsdk/fpdfeditimg.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "public/fpdf_edit.h" 7 #include "public/fpdf_edit.h"
8 8
9 #include <algorithm>
10 #include <memory>
11 #include <utility>
12
9 #include "core/fpdfapi/fpdf_edit/include/cpdf_pagecontentgenerator.h" 13 #include "core/fpdfapi/fpdf_edit/include/cpdf_pagecontentgenerator.h"
10 #include "core/fpdfapi/fpdf_page/include/cpdf_form.h" 14 #include "core/fpdfapi/fpdf_page/include/cpdf_form.h"
11 #include "core/fpdfapi/fpdf_page/include/cpdf_formobject.h" 15 #include "core/fpdfapi/fpdf_page/include/cpdf_formobject.h"
12 #include "core/fpdfapi/fpdf_page/include/cpdf_generalstatedata.h" 16 #include "core/fpdfapi/fpdf_page/include/cpdf_generalstatedata.h"
13 #include "core/fpdfapi/fpdf_page/include/cpdf_imageobject.h" 17 #include "core/fpdfapi/fpdf_page/include/cpdf_imageobject.h"
14 #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" 18 #include "core/fpdfapi/fpdf_page/include/cpdf_page.h"
15 #include "core/fpdfapi/fpdf_page/include/cpdf_pageobject.h" 19 #include "core/fpdfapi/fpdf_page/include/cpdf_pageobject.h"
16 #include "core/fpdfapi/fpdf_page/include/cpdf_pathobject.h" 20 #include "core/fpdfapi/fpdf_page/include/cpdf_pathobject.h"
17 #include "core/fpdfapi/fpdf_page/include/cpdf_shadingobject.h" 21 #include "core/fpdfapi/fpdf_page/include/cpdf_shadingobject.h"
18 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" 22 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h"
(...skipping 11 matching lines...) Expand all
30 #include "fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h" 34 #include "fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h"
31 #include "fpdfsdk/fpdfxfa/include/fpdfxfa_page.h" 35 #include "fpdfsdk/fpdfxfa/include/fpdfxfa_page.h"
32 #endif // PDF_ENABLE_XFA 36 #endif // PDF_ENABLE_XFA
33 37
34 #if _FX_OS_ == _FX_ANDROID_ 38 #if _FX_OS_ == _FX_ANDROID_
35 #include "time.h" 39 #include "time.h"
36 #else 40 #else
37 #include <ctime> 41 #include <ctime>
38 #endif 42 #endif
39 43
44 namespace {
45
46 static_assert(FPDF_PAGEOBJ_TEXT == CPDF_PageObject::TEXT,
47 "FPDF_PAGEOBJ_TEXT/CPDF_PageObject::TEXT mismatch");
48 static_assert(FPDF_PAGEOBJ_PATH == CPDF_PageObject::PATH,
49 "FPDF_PAGEOBJ_PATH/CPDF_PageObject::PATH mismatch");
50 static_assert(FPDF_PAGEOBJ_IMAGE == CPDF_PageObject::IMAGE,
51 "FPDF_PAGEOBJ_IMAGE/CPDF_PageObject::IMAGE mismatch");
52 static_assert(FPDF_PAGEOBJ_SHADING == CPDF_PageObject::SHADING,
53 "FPDF_PAGEOBJ_SHADING/CPDF_PageObject::SHADING mismatch");
54 static_assert(FPDF_PAGEOBJ_FORM == CPDF_PageObject::FORM,
55 "FPDF_PAGEOBJ_FORM/CPDF_PageObject::FORM mismatch");
56
57 bool 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
40 DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_CreateNewDocument() { 67 DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_CreateNewDocument() {
41 CPDF_Document* pDoc = new CPDF_Document(nullptr); 68 CPDF_Document* pDoc = new CPDF_Document(nullptr);
42 pDoc->CreateNewDoc(); 69 pDoc->CreateNewDoc();
43 time_t currentTime; 70 time_t currentTime;
44 71
45 CFX_ByteString DateStr; 72 CFX_ByteString DateStr;
46 73
47 if (FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS)) { 74 if (FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS)) {
48 if (-1 != time(&currentTime)) { 75 if (-1 != time(&currentTime)) {
49 tm* pTM = localtime(&currentTime); 76 tm* pTM = localtime(&currentTime);
(...skipping 22 matching lines...) Expand all
72 } 99 }
73 100
74 DLLEXPORT FPDF_PAGE STDCALL FPDFPage_New(FPDF_DOCUMENT document, 101 DLLEXPORT FPDF_PAGE STDCALL FPDFPage_New(FPDF_DOCUMENT document,
75 int page_index, 102 int page_index,
76 double width, 103 double width,
77 double height) { 104 double height) {
78 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); 105 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
79 if (!pDoc) 106 if (!pDoc)
80 return nullptr; 107 return nullptr;
81 108
82 if (page_index < 0) 109 page_index = std::min(std::max(page_index, 0), pDoc->GetPageCount());
83 page_index = 0;
84 if (pDoc->GetPageCount() < page_index)
85 page_index = pDoc->GetPageCount();
86
87 CPDF_Dictionary* pPageDict = pDoc->CreateNewPage(page_index); 110 CPDF_Dictionary* pPageDict = pDoc->CreateNewPage(page_index);
88 if (!pPageDict) 111 if (!pPageDict)
89 return nullptr; 112 return nullptr;
113
90 CPDF_Array* pMediaBoxArray = new CPDF_Array; 114 CPDF_Array* pMediaBoxArray = new CPDF_Array;
91 pMediaBoxArray->Add(new CPDF_Number(0)); 115 pMediaBoxArray->Add(new CPDF_Number(0));
92 pMediaBoxArray->Add(new CPDF_Number(0)); 116 pMediaBoxArray->Add(new CPDF_Number(0));
93 pMediaBoxArray->Add(new CPDF_Number(FX_FLOAT(width))); 117 pMediaBoxArray->Add(new CPDF_Number(FX_FLOAT(width)));
94 pMediaBoxArray->Add(new CPDF_Number(FX_FLOAT(height))); 118 pMediaBoxArray->Add(new CPDF_Number(FX_FLOAT(height)));
95 119
96 pPageDict->SetAt("MediaBox", pMediaBoxArray); 120 pPageDict->SetAt("MediaBox", pMediaBoxArray);
97 pPageDict->SetAt("Rotate", new CPDF_Number(0)); 121 pPageDict->SetAt("Rotate", new CPDF_Number(0));
98 pPageDict->SetAt("Resources", new CPDF_Dictionary); 122 pPageDict->SetAt("Resources", new CPDF_Dictionary);
99 123
100 #ifdef PDF_ENABLE_XFA 124 #ifdef PDF_ENABLE_XFA
101 CPDFXFA_Page* pPage = 125 CPDFXFA_Page* pPage =
102 new CPDFXFA_Page((CPDFXFA_Document*)document, page_index); 126 new CPDFXFA_Page((CPDFXFA_Document*)document, page_index);
103 pPage->LoadPDFPage(pPageDict); 127 pPage->LoadPDFPage(pPageDict);
104 #else // PDF_ENABLE_XFA 128 #else // PDF_ENABLE_XFA
105 CPDF_Page* pPage = new CPDF_Page(pDoc, pPageDict, true); 129 CPDF_Page* pPage = new CPDF_Page(pDoc, pPageDict, true);
106 pPage->ParseContent(); 130 pPage->ParseContent();
107 #endif // PDF_ENABLE_XFA 131 #endif // PDF_ENABLE_XFA
108 132
109 return pPage; 133 return pPage;
110 } 134 }
111 135
112 DLLEXPORT int STDCALL FPDFPage_GetRotation(FPDF_PAGE page) { 136 DLLEXPORT int STDCALL FPDFPage_GetRotation(FPDF_PAGE page) {
113 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); 137 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
114 if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") || 138 if (!IsPageObject(pPage))
115 !pPage->m_pFormDict->GetObjectBy("Type")->GetDirect() ||
116 pPage->m_pFormDict->GetObjectBy("Type")->GetDirect()->GetString().Compare(
117 "Page")) {
118 return -1;
119 }
120 CPDF_Dictionary* pDict = pPage->m_pFormDict;
121 if (!pDict)
122 return -1; 139 return -1;
123 140
141 CPDF_Dictionary* pDict = pPage->m_pFormDict;
124 while (pDict) { 142 while (pDict) {
125 if (pDict->KeyExist("Rotate")) { 143 if (pDict->KeyExist("Rotate")) {
126 CPDF_Object* pRotateObj = pDict->GetObjectBy("Rotate")->GetDirect(); 144 CPDF_Object* pRotateObj = pDict->GetObjectBy("Rotate")->GetDirect();
127 return pRotateObj ? pRotateObj->GetInteger() / 90 : 0; 145 return pRotateObj ? pRotateObj->GetInteger() / 90 : 0;
128 } 146 }
129 if (!pDict->KeyExist("Parent")) 147 if (!pDict->KeyExist("Parent"))
130 break; 148 break;
131 149
132 pDict = ToDictionary(pDict->GetObjectBy("Parent")->GetDirect()); 150 pDict = ToDictionary(pDict->GetObjectBy("Parent")->GetDirect());
133 } 151 }
134 152
135 return 0; 153 return 0;
136 } 154 }
137 155
138 DLLEXPORT void STDCALL FPDFPage_InsertObject(FPDF_PAGE page, 156 DLLEXPORT void STDCALL FPDFPage_InsertObject(FPDF_PAGE page,
139 FPDF_PAGEOBJECT page_obj) { 157 FPDF_PAGEOBJECT page_obj) {
140 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); 158 CPDF_PageObject* pPageObj = reinterpret_cast<CPDF_PageObject*>(page_obj);
141 if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") ||
142 !pPage->m_pFormDict->GetObjectBy("Type")->GetDirect() ||
143 pPage->m_pFormDict->GetObjectBy("Type")->GetDirect()->GetString().Compare(
144 "Page")) {
145 return;
146 }
147 CPDF_PageObject* pPageObj = (CPDF_PageObject*)page_obj;
148 if (!pPageObj) 159 if (!pPageObj)
149 return; 160 return;
150 161
151 pPage->GetPageObjectList()->push_back( 162 std::unique_ptr<CPDF_PageObject> pPageObjHolder(pPageObj);
dsinclair 2016/07/29 13:22:49 Move this down to 167 where it is first used? No p
Lei Zhang 2016/07/29 14:46:15 FPDFPage_InsertObject() has ownership of |page_obj
152 std::unique_ptr<CPDF_PageObject>(pPageObj)); 163 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
164 if (!IsPageObject(pPage))
165 return;
153 166
167 pPage->GetPageObjectList()->push_back(std::move(pPageObjHolder));
154 switch (pPageObj->GetType()) { 168 switch (pPageObj->GetType()) {
155 case FPDF_PAGEOBJ_PATH: { 169 case CPDF_PageObject::TEXT: {
170 break;
171 }
172 case CPDF_PageObject::PATH: {
156 CPDF_PathObject* pPathObj = pPageObj->AsPath(); 173 CPDF_PathObject* pPathObj = pPageObj->AsPath();
157 pPathObj->CalcBoundingBox(); 174 pPathObj->CalcBoundingBox();
158 break; 175 break;
159 } 176 }
160 case FPDF_PAGEOBJ_TEXT: { 177 case CPDF_PageObject::IMAGE: {
161 break;
162 }
163 case FPDF_PAGEOBJ_IMAGE: {
164 CPDF_ImageObject* pImageObj = pPageObj->AsImage(); 178 CPDF_ImageObject* pImageObj = pPageObj->AsImage();
165 pImageObj->CalcBoundingBox(); 179 pImageObj->CalcBoundingBox();
166 break; 180 break;
167 } 181 }
168 case FPDF_PAGEOBJ_SHADING: { 182 case CPDF_PageObject::SHADING: {
169 CPDF_ShadingObject* pShadingObj = pPageObj->AsShading(); 183 CPDF_ShadingObject* pShadingObj = pPageObj->AsShading();
170 pShadingObj->CalcBoundingBox(); 184 pShadingObj->CalcBoundingBox();
171 break; 185 break;
172 } 186 }
173 case FPDF_PAGEOBJ_FORM: { 187 case CPDF_PageObject::FORM: {
174 CPDF_FormObject* pFormObj = pPageObj->AsForm(); 188 CPDF_FormObject* pFormObj = pPageObj->AsForm();
175 pFormObj->CalcBoundingBox(); 189 pFormObj->CalcBoundingBox();
176 break; 190 break;
177 } 191 }
178 default: 192 default: {
193 ASSERT(false);
179 break; 194 break;
195 }
180 } 196 }
181 } 197 }
182 198
183 DLLEXPORT int STDCALL FPDFPage_CountObject(FPDF_PAGE page) { 199 DLLEXPORT int STDCALL FPDFPage_CountObject(FPDF_PAGE page) {
184 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); 200 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
185 if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") || 201 if (!IsPageObject(pPage))
186 !pPage->m_pFormDict->GetObjectBy("Type")->GetDirect() ||
187 pPage->m_pFormDict->GetObjectBy("Type")->GetDirect()->GetString().Compare(
188 "Page")) {
189 return -1; 202 return -1;
190 }
191 return pdfium::CollectionSize<int>(*pPage->GetPageObjectList()); 203 return pdfium::CollectionSize<int>(*pPage->GetPageObjectList());
192 } 204 }
193 205
194 DLLEXPORT FPDF_PAGEOBJECT STDCALL FPDFPage_GetObject(FPDF_PAGE page, 206 DLLEXPORT FPDF_PAGEOBJECT STDCALL FPDFPage_GetObject(FPDF_PAGE page,
195 int index) { 207 int index) {
196 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); 208 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
197 if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") || 209 if (!IsPageObject(pPage))
198 pPage->m_pFormDict->GetObjectBy("Type")->GetDirect()->GetString().Compare(
199 "Page")) {
200 return nullptr; 210 return nullptr;
201 }
202 return pPage->GetPageObjectList()->GetPageObjectByIndex(index); 211 return pPage->GetPageObjectList()->GetPageObjectByIndex(index);
203 } 212 }
204 213
205 DLLEXPORT FPDF_BOOL STDCALL FPDFPage_HasTransparency(FPDF_PAGE page) { 214 DLLEXPORT FPDF_BOOL STDCALL FPDFPage_HasTransparency(FPDF_PAGE page) {
206 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); 215 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
207 return pPage && pPage->BackgroundAlphaNeeded(); 216 return pPage && pPage->BackgroundAlphaNeeded();
208 } 217 }
209 218
210 DLLEXPORT FPDF_BOOL STDCALL 219 DLLEXPORT FPDF_BOOL STDCALL
211 FPDFPageObj_HasTransparency(FPDF_PAGEOBJECT pageObject) { 220 FPDFPageObj_HasTransparency(FPDF_PAGEOBJECT pageObject) {
212 if (!pageObject) 221 if (!pageObject)
213 return FALSE; 222 return FALSE;
214 CPDF_PageObject* pPageObj = (CPDF_PageObject*)pageObject;
215 223
224 CPDF_PageObject* pPageObj = reinterpret_cast<CPDF_PageObject*>(pageObject);
216 const CPDF_GeneralStateData* pGeneralState = 225 const CPDF_GeneralStateData* pGeneralState =
217 pPageObj->m_GeneralState.GetObject(); 226 pPageObj->m_GeneralState.GetObject();
218 int blend_type = 227 int blend_type =
219 pGeneralState ? pGeneralState->m_BlendType : FXDIB_BLEND_NORMAL; 228 pGeneralState ? pGeneralState->m_BlendType : FXDIB_BLEND_NORMAL;
220 if (blend_type != FXDIB_BLEND_NORMAL) 229 if (blend_type != FXDIB_BLEND_NORMAL)
221 return TRUE; 230 return TRUE;
222 231
223 CPDF_Dictionary* pSMaskDict = 232 CPDF_Dictionary* pSMaskDict =
224 pGeneralState ? ToDictionary(pGeneralState->m_pSoftMask) : nullptr; 233 pGeneralState ? ToDictionary(pGeneralState->m_pSoftMask) : nullptr;
225 if (pSMaskDict) 234 if (pSMaskDict)
226 return TRUE; 235 return TRUE;
227 236
228 if (pGeneralState && pGeneralState->m_FillAlpha != 1.0f) 237 if (pGeneralState && pGeneralState->m_FillAlpha != 1.0f)
229 return TRUE; 238 return TRUE;
230 239
231 if (pPageObj->IsPath()) { 240 if (pPageObj->IsPath() && pGeneralState &&
232 if (pGeneralState && pGeneralState->m_StrokeAlpha != 1.0f) 241 pGeneralState->m_StrokeAlpha != 1.0f) {
233 return TRUE; 242 return TRUE;
234 } 243 }
235 244
236 if (pPageObj->IsForm()) { 245 if (pPageObj->IsForm()) {
237 CPDF_FormObject* pFormObj = pPageObj->AsForm(); 246 const CPDF_Form* pForm = pPageObj->AsForm()->form();
238 if (pFormObj->m_pForm && 247 if (pForm) {
239 (pFormObj->m_pForm->m_Transparency & PDFTRANS_ISOLATED)) 248 int trans = pForm->m_Transparency;
240 return TRUE; 249 if ((trans & PDFTRANS_ISOLATED) || (trans & PDFTRANS_GROUP))
241 if (pFormObj->m_pForm && 250 return TRUE;
242 (!(pFormObj->m_pForm->m_Transparency & PDFTRANS_ISOLATED) && 251 }
243 (pFormObj->m_pForm->m_Transparency & PDFTRANS_GROUP)))
244 return TRUE;
245 } 252 }
253
246 return FALSE; 254 return FALSE;
247 } 255 }
248 256
249 DLLEXPORT FPDF_BOOL STDCALL FPDFPage_GenerateContent(FPDF_PAGE page) { 257 DLLEXPORT FPDF_BOOL STDCALL FPDFPage_GenerateContent(FPDF_PAGE page) {
250 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); 258 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
251 if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") || 259 if (!IsPageObject(pPage))
252 !pPage->m_pFormDict->GetObjectBy("Type")->GetDirect() ||
253 pPage->m_pFormDict->GetObjectBy("Type")->GetDirect()->GetString().Compare(
254 "Page")) {
255 return FALSE; 260 return FALSE;
256 } 261
257 CPDF_PageContentGenerator CG(pPage); 262 CPDF_PageContentGenerator CG(pPage);
258 CG.GenerateContent(); 263 CG.GenerateContent();
259
260 return TRUE; 264 return TRUE;
261 } 265 }
262 266
263 DLLEXPORT void STDCALL FPDFPageObj_Transform(FPDF_PAGEOBJECT page_object, 267 DLLEXPORT void STDCALL FPDFPageObj_Transform(FPDF_PAGEOBJECT page_object,
264 double a, 268 double a,
265 double b, 269 double b,
266 double c, 270 double c,
267 double d, 271 double d,
268 double e, 272 double e,
269 double f) { 273 double f) {
270 CPDF_PageObject* pPageObj = (CPDF_PageObject*)page_object; 274 CPDF_PageObject* pPageObj = reinterpret_cast<CPDF_PageObject*>(page_object);
271 if (!pPageObj) 275 if (!pPageObj)
272 return; 276 return;
273 277
274 CFX_Matrix matrix((FX_FLOAT)a, (FX_FLOAT)b, (FX_FLOAT)c, (FX_FLOAT)d, 278 CFX_Matrix matrix((FX_FLOAT)a, (FX_FLOAT)b, (FX_FLOAT)c, (FX_FLOAT)d,
275 (FX_FLOAT)e, (FX_FLOAT)f); 279 (FX_FLOAT)e, (FX_FLOAT)f);
276 pPageObj->Transform(matrix); 280 pPageObj->Transform(matrix);
277 } 281 }
282
278 DLLEXPORT void STDCALL FPDFPage_TransformAnnots(FPDF_PAGE page, 283 DLLEXPORT void STDCALL FPDFPage_TransformAnnots(FPDF_PAGE page,
279 double a, 284 double a,
280 double b, 285 double b,
281 double c, 286 double c,
282 double d, 287 double d,
283 double e, 288 double e,
284 double f) { 289 double f) {
285 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); 290 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
286 if (!pPage) 291 if (!pPage)
287 return; 292 return;
293
288 CPDF_AnnotList AnnotList(pPage); 294 CPDF_AnnotList AnnotList(pPage);
289 for (size_t i = 0; i < AnnotList.Count(); ++i) { 295 for (size_t i = 0; i < AnnotList.Count(); ++i) {
290 CPDF_Annot* pAnnot = AnnotList.GetAt(i); 296 CPDF_Annot* pAnnot = AnnotList.GetAt(i);
291 // transformAnnots Rectangle 297 // transformAnnots Rectangle
292 CFX_FloatRect rect; 298 CFX_FloatRect rect;
293 pAnnot->GetRect(rect); 299 pAnnot->GetRect(rect);
294 CFX_Matrix matrix((FX_FLOAT)a, (FX_FLOAT)b, (FX_FLOAT)c, (FX_FLOAT)d, 300 CFX_Matrix matrix((FX_FLOAT)a, (FX_FLOAT)b, (FX_FLOAT)c, (FX_FLOAT)d,
295 (FX_FLOAT)e, (FX_FLOAT)f); 301 (FX_FLOAT)e, (FX_FLOAT)f);
296 rect.Transform(&matrix); 302 rect.Transform(&matrix);
297 CPDF_Array* pRectArray = pAnnot->GetAnnotDict()->GetArrayBy("Rect"); 303 CPDF_Array* pRectArray = pAnnot->GetAnnotDict()->GetArrayBy("Rect");
298 if (!pRectArray) 304 if (!pRectArray)
299 pRectArray = new CPDF_Array; 305 pRectArray = new CPDF_Array;
300 pRectArray->SetAt(0, new CPDF_Number(rect.left)); 306 pRectArray->SetAt(0, new CPDF_Number(rect.left));
301 pRectArray->SetAt(1, new CPDF_Number(rect.bottom)); 307 pRectArray->SetAt(1, new CPDF_Number(rect.bottom));
302 pRectArray->SetAt(2, new CPDF_Number(rect.right)); 308 pRectArray->SetAt(2, new CPDF_Number(rect.right));
303 pRectArray->SetAt(3, new CPDF_Number(rect.top)); 309 pRectArray->SetAt(3, new CPDF_Number(rect.top));
304 pAnnot->GetAnnotDict()->SetAt("Rect", pRectArray); 310 pAnnot->GetAnnotDict()->SetAt("Rect", pRectArray);
305 311
306 // Transform AP's rectangle 312 // Transform AP's rectangle
307 // To Do 313 // To Do
308 } 314 }
309 } 315 }
310 316
311 DLLEXPORT void STDCALL FPDFPage_SetRotation(FPDF_PAGE page, int rotate) { 317 DLLEXPORT void STDCALL FPDFPage_SetRotation(FPDF_PAGE page, int rotate) {
312 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); 318 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
313 if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") || 319 if (!IsPageObject(pPage))
314 !pPage->m_pFormDict->GetObjectBy("Type")->GetDirect() ||
315 pPage->m_pFormDict->GetObjectBy("Type")->GetDirect()->GetString().Compare(
316 "Page")) {
317 return; 320 return;
318 } 321
319 CPDF_Dictionary* pDict = pPage->m_pFormDict; 322 CPDF_Dictionary* pDict = pPage->m_pFormDict;
320 rotate %= 4; 323 rotate %= 4;
321
322 pDict->SetAt("Rotate", new CPDF_Number(rotate * 90)); 324 pDict->SetAt("Rotate", new CPDF_Number(rotate * 90));
323 } 325 }
OLDNEW
« fpdfsdk/fpdfeditimg.cpp ('K') | « fpdfsdk/fpdfeditimg.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698