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

Side by Side Diff: fpdfsdk/fpdf_flatten.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/formfiller/cba_fontmap.cpp ('k') | fpdfsdk/fpdf_transformpage.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_flatten.h" 7 #include "public/fpdf_flatten.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 CPDF_Object* pContentsObj = pPage->GetStreamFor("Contents"); 188 CPDF_Object* pContentsObj = pPage->GetStreamFor("Contents");
189 if (!pContentsObj) { 189 if (!pContentsObj) {
190 pContentsObj = pPage->GetArrayFor("Contents"); 190 pContentsObj = pPage->GetArrayFor("Contents");
191 } 191 }
192 192
193 if (!pContentsObj) { 193 if (!pContentsObj) {
194 // Create a new contents dictionary 194 // Create a new contents dictionary
195 if (!key.IsEmpty()) { 195 if (!key.IsEmpty()) {
196 CPDF_Stream* pNewContents = 196 CPDF_Stream* pNewContents =
197 new CPDF_Stream(nullptr, 0, new CPDF_Dictionary); 197 new CPDF_Stream(nullptr, 0, new CPDF_Dictionary);
198 pPage->SetReferenceFor("Contents", pDocument,
199 pDocument->AddIndirectObject(pNewContents));
200
201 CFX_ByteString sStream; 198 CFX_ByteString sStream;
202 sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str()); 199 sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str());
203 pNewContents->SetData(sStream.raw_str(), sStream.GetLength()); 200 pNewContents->SetData(sStream.raw_str(), sStream.GetLength());
201 pPage->SetReferenceFor("Contents", pDocument,
202 pDocument->AddIndirectObject(pNewContents));
204 } 203 }
205 return; 204 return;
206 } 205 }
207 206
208 CPDF_Array* pContentsArray = nullptr; 207 CPDF_Array* pContentsArray = nullptr;
209 208
210 switch (pContentsObj->GetType()) { 209 switch (pContentsObj->GetType()) {
211 case CPDF_Object::STREAM: { 210 case CPDF_Object::STREAM: {
212 pContentsArray = new CPDF_Array; 211 pContentsArray = new CPDF_Array;
213 CPDF_Stream* pContents = pContentsObj->AsStream(); 212 CPDF_Stream* pContents = pContentsObj->AsStream();
(...skipping 13 matching lines...) Expand all
227 pContentsArray = pContentsObj->AsArray(); 226 pContentsArray = pContentsObj->AsArray();
228 break; 227 break;
229 } 228 }
230 default: 229 default:
231 break; 230 break;
232 } 231 }
233 232
234 if (!pContentsArray) 233 if (!pContentsArray)
235 return; 234 return;
236 235
237 uint32_t dwObjNum = pDocument->AddIndirectObject(pContentsArray); 236 pPage->SetReferenceFor("Contents", pDocument,
238 pPage->SetReferenceFor("Contents", pDocument, dwObjNum); 237 pDocument->AddIndirectObject(pContentsArray));
239 238
240 if (!key.IsEmpty()) { 239 if (!key.IsEmpty()) {
241 CPDF_Stream* pNewContents = 240 CPDF_Stream* pNewContents =
242 new CPDF_Stream(nullptr, 0, new CPDF_Dictionary); 241 new CPDF_Stream(nullptr, 0, new CPDF_Dictionary);
243 dwObjNum = pDocument->AddIndirectObject(pNewContents);
244 pContentsArray->AddReference(pDocument, dwObjNum);
245
246 CFX_ByteString sStream; 242 CFX_ByteString sStream;
247 sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str()); 243 sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str());
248 pNewContents->SetData(sStream.raw_str(), sStream.GetLength()); 244 pNewContents->SetData(sStream.raw_str(), sStream.GetLength());
245 pContentsArray->AddReference(pDocument,
246 pDocument->AddIndirectObject(pNewContents));
249 } 247 }
250 } 248 }
251 249
252 CFX_Matrix GetMatrix(CFX_FloatRect rcAnnot, 250 CFX_Matrix GetMatrix(CFX_FloatRect rcAnnot,
253 CFX_FloatRect rcStream, 251 CFX_FloatRect rcStream,
254 const CFX_Matrix& matrix) { 252 const CFX_Matrix& matrix) {
255 if (rcStream.IsEmpty()) 253 if (rcStream.IsEmpty())
256 return CFX_Matrix(); 254 return CFX_Matrix();
257 255
258 matrix.TransformRect(rcStream); 256 matrix.TransformRect(rcStream);
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 } 473 }
476 474
477 CPDF_Dictionary* pXObject = pNewXORes->GetDictFor("XObject"); 475 CPDF_Dictionary* pXObject = pNewXORes->GetDictFor("XObject");
478 if (!pXObject) { 476 if (!pXObject) {
479 pXObject = new CPDF_Dictionary; 477 pXObject = new CPDF_Dictionary;
480 pNewXORes->SetFor("XObject", pXObject); 478 pNewXORes->SetFor("XObject", pXObject);
481 } 479 }
482 480
483 CFX_ByteString sFormName; 481 CFX_ByteString sFormName;
484 sFormName.Format("F%d", i); 482 sFormName.Format("F%d", i);
485 uint32_t dwStreamObjNum = pDocument->AddIndirectObject(pObj); 483 pXObject->SetReferenceFor(sFormName, pDocument,
486 pXObject->SetReferenceFor(sFormName, pDocument, dwStreamObjNum); 484 pDocument->AddIndirectObject(pObj));
487 485
488 CPDF_StreamAcc acc; 486 CPDF_StreamAcc acc;
489 acc.LoadAllData(pNewXObject); 487 acc.LoadAllData(pNewXObject);
490 488
491 const uint8_t* pData = acc.GetData(); 489 const uint8_t* pData = acc.GetData();
492 CFX_ByteString sStream(pData, acc.GetSize()); 490 CFX_ByteString sStream(pData, acc.GetSize());
493 CFX_ByteString sTemp;
494 491
495 if (matrix.IsIdentity()) { 492 if (matrix.IsIdentity()) {
496 matrix.a = 1.0f; 493 matrix.a = 1.0f;
497 matrix.b = 0.0f; 494 matrix.b = 0.0f;
498 matrix.c = 0.0f; 495 matrix.c = 0.0f;
499 matrix.d = 1.0f; 496 matrix.d = 1.0f;
500 matrix.e = 0.0f; 497 matrix.e = 0.0f;
501 matrix.f = 0.0f; 498 matrix.f = 0.0f;
502 } 499 }
503 500
501 CFX_ByteString sTemp;
504 CFX_Matrix m = GetMatrix(rcAnnot, rcStream, matrix); 502 CFX_Matrix m = GetMatrix(rcAnnot, rcStream, matrix);
505 sTemp.Format("q %f 0 0 %f %f %f cm /%s Do Q\n", m.a, m.d, m.e, m.f, 503 sTemp.Format("q %f 0 0 %f %f %f cm /%s Do Q\n", m.a, m.d, m.e, m.f,
506 sFormName.c_str()); 504 sFormName.c_str());
507 sStream += sTemp; 505 sStream += sTemp;
508 pNewXObject->SetData(sStream.raw_str(), sStream.GetLength()); 506 pNewXObject->SetData(sStream.raw_str(), sStream.GetLength());
509 } 507 }
510 pPageDict->RemoveFor("Annots"); 508 pPageDict->RemoveFor("Annots");
511 509
512 ObjectArray.RemoveAll(); 510 ObjectArray.RemoveAll();
513 RectArray.RemoveAll(); 511 RectArray.RemoveAll();
514 512
515 return FLATTEN_SUCCESS; 513 return FLATTEN_SUCCESS;
516 } 514 }
OLDNEW
« no previous file with comments | « fpdfsdk/formfiller/cba_fontmap.cpp ('k') | fpdfsdk/fpdf_transformpage.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698