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

Side by Side Diff: fpdfsdk/fpdf_flatten.cpp

Issue 2345063002: Use string pools in some dictionaries (Closed)
Patch Set: windows compilation 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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 CPDF_Dictionary* pPage, 186 CPDF_Dictionary* pPage,
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 = new CPDF_Stream(
197 new CPDF_Stream(nullptr, 0, new CPDF_Dictionary); 197 nullptr, 0, new CPDF_Dictionary(pDocument->GetByteStringPool()));
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()); 203 pNewContents->SetData(sStream.raw_str(), sStream.GetLength());
204 } 204 }
205 return; 205 return;
206 } 206 }
207 207
208 CPDF_Array* pContentsArray = nullptr; 208 CPDF_Array* pContentsArray = nullptr;
209
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();
214 uint32_t dwObjNum = pDocument->AddIndirectObject(pContents); 213 uint32_t dwObjNum = pDocument->AddIndirectObject(pContents);
215 CPDF_StreamAcc acc; 214 CPDF_StreamAcc acc;
216 acc.LoadAllData(pContents); 215 acc.LoadAllData(pContents);
217 CFX_ByteString sStream = "q\n"; 216 CFX_ByteString sStream = "q\n";
218 CFX_ByteString sBody = 217 CFX_ByteString sBody =
219 CFX_ByteString((const FX_CHAR*)acc.GetData(), acc.GetSize()); 218 CFX_ByteString((const FX_CHAR*)acc.GetData(), acc.GetSize());
(...skipping 11 matching lines...) Expand all
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 uint32_t dwObjNum = pDocument->AddIndirectObject(pContentsArray);
238 pPage->SetReferenceFor("Contents", pDocument, dwObjNum); 237 pPage->SetReferenceFor("Contents", pDocument, dwObjNum);
239 238
240 if (!key.IsEmpty()) { 239 if (!key.IsEmpty()) {
241 CPDF_Stream* pNewContents = 240 CPDF_Stream* pNewContents = new CPDF_Stream(
242 new CPDF_Stream(nullptr, 0, new CPDF_Dictionary); 241 nullptr, 0, new CPDF_Dictionary(pDocument->GetByteStringPool()));
243 dwObjNum = pDocument->AddIndirectObject(pNewContents); 242 dwObjNum = pDocument->AddIndirectObject(pNewContents);
244 pContentsArray->AddReference(pDocument, dwObjNum); 243 pContentsArray->AddReference(pDocument, dwObjNum);
245 244
246 CFX_ByteString sStream; 245 CFX_ByteString sStream;
247 sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str()); 246 sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str());
248 pNewContents->SetData(sStream.raw_str(), sStream.GetLength()); 247 pNewContents->SetData(sStream.raw_str(), sStream.GetLength());
249 } 248 }
250 } 249 }
251 250
252 CFX_Matrix GetMatrix(CFX_FloatRect rcAnnot, 251 CFX_Matrix GetMatrix(CFX_FloatRect rcAnnot,
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 CPDF_Array* pCropBox = new CPDF_Array(); 364 CPDF_Array* pCropBox = new CPDF_Array();
366 pCropBox->Add(new CPDF_Number(rcOriginalCB.left)); 365 pCropBox->Add(new CPDF_Number(rcOriginalCB.left));
367 pCropBox->Add(new CPDF_Number(rcOriginalCB.bottom)); 366 pCropBox->Add(new CPDF_Number(rcOriginalCB.bottom));
368 pCropBox->Add(new CPDF_Number(rcOriginalCB.right)); 367 pCropBox->Add(new CPDF_Number(rcOriginalCB.right));
369 pCropBox->Add(new CPDF_Number(rcOriginalCB.top)); 368 pCropBox->Add(new CPDF_Number(rcOriginalCB.top));
370 pPageDict->SetFor("ArtBox", pCropBox); 369 pPageDict->SetFor("ArtBox", pCropBox);
371 } 370 }
372 371
373 CPDF_Dictionary* pRes = pPageDict->GetDictFor("Resources"); 372 CPDF_Dictionary* pRes = pPageDict->GetDictFor("Resources");
374 if (!pRes) { 373 if (!pRes) {
375 pRes = new CPDF_Dictionary; 374 pRes = new CPDF_Dictionary(pDocument->GetByteStringPool());
376 pPageDict->SetFor("Resources", pRes); 375 pPageDict->SetFor("Resources", pRes);
377 } 376 }
378 377
379 CPDF_Stream* pNewXObject = new CPDF_Stream(nullptr, 0, new CPDF_Dictionary); 378 CPDF_Stream* pNewXObject = new CPDF_Stream(
379 nullptr, 0, new CPDF_Dictionary(pDocument->GetByteStringPool()));
380
380 uint32_t dwObjNum = pDocument->AddIndirectObject(pNewXObject); 381 uint32_t dwObjNum = pDocument->AddIndirectObject(pNewXObject);
381 CPDF_Dictionary* pPageXObject = pRes->GetDictFor("XObject"); 382 CPDF_Dictionary* pPageXObject = pRes->GetDictFor("XObject");
382 if (!pPageXObject) { 383 if (!pPageXObject) {
383 pPageXObject = new CPDF_Dictionary; 384 pPageXObject = new CPDF_Dictionary(pDocument->GetByteStringPool());
384 pRes->SetFor("XObject", pPageXObject); 385 pRes->SetFor("XObject", pPageXObject);
385 } 386 }
386 387
387 CFX_ByteString key = ""; 388 CFX_ByteString key = "";
388 int nStreams = ObjectArray.GetSize(); 389 int nStreams = ObjectArray.GetSize();
389 390
390 if (nStreams > 0) { 391 if (nStreams > 0) {
391 for (int iKey = 0; /*iKey < 100*/; iKey++) { 392 for (int iKey = 0; /*iKey < 100*/; iKey++) {
392 char sExtend[5] = {}; 393 char sExtend[5] = {};
393 FXSYS_itoa(iKey, sExtend, 10); 394 FXSYS_itoa(iKey, sExtend, 10);
394 key = CFX_ByteString("FFT") + CFX_ByteString(sExtend); 395 key = CFX_ByteString("FFT") + CFX_ByteString(sExtend);
395 if (!pPageXObject->KeyExist(key)) 396 if (!pPageXObject->KeyExist(key))
396 break; 397 break;
397 } 398 }
398 } 399 }
399 400
400 SetPageContents(key, pPageDict, pDocument); 401 SetPageContents(key, pPageDict, pDocument);
401 402
402 CPDF_Dictionary* pNewXORes = nullptr; 403 CPDF_Dictionary* pNewXORes = nullptr;
403 404
404 if (!key.IsEmpty()) { 405 if (!key.IsEmpty()) {
405 pPageXObject->SetReferenceFor(key, pDocument, dwObjNum); 406 pPageXObject->SetReferenceFor(key, pDocument, dwObjNum);
406 CPDF_Dictionary* pNewOXbjectDic = pNewXObject->GetDict(); 407 CPDF_Dictionary* pNewOXbjectDic = pNewXObject->GetDict();
407 pNewXORes = new CPDF_Dictionary; 408 pNewXORes = new CPDF_Dictionary(pDocument->GetByteStringPool());
408 pNewOXbjectDic->SetFor("Resources", pNewXORes); 409 pNewOXbjectDic->SetFor("Resources", pNewXORes);
409 pNewOXbjectDic->SetNameFor("Type", "XObject"); 410 pNewOXbjectDic->SetNameFor("Type", "XObject");
410 pNewOXbjectDic->SetNameFor("Subtype", "Form"); 411 pNewOXbjectDic->SetNameFor("Subtype", "Form");
411 pNewOXbjectDic->SetIntegerFor("FormType", 1); 412 pNewOXbjectDic->SetIntegerFor("FormType", 1);
412 pNewOXbjectDic->SetNameFor("Name", "FRM"); 413 pNewOXbjectDic->SetNameFor("Name", "FRM");
413 CFX_FloatRect rcBBox = pPageDict->GetRectFor("ArtBox"); 414 CFX_FloatRect rcBBox = pPageDict->GetRectFor("ArtBox");
414 pNewOXbjectDic->SetRectFor("BBox", rcBBox); 415 pNewOXbjectDic->SetRectFor("BBox", rcBBox);
415 } 416 }
416 417
417 for (int i = 0; i < nStreams; i++) { 418 for (int i = 0; i < nStreams; i++) {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 if (pObj) { 470 if (pObj) {
470 CPDF_Dictionary* pObjDic = pObj->GetDict(); 471 CPDF_Dictionary* pObjDic = pObj->GetDict();
471 if (pObjDic) { 472 if (pObjDic) {
472 pObjDic->SetNameFor("Type", "XObject"); 473 pObjDic->SetNameFor("Type", "XObject");
473 pObjDic->SetNameFor("Subtype", "Form"); 474 pObjDic->SetNameFor("Subtype", "Form");
474 } 475 }
475 } 476 }
476 477
477 CPDF_Dictionary* pXObject = pNewXORes->GetDictFor("XObject"); 478 CPDF_Dictionary* pXObject = pNewXORes->GetDictFor("XObject");
478 if (!pXObject) { 479 if (!pXObject) {
479 pXObject = new CPDF_Dictionary; 480 pXObject = new CPDF_Dictionary(pDocument->GetByteStringPool());
480 pNewXORes->SetFor("XObject", pXObject); 481 pNewXORes->SetFor("XObject", pXObject);
481 } 482 }
482 483
483 CFX_ByteString sFormName; 484 CFX_ByteString sFormName;
484 sFormName.Format("F%d", i); 485 sFormName.Format("F%d", i);
485 uint32_t dwStreamObjNum = pDocument->AddIndirectObject(pObj); 486 uint32_t dwStreamObjNum = pDocument->AddIndirectObject(pObj);
486 pXObject->SetReferenceFor(sFormName, pDocument, dwStreamObjNum); 487 pXObject->SetReferenceFor(sFormName, pDocument, dwStreamObjNum);
487 488
488 CPDF_StreamAcc acc; 489 CPDF_StreamAcc acc;
489 acc.LoadAllData(pNewXObject); 490 acc.LoadAllData(pNewXObject);
(...skipping 17 matching lines...) Expand all
507 sStream += sTemp; 508 sStream += sTemp;
508 pNewXObject->SetData(sStream.raw_str(), sStream.GetLength()); 509 pNewXObject->SetData(sStream.raw_str(), sStream.GetLength());
509 } 510 }
510 pPageDict->RemoveFor("Annots"); 511 pPageDict->RemoveFor("Annots");
511 512
512 ObjectArray.RemoveAll(); 513 ObjectArray.RemoveAll();
513 RectArray.RemoveAll(); 514 RectArray.RemoveAll();
514 515
515 return FLATTEN_SUCCESS; 516 return FLATTEN_SUCCESS;
516 } 517 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698