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

Side by Side Diff: fpdfsdk/fpdf_transformpage.cpp

Issue 2347993002: Clean up CPDF_Stream. (Closed)
Patch Set: ctor Created 4 years, 3 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
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 8
9 #include "core/fpdfapi/fpdf_page/include/cpdf_clippath.h" 9 #include "core/fpdfapi/fpdf_page/include/cpdf_clippath.h"
10 #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" 10 #include "core/fpdfapi/fpdf_page/include/cpdf_page.h"
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 CPDF_Dictionary* pPageDic = pPage->m_pFormDict; 120 CPDF_Dictionary* pPageDic = pPage->m_pFormDict;
121 CPDF_Object* pContentObj = 121 CPDF_Object* pContentObj =
122 pPageDic ? pPageDic->GetObjectFor("Contents") : nullptr; 122 pPageDic ? pPageDic->GetObjectFor("Contents") : nullptr;
123 if (!pContentObj) 123 if (!pContentObj)
124 pContentObj = pPageDic ? pPageDic->GetArrayFor("Contents") : nullptr; 124 pContentObj = pPageDic ? pPageDic->GetArrayFor("Contents") : nullptr;
125 if (!pContentObj) 125 if (!pContentObj)
126 return FALSE; 126 return FALSE;
127 127
128 CPDF_Dictionary* pDic = new CPDF_Dictionary; 128 CPDF_Dictionary* pDic = new CPDF_Dictionary;
129 CPDF_Stream* pStream = new CPDF_Stream(nullptr, 0, pDic); 129 CPDF_Stream* pStream = new CPDF_Stream(nullptr, 0, pDic);
130 pStream->SetData(textBuf.GetBuffer(), textBuf.GetSize(), FALSE, FALSE); 130 pStream->SetData(textBuf.GetBuffer(), textBuf.GetSize());
131 CPDF_Document* pDoc = pPage->m_pDocument; 131 CPDF_Document* pDoc = pPage->m_pDocument;
132 if (!pDoc) 132 if (!pDoc)
133 return FALSE; 133 return FALSE;
134 pDoc->AddIndirectObject(pStream); 134 pDoc->AddIndirectObject(pStream);
135 135
136 pDic = new CPDF_Dictionary; 136 pDic = new CPDF_Dictionary;
137 CPDF_Stream* pEndStream = new CPDF_Stream(nullptr, 0, pDic); 137 CPDF_Stream* pEndStream = new CPDF_Stream(nullptr, 0, pDic);
138 pEndStream->SetData((const uint8_t*)" Q", 2, FALSE, FALSE); 138 pEndStream->SetData((const uint8_t*)" Q", 2);
139 pDoc->AddIndirectObject(pEndStream); 139 pDoc->AddIndirectObject(pEndStream);
140 140
141 CPDF_Array* pContentArray = nullptr; 141 CPDF_Array* pContentArray = nullptr;
142 CPDF_Array* pArray = ToArray(pContentObj); 142 CPDF_Array* pArray = ToArray(pContentObj);
143 if (pArray) { 143 if (pArray) {
144 pContentArray = pArray; 144 pContentArray = pArray;
145 CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum()); 145 CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum());
146 pContentArray->InsertAt(0, pRef); 146 pContentArray->InsertAt(0, pRef);
147 pContentArray->AddReference(pDoc, pEndStream); 147 pContentArray->AddReference(pDoc, pEndStream);
148 } else if (CPDF_Reference* pReference = ToReference(pContentObj)) { 148 } else if (CPDF_Reference* pReference = ToReference(pContentObj)) {
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 } else { 295 } else {
296 OutputPath(strClip, path); 296 OutputPath(strClip, path);
297 if (iClipType == FXFILL_WINDING) 297 if (iClipType == FXFILL_WINDING)
298 strClip << "W n\n"; 298 strClip << "W n\n";
299 else 299 else
300 strClip << "W* n\n"; 300 strClip << "W* n\n";
301 } 301 }
302 } 302 }
303 CPDF_Dictionary* pDic = new CPDF_Dictionary; 303 CPDF_Dictionary* pDic = new CPDF_Dictionary;
304 CPDF_Stream* pStream = new CPDF_Stream(nullptr, 0, pDic); 304 CPDF_Stream* pStream = new CPDF_Stream(nullptr, 0, pDic);
305 pStream->SetData(strClip.GetBuffer(), strClip.GetSize(), FALSE, FALSE); 305 pStream->SetData(strClip.GetBuffer(), strClip.GetSize());
306 CPDF_Document* pDoc = pPage->m_pDocument; 306 CPDF_Document* pDoc = pPage->m_pDocument;
307 if (!pDoc) 307 if (!pDoc)
308 return; 308 return;
309 pDoc->AddIndirectObject(pStream); 309 pDoc->AddIndirectObject(pStream);
310 310
311 CPDF_Array* pContentArray = nullptr; 311 CPDF_Array* pContentArray = nullptr;
312 CPDF_Array* pArray = ToArray(pContentObj); 312 CPDF_Array* pArray = ToArray(pContentObj);
313 if (pArray) { 313 if (pArray) {
314 pContentArray = pArray; 314 pContentArray = pArray;
315 CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum()); 315 CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum());
316 pContentArray->InsertAt(0, pRef); 316 pContentArray->InsertAt(0, pRef);
317 } else if (CPDF_Reference* pReference = ToReference(pContentObj)) { 317 } else if (CPDF_Reference* pReference = ToReference(pContentObj)) {
318 CPDF_Object* pDirectObj = pReference->GetDirect(); 318 CPDF_Object* pDirectObj = pReference->GetDirect();
319 if (pDirectObj) { 319 if (pDirectObj) {
320 CPDF_Array* pObjArray = pDirectObj->AsArray(); 320 CPDF_Array* pObjArray = pDirectObj->AsArray();
321 if (pObjArray) { 321 if (pObjArray) {
322 pContentArray = pObjArray; 322 pContentArray = pObjArray;
323 CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum()); 323 CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum());
324 pContentArray->InsertAt(0, pRef); 324 pContentArray->InsertAt(0, pRef);
325 } else if (pDirectObj->IsStream()) { 325 } else if (pDirectObj->IsStream()) {
326 pContentArray = new CPDF_Array(); 326 pContentArray = new CPDF_Array();
327 pContentArray->AddReference(pDoc, pStream->GetObjNum()); 327 pContentArray->AddReference(pDoc, pStream->GetObjNum());
328 pContentArray->AddReference(pDoc, pDirectObj->GetObjNum()); 328 pContentArray->AddReference(pDoc, pDirectObj->GetObjNum());
329 pPageDic->SetReferenceFor("Contents", pDoc, 329 pPageDic->SetReferenceFor("Contents", pDoc,
330 pDoc->AddIndirectObject(pContentArray)); 330 pDoc->AddIndirectObject(pContentArray));
331 } 331 }
332 } 332 }
333 } 333 }
334 } 334 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698