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

Side by Side Diff: fpdfsdk/fpdf_flatten.cpp

Issue 2345063002: Use string pools in some dictionaries (Closed)
Patch Set: Remove default 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_flatten.h" 7 #include "public/fpdf_flatten.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 CPDF_Document* pDocument) { 187 CPDF_Document* pDocument) {
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(pDocument));
198 pPage->SetReferenceFor("Contents", pDocument, 198 pPage->SetReferenceFor("Contents", pDocument,
199 pDocument->AddIndirectObject(pNewContents)); 199 pDocument->AddIndirectObject(pNewContents));
200 200
201 CFX_ByteString sStream; 201 CFX_ByteString sStream;
202 sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str()); 202 sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str());
203 pNewContents->SetData(sStream.raw_str(), sStream.GetLength(), FALSE, 203 pNewContents->SetData(sStream.raw_str(), sStream.GetLength(), FALSE,
204 FALSE); 204 FALSE);
205 } 205 }
206 return; 206 return;
207 } 207 }
208 208
209 CPDF_Array* pContentsArray = nullptr; 209 CPDF_Array* pContentsArray = nullptr;
210
211 switch (pContentsObj->GetType()) { 210 switch (pContentsObj->GetType()) {
212 case CPDF_Object::STREAM: { 211 case CPDF_Object::STREAM: {
213 pContentsArray = new CPDF_Array; 212 pContentsArray = new CPDF_Array;
214 CPDF_Stream* pContents = pContentsObj->AsStream(); 213 CPDF_Stream* pContents = pContentsObj->AsStream();
215 uint32_t dwObjNum = pDocument->AddIndirectObject(pContents); 214 uint32_t dwObjNum = pDocument->AddIndirectObject(pContents);
216 CPDF_StreamAcc acc; 215 CPDF_StreamAcc acc;
217 acc.LoadAllData(pContents); 216 acc.LoadAllData(pContents);
218 CFX_ByteString sStream = "q\n"; 217 CFX_ByteString sStream = "q\n";
219 CFX_ByteString sBody = 218 CFX_ByteString sBody =
220 CFX_ByteString((const FX_CHAR*)acc.GetData(), acc.GetSize()); 219 CFX_ByteString((const FX_CHAR*)acc.GetData(), acc.GetSize());
(...skipping 12 matching lines...) Expand all
233 } 232 }
234 233
235 if (!pContentsArray) 234 if (!pContentsArray)
236 return; 235 return;
237 236
238 uint32_t dwObjNum = pDocument->AddIndirectObject(pContentsArray); 237 uint32_t dwObjNum = pDocument->AddIndirectObject(pContentsArray);
239 pPage->SetReferenceFor("Contents", pDocument, dwObjNum); 238 pPage->SetReferenceFor("Contents", pDocument, dwObjNum);
240 239
241 if (!key.IsEmpty()) { 240 if (!key.IsEmpty()) {
242 CPDF_Stream* pNewContents = 241 CPDF_Stream* pNewContents =
243 new CPDF_Stream(nullptr, 0, new CPDF_Dictionary); 242 new CPDF_Stream(nullptr, 0, new CPDF_Dictionary(pDocument));
244 dwObjNum = pDocument->AddIndirectObject(pNewContents); 243 dwObjNum = pDocument->AddIndirectObject(pNewContents);
245 pContentsArray->AddReference(pDocument, dwObjNum); 244 pContentsArray->AddReference(pDocument, dwObjNum);
246 245
247 CFX_ByteString sStream; 246 CFX_ByteString sStream;
248 sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str()); 247 sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str());
249 pNewContents->SetData(sStream.raw_str(), sStream.GetLength(), FALSE, FALSE); 248 pNewContents->SetData(sStream.raw_str(), sStream.GetLength(), FALSE, FALSE);
250 } 249 }
251 } 250 }
252 251
253 CFX_Matrix GetMatrix(CFX_FloatRect rcAnnot, 252 CFX_Matrix GetMatrix(CFX_FloatRect rcAnnot,
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 CPDF_Array* pCropBox = new CPDF_Array(); 365 CPDF_Array* pCropBox = new CPDF_Array();
367 pCropBox->Add(new CPDF_Number(rcOriginalCB.left)); 366 pCropBox->Add(new CPDF_Number(rcOriginalCB.left));
368 pCropBox->Add(new CPDF_Number(rcOriginalCB.bottom)); 367 pCropBox->Add(new CPDF_Number(rcOriginalCB.bottom));
369 pCropBox->Add(new CPDF_Number(rcOriginalCB.right)); 368 pCropBox->Add(new CPDF_Number(rcOriginalCB.right));
370 pCropBox->Add(new CPDF_Number(rcOriginalCB.top)); 369 pCropBox->Add(new CPDF_Number(rcOriginalCB.top));
371 pPageDict->SetFor("ArtBox", pCropBox); 370 pPageDict->SetFor("ArtBox", pCropBox);
372 } 371 }
373 372
374 CPDF_Dictionary* pRes = pPageDict->GetDictFor("Resources"); 373 CPDF_Dictionary* pRes = pPageDict->GetDictFor("Resources");
375 if (!pRes) { 374 if (!pRes) {
376 pRes = new CPDF_Dictionary; 375 pRes = new CPDF_Dictionary(pDocument);
dsinclair 2016/09/19 13:24:34 Reading through these, I think see pRes = new
Tom Sepez 2016/09/19 18:24:59 Done.
377 pPageDict->SetFor("Resources", pRes); 376 pPageDict->SetFor("Resources", pRes);
378 } 377 }
379 378
380 CPDF_Stream* pNewXObject = new CPDF_Stream(nullptr, 0, new CPDF_Dictionary); 379 CPDF_Stream* pNewXObject =
380 new CPDF_Stream(nullptr, 0, new CPDF_Dictionary(pDocument));
381
381 uint32_t dwObjNum = pDocument->AddIndirectObject(pNewXObject); 382 uint32_t dwObjNum = pDocument->AddIndirectObject(pNewXObject);
382 CPDF_Dictionary* pPageXObject = pRes->GetDictFor("XObject"); 383 CPDF_Dictionary* pPageXObject = pRes->GetDictFor("XObject");
383 if (!pPageXObject) { 384 if (!pPageXObject) {
384 pPageXObject = new CPDF_Dictionary; 385 pPageXObject = new CPDF_Dictionary(pDocument);
385 pRes->SetFor("XObject", pPageXObject); 386 pRes->SetFor("XObject", pPageXObject);
386 } 387 }
387 388
388 CFX_ByteString key = ""; 389 CFX_ByteString key = "";
389 int nStreams = ObjectArray.GetSize(); 390 int nStreams = ObjectArray.GetSize();
390 391
391 if (nStreams > 0) { 392 if (nStreams > 0) {
392 for (int iKey = 0; /*iKey < 100*/; iKey++) { 393 for (int iKey = 0; /*iKey < 100*/; iKey++) {
393 char sExtend[5] = {}; 394 char sExtend[5] = {};
394 FXSYS_itoa(iKey, sExtend, 10); 395 FXSYS_itoa(iKey, sExtend, 10);
395 key = CFX_ByteString("FFT") + CFX_ByteString(sExtend); 396 key = CFX_ByteString("FFT") + CFX_ByteString(sExtend);
396 if (!pPageXObject->KeyExist(key)) 397 if (!pPageXObject->KeyExist(key))
397 break; 398 break;
398 } 399 }
399 } 400 }
400 401
401 SetPageContents(key, pPageDict, pDocument); 402 SetPageContents(key, pPageDict, pDocument);
402 403
403 CPDF_Dictionary* pNewXORes = nullptr; 404 CPDF_Dictionary* pNewXORes = nullptr;
404 405
405 if (!key.IsEmpty()) { 406 if (!key.IsEmpty()) {
406 pPageXObject->SetReferenceFor(key, pDocument, dwObjNum); 407 pPageXObject->SetReferenceFor(key, pDocument, dwObjNum);
407 CPDF_Dictionary* pNewOXbjectDic = pNewXObject->GetDict(); 408 CPDF_Dictionary* pNewOXbjectDic = pNewXObject->GetDict();
408 pNewXORes = new CPDF_Dictionary; 409 pNewXORes = new CPDF_Dictionary(pDocument);
409 pNewOXbjectDic->SetFor("Resources", pNewXORes); 410 pNewOXbjectDic->SetFor("Resources", pNewXORes);
410 pNewOXbjectDic->SetNameFor("Type", "XObject"); 411 pNewOXbjectDic->SetNameFor("Type", "XObject");
411 pNewOXbjectDic->SetNameFor("Subtype", "Form"); 412 pNewOXbjectDic->SetNameFor("Subtype", "Form");
412 pNewOXbjectDic->SetIntegerFor("FormType", 1); 413 pNewOXbjectDic->SetIntegerFor("FormType", 1);
413 pNewOXbjectDic->SetNameFor("Name", "FRM"); 414 pNewOXbjectDic->SetNameFor("Name", "FRM");
414 CFX_FloatRect rcBBox = pPageDict->GetRectFor("ArtBox"); 415 CFX_FloatRect rcBBox = pPageDict->GetRectFor("ArtBox");
415 pNewOXbjectDic->SetRectFor("BBox", rcBBox); 416 pNewOXbjectDic->SetRectFor("BBox", rcBBox);
416 } 417 }
417 418
418 for (int i = 0; i < nStreams; i++) { 419 for (int i = 0; i < nStreams; i++) {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 if (pObj) { 471 if (pObj) {
471 CPDF_Dictionary* pObjDic = pObj->GetDict(); 472 CPDF_Dictionary* pObjDic = pObj->GetDict();
472 if (pObjDic) { 473 if (pObjDic) {
473 pObjDic->SetNameFor("Type", "XObject"); 474 pObjDic->SetNameFor("Type", "XObject");
474 pObjDic->SetNameFor("Subtype", "Form"); 475 pObjDic->SetNameFor("Subtype", "Form");
475 } 476 }
476 } 477 }
477 478
478 CPDF_Dictionary* pXObject = pNewXORes->GetDictFor("XObject"); 479 CPDF_Dictionary* pXObject = pNewXORes->GetDictFor("XObject");
479 if (!pXObject) { 480 if (!pXObject) {
480 pXObject = new CPDF_Dictionary; 481 pXObject = new CPDF_Dictionary(pDocument);
481 pNewXORes->SetFor("XObject", pXObject); 482 pNewXORes->SetFor("XObject", pXObject);
482 } 483 }
483 484
484 CFX_ByteString sFormName; 485 CFX_ByteString sFormName;
485 sFormName.Format("F%d", i); 486 sFormName.Format("F%d", i);
486 uint32_t dwStreamObjNum = pDocument->AddIndirectObject(pObj); 487 uint32_t dwStreamObjNum = pDocument->AddIndirectObject(pObj);
487 pXObject->SetReferenceFor(sFormName, pDocument, dwStreamObjNum); 488 pXObject->SetReferenceFor(sFormName, pDocument, dwStreamObjNum);
488 489
489 CPDF_StreamAcc acc; 490 CPDF_StreamAcc acc;
490 acc.LoadAllData(pNewXObject); 491 acc.LoadAllData(pNewXObject);
(...skipping 17 matching lines...) Expand all
508 sStream += sTemp; 509 sStream += sTemp;
509 pNewXObject->SetData(sStream.raw_str(), sStream.GetLength(), FALSE, FALSE); 510 pNewXObject->SetData(sStream.raw_str(), sStream.GetLength(), FALSE, FALSE);
510 } 511 }
511 pPageDict->RemoveFor("Annots"); 512 pPageDict->RemoveFor("Annots");
512 513
513 ObjectArray.RemoveAll(); 514 ObjectArray.RemoveAll();
514 RectArray.RemoveAll(); 515 RectArray.RemoveAll();
515 516
516 return FLATTEN_SUCCESS; 517 return FLATTEN_SUCCESS;
517 } 518 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698