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

Side by Side Diff: core/fpdfapi/fpdf_edit/cpdf_pagecontentgenerator.cpp

Issue 2345063002: Use string pools in some dictionaries (Closed)
Patch Set: more 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 2016 PDFium Authors. All rights reserved. 1 // Copyright 2016 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 "core/fpdfapi/fpdf_edit/include/cpdf_pagecontentgenerator.h" 7 #include "core/fpdfapi/fpdf_edit/include/cpdf_pagecontentgenerator.h"
8 8
9 #include "core/fpdfapi/fpdf_edit/include/cpdf_creator.h" 9 #include "core/fpdfapi/fpdf_edit/include/cpdf_creator.h"
10 #include "core/fpdfapi/fpdf_page/include/cpdf_image.h" 10 #include "core/fpdfapi/fpdf_page/include/cpdf_image.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 CPDF_Stream* pStream = new CPDF_Stream(nullptr, 0, nullptr); 56 CPDF_Stream* pStream = new CPDF_Stream(nullptr, 0, nullptr);
57 pStream->SetData(buf.GetBuffer(), buf.GetLength(), FALSE, FALSE); 57 pStream->SetData(buf.GetBuffer(), buf.GetLength(), FALSE, FALSE);
58 m_pDocument->AddIndirectObject(pStream); 58 m_pDocument->AddIndirectObject(pStream);
59 pPageDict->SetReferenceFor("Contents", m_pDocument, pStream->GetObjNum()); 59 pPageDict->SetReferenceFor("Contents", m_pDocument, pStream->GetObjNum());
60 } 60 }
61 61
62 CFX_ByteString CPDF_PageContentGenerator::RealizeResource( 62 CFX_ByteString CPDF_PageContentGenerator::RealizeResource(
63 CPDF_Object* pResourceObj, 63 CPDF_Object* pResourceObj,
64 const CFX_ByteString& bsType) { 64 const CFX_ByteString& bsType) {
65 if (!m_pPage->m_pResources) { 65 if (!m_pPage->m_pResources) {
66 m_pPage->m_pResources = new CPDF_Dictionary; 66 m_pPage->m_pResources =
67 new CPDF_Dictionary(m_pDocument->GetByteStringPool());
67 int objnum = m_pDocument->AddIndirectObject(m_pPage->m_pResources); 68 int objnum = m_pDocument->AddIndirectObject(m_pPage->m_pResources);
68 m_pPage->m_pFormDict->SetReferenceFor("Resources", m_pDocument, objnum); 69 m_pPage->m_pFormDict->SetReferenceFor("Resources", m_pDocument, objnum);
69 } 70 }
70 CPDF_Dictionary* pResList = m_pPage->m_pResources->GetDictFor(bsType); 71 CPDF_Dictionary* pResList = m_pPage->m_pResources->GetDictFor(bsType);
71 if (!pResList) { 72 if (!pResList) {
72 pResList = new CPDF_Dictionary; 73 pResList = new CPDF_Dictionary(m_pDocument->GetByteStringPool());
73 m_pPage->m_pResources->SetFor(bsType, pResList); 74 m_pPage->m_pResources->SetFor(bsType, pResList);
74 } 75 }
75 m_pDocument->AddIndirectObject(pResourceObj); 76 m_pDocument->AddIndirectObject(pResourceObj);
76 CFX_ByteString name; 77 CFX_ByteString name;
77 int idnum = 1; 78 int idnum = 1;
78 while (1) { 79 while (1) {
79 name.Format("FX%c%d", bsType[0], idnum); 80 name.Format("FX%c%d", bsType[0], idnum);
80 if (!pResList->KeyExist(name)) { 81 if (!pResList->KeyExist(name)) {
81 break; 82 break;
82 } 83 }
(...skipping 23 matching lines...) Expand all
106 } 107 }
107 108
108 void CPDF_PageContentGenerator::ProcessForm(CFX_ByteTextBuf& buf, 109 void CPDF_PageContentGenerator::ProcessForm(CFX_ByteTextBuf& buf,
109 const uint8_t* data, 110 const uint8_t* data,
110 uint32_t size, 111 uint32_t size,
111 CFX_Matrix& matrix) { 112 CFX_Matrix& matrix) {
112 if (!data || !size) { 113 if (!data || !size) {
113 return; 114 return;
114 } 115 }
115 CPDF_Stream* pStream = new CPDF_Stream(nullptr, 0, nullptr); 116 CPDF_Stream* pStream = new CPDF_Stream(nullptr, 0, nullptr);
116 CPDF_Dictionary* pFormDict = new CPDF_Dictionary; 117 CPDF_Dictionary* pFormDict =
118 new CPDF_Dictionary(m_pDocument->GetByteStringPool());
117 pFormDict->SetNameFor("Type", "XObject"); 119 pFormDict->SetNameFor("Type", "XObject");
118 pFormDict->SetNameFor("Subtype", "Form"); 120 pFormDict->SetNameFor("Subtype", "Form");
119 CFX_FloatRect bbox = m_pPage->GetPageBBox(); 121 CFX_FloatRect bbox = m_pPage->GetPageBBox();
120 matrix.TransformRect(bbox); 122 matrix.TransformRect(bbox);
121 pFormDict->SetRectFor("BBox", bbox); 123 pFormDict->SetRectFor("BBox", bbox);
122 pStream->InitStream(data, size, pFormDict); 124 pStream->InitStream(data, size, pFormDict);
123 buf << "q " << matrix << " cm "; 125 buf << "q " << matrix << " cm ";
124 CFX_ByteString name = RealizeResource(pStream, "XObject"); 126 CFX_ByteString name = RealizeResource(pStream, "XObject");
125 buf << "/" << PDF_NameEncode(name) << " Do Q\n"; 127 buf << "/" << PDF_NameEncode(name) << " Do Q\n";
126 } 128 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 CPDF_StreamAcc contentStream; 165 CPDF_StreamAcc contentStream;
164 contentStream.LoadAllData(pStream); 166 contentStream.LoadAllData(pStream);
165 ProcessForm(buf, contentStream.GetData(), contentStream.GetSize(), matrix); 167 ProcessForm(buf, contentStream.GetData(), contentStream.GetSize(), matrix);
166 } 168 }
167 CPDF_Stream* pStream = new CPDF_Stream(nullptr, 0, nullptr); 169 CPDF_Stream* pStream = new CPDF_Stream(nullptr, 0, nullptr);
168 pStream->SetData(buf.GetBuffer(), buf.GetLength(), FALSE, FALSE); 170 pStream->SetData(buf.GetBuffer(), buf.GetLength(), FALSE, FALSE);
169 m_pDocument->AddIndirectObject(pStream); 171 m_pDocument->AddIndirectObject(pStream);
170 m_pPage->m_pFormDict->SetReferenceFor("Contents", m_pDocument, 172 m_pPage->m_pFormDict->SetReferenceFor("Contents", m_pDocument,
171 pStream->GetObjNum()); 173 pStream->GetObjNum());
172 } 174 }
OLDNEW
« no previous file with comments | « no previous file | core/fpdfapi/fpdf_font/cpdf_font.cpp » ('j') | core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698