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

Side by Side Diff: fpdfsdk/fpdf_transformpage.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_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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 textBuf << bsMatix; 118 textBuf << bsMatix;
119 119
120 CPDF_Dictionary* pPageDic = pPage->m_pFormDict; 120 CPDF_Dictionary* pPageDic = pPage->m_pFormDict;
121 CPDF_Object* pContentObj = 121 CPDF_Object* pContentObj =
122 pPageDic ? pPageDic->GetObjectFor("Contents") : nullptr; 122 pPageDic ? pPageDic->GetObjectFor("Contents") : nullptr;
123 if (!pContentObj) 123 if (!pContentObj)
124 pContentObj = pPageDic ? pPageDic->GetArrayFor("Contents") : nullptr; 124 pContentObj = pPageDic ? pPageDic->GetArrayFor("Contents") : nullptr;
125 if (!pContentObj) 125 if (!pContentObj)
126 return FALSE; 126 return FALSE;
127 127
128 CPDF_Dictionary* pDic = new CPDF_Dictionary;
129 CPDF_Stream* pStream = new CPDF_Stream(nullptr, 0, pDic);
130 pStream->SetData(textBuf.GetBuffer(), textBuf.GetSize(), FALSE, FALSE);
131 CPDF_Document* pDoc = pPage->m_pDocument; 128 CPDF_Document* pDoc = pPage->m_pDocument;
132 if (!pDoc) 129 if (!pDoc)
133 return FALSE; 130 return FALSE;
131
132 CPDF_Dictionary* pDic = new CPDF_Dictionary(pDoc);
133 CPDF_Stream* pStream = new CPDF_Stream(nullptr, 0, pDic);
134 pStream->SetData(textBuf.GetBuffer(), textBuf.GetSize(), FALSE, FALSE);
dsinclair 2016/09/19 13:24:34 Previously this would SetData regardless of the va
Tom Sepez 2016/09/19 18:25:00 Yes, it would be a leak in that case as the new st
134 pDoc->AddIndirectObject(pStream); 135 pDoc->AddIndirectObject(pStream);
136 pDic = new CPDF_Dictionary(pDoc);
135 137
136 pDic = new CPDF_Dictionary;
137 CPDF_Stream* pEndStream = new CPDF_Stream(nullptr, 0, pDic); 138 CPDF_Stream* pEndStream = new CPDF_Stream(nullptr, 0, pDic);
138 pEndStream->SetData((const uint8_t*)" Q", 2, FALSE, FALSE); 139 pEndStream->SetData((const uint8_t*)" Q", 2, FALSE, FALSE);
139 pDoc->AddIndirectObject(pEndStream); 140 pDoc->AddIndirectObject(pEndStream);
140 141
141 CPDF_Array* pContentArray = nullptr; 142 CPDF_Array* pContentArray = nullptr;
142 CPDF_Array* pArray = ToArray(pContentObj); 143 CPDF_Array* pArray = ToArray(pContentObj);
143 if (pArray) { 144 if (pArray) {
144 pContentArray = pArray; 145 pContentArray = pArray;
145 CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum()); 146 CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum());
146 pContentArray->InsertAt(0, pRef); 147 pContentArray->InsertAt(0, pRef);
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 // Empty clipping (totally clipped out) 294 // Empty clipping (totally clipped out)
294 strClip << "0 0 m W n "; 295 strClip << "0 0 m W n ";
295 } else { 296 } else {
296 OutputPath(strClip, path); 297 OutputPath(strClip, path);
297 if (iClipType == FXFILL_WINDING) 298 if (iClipType == FXFILL_WINDING)
298 strClip << "W n\n"; 299 strClip << "W n\n";
299 else 300 else
300 strClip << "W* n\n"; 301 strClip << "W* n\n";
301 } 302 }
302 } 303 }
303 CPDF_Dictionary* pDic = new CPDF_Dictionary;
304 CPDF_Stream* pStream = new CPDF_Stream(nullptr, 0, pDic);
305 pStream->SetData(strClip.GetBuffer(), strClip.GetSize(), FALSE, FALSE);
306 CPDF_Document* pDoc = pPage->m_pDocument; 304 CPDF_Document* pDoc = pPage->m_pDocument;
307 if (!pDoc) 305 if (!pDoc)
308 return; 306 return;
307
308 CPDF_Dictionary* pDic = new CPDF_Dictionary(pDoc);
309 CPDF_Stream* pStream = new CPDF_Stream(nullptr, 0, pDic);
310 pStream->SetData(strClip.GetBuffer(), strClip.GetSize(), FALSE, FALSE);
dsinclair 2016/09/19 13:24:34 ditto
Tom Sepez 2016/09/19 18:25:00 ditto
309 pDoc->AddIndirectObject(pStream); 311 pDoc->AddIndirectObject(pStream);
310 312
311 CPDF_Array* pContentArray = nullptr; 313 CPDF_Array* pContentArray = nullptr;
312 CPDF_Array* pArray = ToArray(pContentObj); 314 CPDF_Array* pArray = ToArray(pContentObj);
313 if (pArray) { 315 if (pArray) {
314 pContentArray = pArray; 316 pContentArray = pArray;
315 CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum()); 317 CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum());
316 pContentArray->InsertAt(0, pRef); 318 pContentArray->InsertAt(0, pRef);
317 } else if (CPDF_Reference* pReference = ToReference(pContentObj)) { 319 } else if (CPDF_Reference* pReference = ToReference(pContentObj)) {
318 CPDF_Object* pDirectObj = pReference->GetDirect(); 320 CPDF_Object* pDirectObj = pReference->GetDirect();
319 if (pDirectObj) { 321 if (pDirectObj) {
320 CPDF_Array* pObjArray = pDirectObj->AsArray(); 322 CPDF_Array* pObjArray = pDirectObj->AsArray();
321 if (pObjArray) { 323 if (pObjArray) {
322 pContentArray = pObjArray; 324 pContentArray = pObjArray;
323 CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum()); 325 CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum());
324 pContentArray->InsertAt(0, pRef); 326 pContentArray->InsertAt(0, pRef);
325 } else if (pDirectObj->IsStream()) { 327 } else if (pDirectObj->IsStream()) {
326 pContentArray = new CPDF_Array(); 328 pContentArray = new CPDF_Array();
327 pContentArray->AddReference(pDoc, pStream->GetObjNum()); 329 pContentArray->AddReference(pDoc, pStream->GetObjNum());
328 pContentArray->AddReference(pDoc, pDirectObj->GetObjNum()); 330 pContentArray->AddReference(pDoc, pDirectObj->GetObjNum());
329 pPageDic->SetReferenceFor("Contents", pDoc, 331 pPageDic->SetReferenceFor("Contents", pDoc,
330 pDoc->AddIndirectObject(pContentArray)); 332 pDoc->AddIndirectObject(pContentArray));
331 } 333 }
332 } 334 }
333 } 335 }
334 } 336 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698