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

Side by Side Diff: fpdfsdk/fpdf_transformpage.cpp

Issue 2498223005: Make CPDF_Array take unique_ptrs (Closed)
Patch Set: nits Created 4 years, 1 month 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/fpdf_flatten.cpp ('k') | fpdfsdk/fpdfdoc_unittest.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_transformpage.h" 7 #include "public/fpdf_transformpage.h"
8 8
9 #include "core/fpdfapi/page/cpdf_clippath.h" 9 #include "core/fpdfapi/page/cpdf_clippath.h"
10 #include "core/fpdfapi/page/cpdf_page.h" 10 #include "core/fpdfapi/page/cpdf_page.h"
11 #include "core/fpdfapi/page/cpdf_pageobject.h" 11 #include "core/fpdfapi/page/cpdf_pageobject.h"
12 #include "core/fpdfapi/page/cpdf_path.h" 12 #include "core/fpdfapi/page/cpdf_path.h"
13 #include "core/fpdfapi/parser/cpdf_array.h" 13 #include "core/fpdfapi/parser/cpdf_array.h"
14 #include "core/fpdfapi/parser/cpdf_document.h" 14 #include "core/fpdfapi/parser/cpdf_document.h"
15 #include "core/fpdfapi/parser/cpdf_number.h" 15 #include "core/fpdfapi/parser/cpdf_number.h"
16 #include "core/fpdfapi/parser/cpdf_reference.h" 16 #include "core/fpdfapi/parser/cpdf_reference.h"
17 #include "core/fpdfapi/parser/cpdf_stream.h" 17 #include "core/fpdfapi/parser/cpdf_stream.h"
18 #include "core/fxge/cfx_pathdata.h" 18 #include "core/fxge/cfx_pathdata.h"
19 #include "fpdfsdk/fsdk_define.h" 19 #include "fpdfsdk/fsdk_define.h"
20 20
21 namespace { 21 namespace {
22 22
23 void SetBoundingBox(CPDF_Page* page, 23 void SetBoundingBox(CPDF_Page* page,
24 const CFX_ByteString& key, 24 const CFX_ByteString& key,
25 float left, 25 float left,
26 float bottom, 26 float bottom,
27 float right, 27 float right,
28 float top) { 28 float top) {
29 CPDF_Array* pBoundingBoxArray = new CPDF_Array; 29 CPDF_Array* pBoundingBoxArray = new CPDF_Array;
30 pBoundingBoxArray->Add(new CPDF_Number(left)); 30 pBoundingBoxArray->AddNew<CPDF_Number>(left);
31 pBoundingBoxArray->Add(new CPDF_Number(bottom)); 31 pBoundingBoxArray->AddNew<CPDF_Number>(bottom);
32 pBoundingBoxArray->Add(new CPDF_Number(right)); 32 pBoundingBoxArray->AddNew<CPDF_Number>(right);
33 pBoundingBoxArray->Add(new CPDF_Number(top)); 33 pBoundingBoxArray->AddNew<CPDF_Number>(top);
34 page->m_pFormDict->SetFor(key, pBoundingBoxArray); 34 page->m_pFormDict->SetFor(key, pBoundingBoxArray);
35 } 35 }
36 36
37 bool GetBoundingBox(CPDF_Page* page, 37 bool GetBoundingBox(CPDF_Page* page,
38 const CFX_ByteString& key, 38 const CFX_ByteString& key,
39 float* left, 39 float* left,
40 float* bottom, 40 float* bottom,
41 float* right, 41 float* right,
42 float* top) { 42 float* top) {
43 CPDF_Array* pArray = page->m_pFormDict->GetArrayFor(key); 43 CPDF_Array* pArray = page->m_pFormDict->GetArrayFor(key);
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 135
136 pDic = new CPDF_Dictionary(pDoc->GetByteStringPool()); 136 pDic = new CPDF_Dictionary(pDoc->GetByteStringPool());
137 137
138 CPDF_Stream* pEndStream = pDoc->NewIndirect<CPDF_Stream>(nullptr, 0, pDic); 138 CPDF_Stream* pEndStream = pDoc->NewIndirect<CPDF_Stream>(nullptr, 0, pDic);
139 pEndStream->SetData((const uint8_t*)" Q", 2); 139 pEndStream->SetData((const uint8_t*)" Q", 2);
140 140
141 CPDF_Array* pContentArray = nullptr; 141 CPDF_Array* pContentArray = nullptr;
142 CPDF_Array* pArray = ToArray(pContentObj); 142 CPDF_Array* pArray = ToArray(pContentObj);
143 if (pArray) { 143 if (pArray) {
144 pContentArray = pArray; 144 pContentArray = pArray;
145 CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum()); 145 pContentArray->InsertNewAt<CPDF_Reference>(0, pDoc, pStream->GetObjNum());
146 pContentArray->InsertAt(0, pRef); 146 pContentArray->AddNew<CPDF_Reference>(pDoc, pEndStream->GetObjNum());
147 pContentArray->AddReference(pDoc, pEndStream->GetObjNum());
148 } else if (CPDF_Reference* pReference = ToReference(pContentObj)) { 147 } else if (CPDF_Reference* pReference = ToReference(pContentObj)) {
149 CPDF_Object* pDirectObj = pReference->GetDirect(); 148 CPDF_Object* pDirectObj = pReference->GetDirect();
150 if (pDirectObj) { 149 if (pDirectObj) {
151 CPDF_Array* pObjArray = pDirectObj->AsArray(); 150 CPDF_Array* pObjArray = pDirectObj->AsArray();
152 if (pObjArray) { 151 if (pObjArray) {
153 pContentArray = pObjArray; 152 pContentArray = pObjArray;
154 CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum()); 153 pContentArray->InsertNewAt<CPDF_Reference>(0, pDoc,
155 pContentArray->InsertAt(0, pRef); 154 pStream->GetObjNum());
156 pContentArray->AddReference(pDoc, pEndStream->GetObjNum()); 155 pContentArray->AddNew<CPDF_Reference>(pDoc, pEndStream->GetObjNum());
157 } else if (pDirectObj->IsStream()) { 156 } else if (pDirectObj->IsStream()) {
158 pContentArray = pDoc->NewIndirect<CPDF_Array>(); 157 pContentArray = pDoc->NewIndirect<CPDF_Array>();
159 pContentArray->AddReference(pDoc, pStream->GetObjNum()); 158 pContentArray->AddNew<CPDF_Reference>(pDoc, pStream->GetObjNum());
160 pContentArray->AddReference(pDoc, pDirectObj->GetObjNum()); 159 pContentArray->AddNew<CPDF_Reference>(pDoc, pDirectObj->GetObjNum());
161 pContentArray->AddReference(pDoc, pEndStream->GetObjNum()); 160 pContentArray->AddNew<CPDF_Reference>(pDoc, pEndStream->GetObjNum());
162 pPageDic->SetReferenceFor("Contents", pDoc, pContentArray); 161 pPageDic->SetReferenceFor("Contents", pDoc, pContentArray);
163 } 162 }
164 } 163 }
165 } 164 }
166 165
167 // Need to transform the patterns as well. 166 // Need to transform the patterns as well.
168 CPDF_Dictionary* pRes = pPageDic->GetDictFor("Resources"); 167 CPDF_Dictionary* pRes = pPageDic->GetDictFor("Resources");
169 if (pRes) { 168 if (pRes) {
170 CPDF_Dictionary* pPattenDict = pRes->GetDictFor("Pattern"); 169 CPDF_Dictionary* pPattenDict = pRes->GetDictFor("Pattern");
171 if (pPattenDict) { 170 if (pPattenDict) {
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 } 299 }
301 } 300 }
302 CPDF_Document* pDoc = pPage->m_pDocument; 301 CPDF_Document* pDoc = pPage->m_pDocument;
303 if (!pDoc) 302 if (!pDoc)
304 return; 303 return;
305 304
306 CPDF_Dictionary* pDic = new CPDF_Dictionary(pDoc->GetByteStringPool()); 305 CPDF_Dictionary* pDic = new CPDF_Dictionary(pDoc->GetByteStringPool());
307 CPDF_Stream* pStream = pDoc->NewIndirect<CPDF_Stream>(nullptr, 0, pDic); 306 CPDF_Stream* pStream = pDoc->NewIndirect<CPDF_Stream>(nullptr, 0, pDic);
308 pStream->SetData(strClip.GetBuffer(), strClip.GetSize()); 307 pStream->SetData(strClip.GetBuffer(), strClip.GetSize());
309 308
310 CPDF_Array* pContentArray = nullptr;
311 CPDF_Array* pArray = ToArray(pContentObj); 309 CPDF_Array* pArray = ToArray(pContentObj);
312 if (pArray) { 310 if (pArray) {
313 pContentArray = pArray; 311 pArray->InsertNewAt<CPDF_Reference>(0, pDoc, pStream->GetObjNum());
314 CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum()); 312 return;
315 pContentArray->InsertAt(0, pRef); 313 }
316 } else if (CPDF_Reference* pReference = ToReference(pContentObj)) { 314 CPDF_Reference* pReference = ToReference(pContentObj);
317 CPDF_Object* pDirectObj = pReference->GetDirect(); 315 if (!pReference)
318 if (pDirectObj) { 316 return;
319 CPDF_Array* pObjArray = pDirectObj->AsArray(); 317
320 if (pObjArray) { 318 CPDF_Object* pDirectObj = pReference->GetDirect();
321 pContentArray = pObjArray; 319 if (!pDirectObj)
322 CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum()); 320 return;
323 pContentArray->InsertAt(0, pRef); 321
324 } else if (pDirectObj->IsStream()) { 322 CPDF_Array* pObjArray = pDirectObj->AsArray();
325 pContentArray = pDoc->NewIndirect<CPDF_Array>(); 323 if (pObjArray) {
326 pContentArray->AddReference(pDoc, pStream->GetObjNum()); 324 pObjArray->InsertNewAt<CPDF_Reference>(0, pDoc, pStream->GetObjNum());
327 pContentArray->AddReference(pDoc, pDirectObj->GetObjNum()); 325 return;
328 pPageDic->SetReferenceFor("Contents", pDoc, pContentArray); 326 }
329 } 327 if (pDirectObj->IsStream()) {
330 } 328 CPDF_Array* pContentArray = pDoc->NewIndirect<CPDF_Array>();
329 pContentArray->AddNew<CPDF_Reference>(pDoc, pStream->GetObjNum());
330 pContentArray->AddNew<CPDF_Reference>(pDoc, pDirectObj->GetObjNum());
331 pPageDic->SetReferenceFor("Contents", pDoc, pContentArray);
331 } 332 }
332 } 333 }
OLDNEW
« no previous file with comments | « fpdfsdk/fpdf_flatten.cpp ('k') | fpdfsdk/fpdfdoc_unittest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698