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

Side by Side Diff: fpdfsdk/fpdf_transformpage.cpp

Issue 2361713002: Remove some objnum locals with AddIndirectObject (Closed)
Patch Set: Same treatment for arrays 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
« no previous file with comments | « fpdfsdk/fpdf_flatten.cpp ('k') | fpdfsdk/fpdfdoc_unittest.cpp » ('j') | 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_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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
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); 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->GetObjNum());
148 } else if (CPDF_Reference* pReference = ToReference(pContentObj)) { 148 } else if (CPDF_Reference* pReference = ToReference(pContentObj)) {
149 CPDF_Object* pDirectObj = pReference->GetDirect(); 149 CPDF_Object* pDirectObj = pReference->GetDirect();
150 if (pDirectObj) { 150 if (pDirectObj) {
151 CPDF_Array* pObjArray = pDirectObj->AsArray(); 151 CPDF_Array* pObjArray = pDirectObj->AsArray();
152 if (pObjArray) { 152 if (pObjArray) {
153 pContentArray = pObjArray; 153 pContentArray = pObjArray;
154 CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum()); 154 CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum());
155 pContentArray->InsertAt(0, pRef); 155 pContentArray->InsertAt(0, pRef);
156 pContentArray->AddReference(pDoc, pEndStream); 156 pContentArray->AddReference(pDoc, pEndStream->GetObjNum());
157 } else if (pDirectObj->IsStream()) { 157 } else if (pDirectObj->IsStream()) {
158 pContentArray = new CPDF_Array(); 158 pContentArray = new CPDF_Array();
159 pContentArray->AddReference(pDoc, pStream->GetObjNum()); 159 pContentArray->AddReference(pDoc, pStream->GetObjNum());
160 pContentArray->AddReference(pDoc, pDirectObj->GetObjNum()); 160 pContentArray->AddReference(pDoc, pDirectObj->GetObjNum());
161 pContentArray->AddReference(pDoc, pEndStream); 161 pContentArray->AddReference(pDoc, pEndStream->GetObjNum());
162 pPageDic->SetReferenceFor("Contents", pDoc, 162 pPageDic->SetReferenceFor("Contents", pDoc,
163 pDoc->AddIndirectObject(pContentArray)); 163 pDoc->AddIndirectObject(pContentArray));
164 } 164 }
165 } 165 }
166 } 166 }
167 167
168 // Need to transform the patterns as well. 168 // Need to transform the patterns as well.
169 CPDF_Dictionary* pRes = pPageDic->GetDictFor("Resources"); 169 CPDF_Dictionary* pRes = pPageDic->GetDictFor("Resources");
170 if (pRes) { 170 if (pRes) {
171 CPDF_Dictionary* pPattenDict = pRes->GetDictFor("Pattern"); 171 CPDF_Dictionary* pPattenDict = pRes->GetDictFor("Pattern");
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
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()); 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
309 pDoc->AddIndirectObject(pStream); 310 pDoc->AddIndirectObject(pStream);
310 311
311 CPDF_Array* pContentArray = nullptr; 312 CPDF_Array* pContentArray = nullptr;
312 CPDF_Array* pArray = ToArray(pContentObj); 313 CPDF_Array* pArray = ToArray(pContentObj);
313 if (pArray) { 314 if (pArray) {
314 pContentArray = pArray; 315 pContentArray = pArray;
315 CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum()); 316 CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum());
316 pContentArray->InsertAt(0, pRef); 317 pContentArray->InsertAt(0, pRef);
317 } else if (CPDF_Reference* pReference = ToReference(pContentObj)) { 318 } else if (CPDF_Reference* pReference = ToReference(pContentObj)) {
318 CPDF_Object* pDirectObj = pReference->GetDirect(); 319 CPDF_Object* pDirectObj = pReference->GetDirect();
319 if (pDirectObj) { 320 if (pDirectObj) {
320 CPDF_Array* pObjArray = pDirectObj->AsArray(); 321 CPDF_Array* pObjArray = pDirectObj->AsArray();
321 if (pObjArray) { 322 if (pObjArray) {
322 pContentArray = pObjArray; 323 pContentArray = pObjArray;
323 CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum()); 324 CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum());
324 pContentArray->InsertAt(0, pRef); 325 pContentArray->InsertAt(0, pRef);
325 } else if (pDirectObj->IsStream()) { 326 } else if (pDirectObj->IsStream()) {
326 pContentArray = new CPDF_Array(); 327 pContentArray = new CPDF_Array();
327 pContentArray->AddReference(pDoc, pStream->GetObjNum()); 328 pContentArray->AddReference(pDoc, pStream->GetObjNum());
328 pContentArray->AddReference(pDoc, pDirectObj->GetObjNum()); 329 pContentArray->AddReference(pDoc, pDirectObj->GetObjNum());
329 pPageDic->SetReferenceFor("Contents", pDoc, 330 pPageDic->SetReferenceFor("Contents", pDoc,
330 pDoc->AddIndirectObject(pContentArray)); 331 pDoc->AddIndirectObject(pContentArray));
331 } 332 }
332 } 333 }
333 } 334 }
334 } 335 }
OLDNEW
« no previous file with comments | « fpdfsdk/fpdf_flatten.cpp ('k') | fpdfsdk/fpdfdoc_unittest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698