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

Side by Side Diff: fpdfsdk/src/fpdf_transformpage.cpp

Issue 1419643005: Merge to XFA: Add type cast definitions for CPDF_Array. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Created 5 years, 1 month 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
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_transformpage.h" 7 #include "../../public/fpdf_transformpage.h"
8 #include "../include/fsdk_define.h" 8 #include "../include/fsdk_define.h"
9 9
10 namespace { 10 namespace {
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 bsClipping.Format("%f %f %f %f re W* n ", rect.left, rect.bottom, 102 bsClipping.Format("%f %f %f %f re W* n ", rect.left, rect.bottom,
103 rect.Width(), rect.Height()); 103 rect.Width(), rect.Height());
104 textBuf << bsClipping; 104 textBuf << bsClipping;
105 105
106 CFX_ByteString bsMatix; 106 CFX_ByteString bsMatix;
107 bsMatix.Format("%f %f %f %f %f %f cm ", matrix->a, matrix->b, matrix->c, 107 bsMatix.Format("%f %f %f %f %f %f cm ", matrix->a, matrix->b, matrix->c,
108 matrix->d, matrix->e, matrix->f); 108 matrix->d, matrix->e, matrix->f);
109 textBuf << bsMatix; 109 textBuf << bsMatix;
110 110
111 CPDF_Dictionary* pPageDic = pPage->m_pFormDict; 111 CPDF_Dictionary* pPageDic = pPage->m_pFormDict;
112 CPDF_Object* pContentObj = pPageDic ? pPageDic->GetElement("Contents") : NULL; 112 CPDF_Object* pContentObj =
113 pPageDic ? pPageDic->GetElement("Contents") : nullptr;
113 if (!pContentObj) 114 if (!pContentObj)
114 pContentObj = pPageDic ? pPageDic->GetArray("Contents") : NULL; 115 pContentObj = pPageDic ? pPageDic->GetArray("Contents") : nullptr;
115 if (!pContentObj) 116 if (!pContentObj)
116 return FALSE; 117 return FALSE;
117 118
118 CPDF_Dictionary* pDic = new CPDF_Dictionary; 119 CPDF_Dictionary* pDic = new CPDF_Dictionary;
119 CPDF_Stream* pStream = new CPDF_Stream(NULL, 0, pDic); 120 CPDF_Stream* pStream = new CPDF_Stream(nullptr, 0, pDic);
120 pStream->SetData(textBuf.GetBuffer(), textBuf.GetSize(), FALSE, FALSE); 121 pStream->SetData(textBuf.GetBuffer(), textBuf.GetSize(), FALSE, FALSE);
121 CPDF_Document* pDoc = pPage->m_pDocument; 122 CPDF_Document* pDoc = pPage->m_pDocument;
122 if (!pDoc) 123 if (!pDoc)
123 return FALSE; 124 return FALSE;
124 pDoc->AddIndirectObject(pStream); 125 pDoc->AddIndirectObject(pStream);
125 126
126 pDic = new CPDF_Dictionary; 127 pDic = new CPDF_Dictionary;
127 CPDF_Stream* pEndStream = new CPDF_Stream(NULL, 0, pDic); 128 CPDF_Stream* pEndStream = new CPDF_Stream(nullptr, 0, pDic);
128 pEndStream->SetData((const uint8_t*)" Q", 2, FALSE, FALSE); 129 pEndStream->SetData((const uint8_t*)" Q", 2, FALSE, FALSE);
129 pDoc->AddIndirectObject(pEndStream); 130 pDoc->AddIndirectObject(pEndStream);
130 131
131 CPDF_Array* pContentArray = NULL; 132 CPDF_Array* pContentArray = nullptr;
132 if (pContentObj && pContentObj->GetType() == PDFOBJ_ARRAY) { 133 if (CPDF_Array* pArray = ToArray(pContentObj)) {
133 pContentArray = (CPDF_Array*)pContentObj; 134 pContentArray = pArray;
134 CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum()); 135 CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum());
135 pContentArray->InsertAt(0, pRef); 136 pContentArray->InsertAt(0, pRef);
136 pContentArray->AddReference(pDoc, pEndStream); 137 pContentArray->AddReference(pDoc, pEndStream);
137 } else if (pContentObj && pContentObj->GetType() == PDFOBJ_REFERENCE) { 138 } else if (pContentObj && pContentObj->GetType() == PDFOBJ_REFERENCE) {
138 CPDF_Reference* pReference = (CPDF_Reference*)pContentObj; 139 CPDF_Reference* pReference = (CPDF_Reference*)pContentObj;
139 CPDF_Object* pDirectObj = pReference->GetDirect(); 140 CPDF_Object* pDirectObj = pReference->GetDirect();
140 if (pDirectObj != NULL) { 141 if (pDirectObj) {
141 if (pDirectObj->GetType() == PDFOBJ_ARRAY) { 142 if (CPDF_Array* pArray = pDirectObj->AsArray()) {
142 pContentArray = (CPDF_Array*)pDirectObj; 143 pContentArray = pArray;
143 CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum()); 144 CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum());
144 pContentArray->InsertAt(0, pRef); 145 pContentArray->InsertAt(0, pRef);
145 pContentArray->AddReference(pDoc, pEndStream); 146 pContentArray->AddReference(pDoc, pEndStream);
146 } else if (pDirectObj->GetType() == PDFOBJ_STREAM) { 147 } else if (pDirectObj->GetType() == PDFOBJ_STREAM) {
147 pContentArray = new CPDF_Array(); 148 pContentArray = new CPDF_Array();
148 pContentArray->AddReference(pDoc, pStream->GetObjNum()); 149 pContentArray->AddReference(pDoc, pStream->GetObjNum());
149 pContentArray->AddReference(pDoc, pDirectObj->GetObjNum()); 150 pContentArray->AddReference(pDoc, pDirectObj->GetObjNum());
150 pContentArray->AddReference(pDoc, pEndStream); 151 pContentArray->AddReference(pDoc, pEndStream);
151 pPageDic->SetAtReference("Contents", pDoc, 152 pPageDic->SetAtReference("Contents", pDoc,
152 pDoc->AddIndirectObject(pContentArray)); 153 pDoc->AddIndirectObject(pContentArray));
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 } 261 }
261 } 262 }
262 263
263 DLLEXPORT void STDCALL FPDFPage_InsertClipPath(FPDF_PAGE page, 264 DLLEXPORT void STDCALL FPDFPage_InsertClipPath(FPDF_PAGE page,
264 FPDF_CLIPPATH clipPath) { 265 FPDF_CLIPPATH clipPath) {
265 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); 266 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
266 if (!pPage) 267 if (!pPage)
267 return; 268 return;
268 269
269 CPDF_Dictionary* pPageDic = pPage->m_pFormDict; 270 CPDF_Dictionary* pPageDic = pPage->m_pFormDict;
270 CPDF_Object* pContentObj = pPageDic ? pPageDic->GetElement("Contents") : NULL; 271 CPDF_Object* pContentObj =
272 pPageDic ? pPageDic->GetElement("Contents") : nullptr;
271 if (!pContentObj) 273 if (!pContentObj)
272 pContentObj = pPageDic ? pPageDic->GetArray("Contents") : NULL; 274 pContentObj = pPageDic ? pPageDic->GetArray("Contents") : nullptr;
273 if (!pContentObj) 275 if (!pContentObj)
274 return; 276 return;
275 277
276 CFX_ByteTextBuf strClip; 278 CFX_ByteTextBuf strClip;
277 CPDF_ClipPath* pClipPath = (CPDF_ClipPath*)clipPath; 279 CPDF_ClipPath* pClipPath = (CPDF_ClipPath*)clipPath;
278 FX_DWORD i; 280 FX_DWORD i;
279 for (i = 0; i < pClipPath->GetPathCount(); i++) { 281 for (i = 0; i < pClipPath->GetPathCount(); i++) {
280 CPDF_Path path = pClipPath->GetPath(i); 282 CPDF_Path path = pClipPath->GetPath(i);
281 int iClipType = pClipPath->GetClipType(i); 283 int iClipType = pClipPath->GetClipType(i);
282 if (path.GetPointCount() == 0) { 284 if (path.GetPointCount() == 0) {
283 // Empty clipping (totally clipped out) 285 // Empty clipping (totally clipped out)
284 strClip << "0 0 m W n "; 286 strClip << "0 0 m W n ";
285 } else { 287 } else {
286 OutputPath(strClip, path); 288 OutputPath(strClip, path);
287 if (iClipType == FXFILL_WINDING) 289 if (iClipType == FXFILL_WINDING)
288 strClip << "W n\n"; 290 strClip << "W n\n";
289 else 291 else
290 strClip << "W* n\n"; 292 strClip << "W* n\n";
291 } 293 }
292 } 294 }
293 CPDF_Dictionary* pDic = new CPDF_Dictionary; 295 CPDF_Dictionary* pDic = new CPDF_Dictionary;
294 CPDF_Stream* pStream = new CPDF_Stream(NULL, 0, pDic); 296 CPDF_Stream* pStream = new CPDF_Stream(nullptr, 0, pDic);
295 pStream->SetData(strClip.GetBuffer(), strClip.GetSize(), FALSE, FALSE); 297 pStream->SetData(strClip.GetBuffer(), strClip.GetSize(), FALSE, FALSE);
296 CPDF_Document* pDoc = pPage->m_pDocument; 298 CPDF_Document* pDoc = pPage->m_pDocument;
297 if (!pDoc) 299 if (!pDoc)
298 return; 300 return;
299 pDoc->AddIndirectObject(pStream); 301 pDoc->AddIndirectObject(pStream);
300 302
301 CPDF_Array* pContentArray = NULL; 303 CPDF_Array* pContentArray = nullptr;
302 if (pContentObj && pContentObj->GetType() == PDFOBJ_ARRAY) { 304 if (CPDF_Array* pArray = ToArray(pContentObj)) {
303 pContentArray = (CPDF_Array*)pContentObj; 305 pContentArray = pArray;
304 CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum()); 306 CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum());
305 pContentArray->InsertAt(0, pRef); 307 pContentArray->InsertAt(0, pRef);
306 } else if (pContentObj && pContentObj->GetType() == PDFOBJ_REFERENCE) { 308 } else if (pContentObj && pContentObj->GetType() == PDFOBJ_REFERENCE) {
307 CPDF_Reference* pReference = (CPDF_Reference*)pContentObj; 309 CPDF_Reference* pReference = (CPDF_Reference*)pContentObj;
308 CPDF_Object* pDirectObj = pReference->GetDirect(); 310 CPDF_Object* pDirectObj = pReference->GetDirect();
309 if (pDirectObj != NULL) { 311 if (pDirectObj) {
310 if (pDirectObj->GetType() == PDFOBJ_ARRAY) { 312 if (CPDF_Array* pArray = pDirectObj->AsArray()) {
311 pContentArray = (CPDF_Array*)pDirectObj; 313 pContentArray = pArray;
312 CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum()); 314 CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum());
313 pContentArray->InsertAt(0, pRef); 315 pContentArray->InsertAt(0, pRef);
314 } else if (pDirectObj->GetType() == PDFOBJ_STREAM) { 316 } else if (pDirectObj->GetType() == PDFOBJ_STREAM) {
315 pContentArray = new CPDF_Array(); 317 pContentArray = new CPDF_Array();
316 pContentArray->AddReference(pDoc, pStream->GetObjNum()); 318 pContentArray->AddReference(pDoc, pStream->GetObjNum());
317 pContentArray->AddReference(pDoc, pDirectObj->GetObjNum()); 319 pContentArray->AddReference(pDoc, pDirectObj->GetObjNum());
318 pPageDic->SetAtReference("Contents", pDoc, 320 pPageDic->SetAtReference("Contents", pDoc,
319 pDoc->AddIndirectObject(pContentArray)); 321 pDoc->AddIndirectObject(pContentArray));
320 } 322 }
321 } 323 }
322 } 324 }
323 } 325 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698