OLD | NEW |
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 #include "../../public/fpdf_formfill.h" | 8 #include "../../public/fpdf_formfill.h" |
9 #include "../include/fsdk_define.h" | 9 #include "../include/fsdk_define.h" |
10 | 10 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 pPageDict->SetAt("Resources", new CPDF_Dictionary); | 78 pPageDict->SetAt("Resources", new CPDF_Dictionary); |
79 | 79 |
80 CPDF_Page* pPage = new CPDF_Page; | 80 CPDF_Page* pPage = new CPDF_Page; |
81 pPage->Load(pDoc, pPageDict); | 81 pPage->Load(pDoc, pPageDict); |
82 pPage->ParseContent(); | 82 pPage->ParseContent(); |
83 | 83 |
84 return pPage; | 84 return pPage; |
85 } | 85 } |
86 | 86 |
87 DLLEXPORT int STDCALL FPDFPage_GetRotation(FPDF_PAGE page) { | 87 DLLEXPORT int STDCALL FPDFPage_GetRotation(FPDF_PAGE page) { |
88 CPDF_Page* pPage = (CPDF_Page*)page; | 88 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
89 if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") || | 89 if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") || |
90 !pPage->m_pFormDict->GetElement("Type")->GetDirect() || | 90 !pPage->m_pFormDict->GetElement("Type")->GetDirect() || |
91 pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare( | 91 pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare( |
92 "Page")) { | 92 "Page")) { |
93 return -1; | 93 return -1; |
94 } | 94 } |
95 CPDF_Dictionary* pDict = pPage->m_pFormDict; | 95 CPDF_Dictionary* pDict = pPage->m_pFormDict; |
96 | 96 |
97 int rotate = 0; | 97 int rotate = 0; |
98 if (pDict != NULL) { | 98 if (pDict != NULL) { |
(...skipping 23 matching lines...) Expand all Loading... |
122 } | 122 } |
123 } else { | 123 } else { |
124 return -1; | 124 return -1; |
125 } | 125 } |
126 | 126 |
127 return rotate; | 127 return rotate; |
128 } | 128 } |
129 | 129 |
130 DLLEXPORT void STDCALL FPDFPage_InsertObject(FPDF_PAGE page, | 130 DLLEXPORT void STDCALL FPDFPage_InsertObject(FPDF_PAGE page, |
131 FPDF_PAGEOBJECT page_obj) { | 131 FPDF_PAGEOBJECT page_obj) { |
132 CPDF_Page* pPage = (CPDF_Page*)page; | 132 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
133 if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") || | 133 if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") || |
134 !pPage->m_pFormDict->GetElement("Type")->GetDirect() || | 134 !pPage->m_pFormDict->GetElement("Type")->GetDirect() || |
135 pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare( | 135 pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare( |
136 "Page")) { | 136 "Page")) { |
137 return; | 137 return; |
138 } | 138 } |
139 CPDF_PageObject* pPageObj = (CPDF_PageObject*)page_obj; | 139 CPDF_PageObject* pPageObj = (CPDF_PageObject*)page_obj; |
140 if (pPageObj == NULL) | 140 if (pPageObj == NULL) |
141 return; | 141 return; |
142 FX_POSITION LastPersition = pPage->GetLastObjectPosition(); | 142 FX_POSITION LastPersition = pPage->GetLastObjectPosition(); |
(...skipping 21 matching lines...) Expand all Loading... |
164 break; | 164 break; |
165 } | 165 } |
166 case FPDF_PAGEOBJ_FORM: { | 166 case FPDF_PAGEOBJ_FORM: { |
167 CPDF_FormObject* pFormObj = (CPDF_FormObject*)pPageObj; | 167 CPDF_FormObject* pFormObj = (CPDF_FormObject*)pPageObj; |
168 pFormObj->CalcBoundingBox(); | 168 pFormObj->CalcBoundingBox(); |
169 break; | 169 break; |
170 } | 170 } |
171 default: | 171 default: |
172 break; | 172 break; |
173 } | 173 } |
174 | |
175 // pPage->ParseContent(); | |
176 // pPage->GenerateContent(); | |
177 } | 174 } |
178 | 175 |
179 DLLEXPORT int STDCALL FPDFPage_CountObject(FPDF_PAGE page) { | 176 DLLEXPORT int STDCALL FPDFPage_CountObject(FPDF_PAGE page) { |
180 CPDF_Page* pPage = (CPDF_Page*)page; | 177 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
181 if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") || | 178 if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") || |
182 !pPage->m_pFormDict->GetElement("Type")->GetDirect() || | 179 !pPage->m_pFormDict->GetElement("Type")->GetDirect() || |
183 pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare( | 180 pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare( |
184 "Page")) { | 181 "Page")) { |
185 return -1; | 182 return -1; |
186 } | 183 } |
187 return pPage->CountObjects(); | 184 return pPage->CountObjects(); |
188 // return 0; | |
189 } | 185 } |
190 | 186 |
191 DLLEXPORT FPDF_PAGEOBJECT STDCALL FPDFPage_GetObject(FPDF_PAGE page, | 187 DLLEXPORT FPDF_PAGEOBJECT STDCALL FPDFPage_GetObject(FPDF_PAGE page, |
192 int index) { | 188 int index) { |
193 CPDF_Page* pPage = (CPDF_Page*)page; | 189 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
194 if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") || | 190 if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") || |
195 pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare( | 191 pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare( |
196 "Page")) { | 192 "Page")) { |
197 return NULL; | 193 return NULL; |
198 } | 194 } |
199 return pPage->GetObjectByIndex(index); | 195 return pPage->GetObjectByIndex(index); |
200 // return NULL; | |
201 } | 196 } |
202 | 197 |
203 DLLEXPORT FPDF_BOOL STDCALL FPDFPage_HasTransparency(FPDF_PAGE page) { | 198 DLLEXPORT FPDF_BOOL STDCALL FPDFPage_HasTransparency(FPDF_PAGE page) { |
204 if (!page) | 199 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
205 return FALSE; | 200 return pPage && pPage->BackgroundAlphaNeeded(); |
206 CPDF_Page* pPage = (CPDF_Page*)page; | |
207 | |
208 return pPage->BackgroundAlphaNeeded(); | |
209 } | 201 } |
210 | 202 |
211 DLLEXPORT FPDF_BOOL STDCALL | 203 DLLEXPORT FPDF_BOOL STDCALL |
212 FPDFPageObj_HasTransparency(FPDF_PAGEOBJECT pageObject) { | 204 FPDFPageObj_HasTransparency(FPDF_PAGEOBJECT pageObject) { |
213 if (!pageObject) | 205 if (!pageObject) |
214 return FALSE; | 206 return FALSE; |
215 CPDF_PageObject* pPageObj = (CPDF_PageObject*)pageObject; | 207 CPDF_PageObject* pPageObj = (CPDF_PageObject*)pageObject; |
216 | 208 |
217 const CPDF_GeneralStateData* pGeneralState = pPageObj->m_GeneralState; | 209 const CPDF_GeneralStateData* pGeneralState = pPageObj->m_GeneralState; |
218 int blend_type = | 210 int blend_type = |
(...skipping 21 matching lines...) Expand all Loading... |
240 return TRUE; | 232 return TRUE; |
241 if (pFormObj->m_pForm && | 233 if (pFormObj->m_pForm && |
242 (!(pFormObj->m_pForm->m_Transparency & PDFTRANS_ISOLATED) && | 234 (!(pFormObj->m_pForm->m_Transparency & PDFTRANS_ISOLATED) && |
243 (pFormObj->m_pForm->m_Transparency & PDFTRANS_GROUP))) | 235 (pFormObj->m_pForm->m_Transparency & PDFTRANS_GROUP))) |
244 return TRUE; | 236 return TRUE; |
245 } | 237 } |
246 return FALSE; | 238 return FALSE; |
247 } | 239 } |
248 | 240 |
249 DLLEXPORT FPDF_BOOL STDCALL FPDFPage_GenerateContent(FPDF_PAGE page) { | 241 DLLEXPORT FPDF_BOOL STDCALL FPDFPage_GenerateContent(FPDF_PAGE page) { |
250 CPDF_Page* pPage = (CPDF_Page*)page; | 242 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
251 if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") || | 243 if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") || |
252 !pPage->m_pFormDict->GetElement("Type")->GetDirect() || | 244 !pPage->m_pFormDict->GetElement("Type")->GetDirect() || |
253 pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare( | 245 pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare( |
254 "Page")) { | 246 "Page")) { |
255 return FALSE; | 247 return FALSE; |
256 } | 248 } |
257 CPDF_PageContentGenerate CG(pPage); | 249 CPDF_PageContentGenerate CG(pPage); |
258 CG.GenerateContent(); | 250 CG.GenerateContent(); |
259 | 251 |
260 return TRUE; | 252 return TRUE; |
(...skipping 14 matching lines...) Expand all Loading... |
275 (FX_FLOAT)e, (FX_FLOAT)f); | 267 (FX_FLOAT)e, (FX_FLOAT)f); |
276 pPageObj->Transform(matrix); | 268 pPageObj->Transform(matrix); |
277 } | 269 } |
278 DLLEXPORT void STDCALL FPDFPage_TransformAnnots(FPDF_PAGE page, | 270 DLLEXPORT void STDCALL FPDFPage_TransformAnnots(FPDF_PAGE page, |
279 double a, | 271 double a, |
280 double b, | 272 double b, |
281 double c, | 273 double c, |
282 double d, | 274 double d, |
283 double e, | 275 double e, |
284 double f) { | 276 double f) { |
285 if (page == NULL) | 277 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
| 278 if (!pPage) |
286 return; | 279 return; |
287 CPDF_Page* pPage = (CPDF_Page*)page; | |
288 CPDF_AnnotList AnnotList(pPage); | 280 CPDF_AnnotList AnnotList(pPage); |
289 for (int i = 0; i < AnnotList.Count(); i++) { | 281 for (int i = 0; i < AnnotList.Count(); i++) { |
290 CPDF_Annot* pAnnot = AnnotList.GetAt(i); | 282 CPDF_Annot* pAnnot = AnnotList.GetAt(i); |
291 // transformAnnots Rectangle | 283 // transformAnnots Rectangle |
292 CPDF_Rect rect; | 284 CPDF_Rect rect; |
293 pAnnot->GetRect(rect); | 285 pAnnot->GetRect(rect); |
294 CFX_AffineMatrix matrix((FX_FLOAT)a, (FX_FLOAT)b, (FX_FLOAT)c, (FX_FLOAT)d, | 286 CFX_AffineMatrix matrix((FX_FLOAT)a, (FX_FLOAT)b, (FX_FLOAT)c, (FX_FLOAT)d, |
295 (FX_FLOAT)e, (FX_FLOAT)f); | 287 (FX_FLOAT)e, (FX_FLOAT)f); |
296 rect.Transform(&matrix); | 288 rect.Transform(&matrix); |
297 CPDF_Array* pRectArray = NULL; | 289 CPDF_Array* pRectArray = NULL; |
298 pRectArray = pAnnot->GetAnnotDict()->GetArray("Rect"); | 290 pRectArray = pAnnot->GetAnnotDict()->GetArray("Rect"); |
299 if (!pRectArray) | 291 if (!pRectArray) |
300 pRectArray = CPDF_Array::Create(); | 292 pRectArray = CPDF_Array::Create(); |
301 pRectArray->SetAt(0, new CPDF_Number(rect.left)); | 293 pRectArray->SetAt(0, new CPDF_Number(rect.left)); |
302 pRectArray->SetAt(1, new CPDF_Number(rect.bottom)); | 294 pRectArray->SetAt(1, new CPDF_Number(rect.bottom)); |
303 pRectArray->SetAt(2, new CPDF_Number(rect.right)); | 295 pRectArray->SetAt(2, new CPDF_Number(rect.right)); |
304 pRectArray->SetAt(3, new CPDF_Number(rect.top)); | 296 pRectArray->SetAt(3, new CPDF_Number(rect.top)); |
305 pAnnot->GetAnnotDict()->SetAt("Rect", pRectArray); | 297 pAnnot->GetAnnotDict()->SetAt("Rect", pRectArray); |
306 | 298 |
307 // Transform AP's rectangle | 299 // Transform AP's rectangle |
308 // To Do | 300 // To Do |
309 } | 301 } |
310 } | 302 } |
311 | 303 |
312 DLLEXPORT void STDCALL FPDFPage_SetRotation(FPDF_PAGE page, int rotate) { | 304 DLLEXPORT void STDCALL FPDFPage_SetRotation(FPDF_PAGE page, int rotate) { |
313 CPDF_Page* pPage = (CPDF_Page*)page; | 305 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
314 if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") || | 306 if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") || |
315 !pPage->m_pFormDict->GetElement("Type")->GetDirect() || | 307 !pPage->m_pFormDict->GetElement("Type")->GetDirect() || |
316 pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare( | 308 pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare( |
317 "Page")) { | 309 "Page")) { |
318 return; | 310 return; |
319 } | 311 } |
320 CPDF_Dictionary* pDict = pPage->m_pFormDict; | 312 CPDF_Dictionary* pDict = pPage->m_pFormDict; |
321 rotate %= 4; | 313 rotate %= 4; |
322 | 314 |
323 pDict->SetAt("Rotate", new CPDF_Number(rotate * 90)); | 315 pDict->SetAt("Rotate", new CPDF_Number(rotate * 90)); |
324 } | 316 } |
OLD | NEW |