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

Side by Side Diff: fpdfsdk/fpdf_flatten.cpp

Issue 2489283003: Make AddIndirectObject() take a unique_ptr. (Closed)
Patch Set: Address review comments 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/formfiller/cba_fontmap.cpp ('k') | fpdfsdk/fpdf_transformpage.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_flatten.h" 7 #include "public/fpdf_flatten.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 rcRet.left = GetMinMaxValue(*pRectArray, MIN, LEFT); 165 rcRet.left = GetMinMaxValue(*pRectArray, MIN, LEFT);
166 rcRet.top = GetMinMaxValue(*pRectArray, MAX, TOP); 166 rcRet.top = GetMinMaxValue(*pRectArray, MAX, TOP);
167 rcRet.right = GetMinMaxValue(*pRectArray, MAX, RIGHT); 167 rcRet.right = GetMinMaxValue(*pRectArray, MAX, RIGHT);
168 rcRet.bottom = GetMinMaxValue(*pRectArray, MIN, BOTTOM); 168 rcRet.bottom = GetMinMaxValue(*pRectArray, MIN, BOTTOM);
169 169
170 return rcRet; 170 return rcRet;
171 } 171 }
172 172
173 uint32_t NewIndirectContentsStream(const CFX_ByteString& key, 173 uint32_t NewIndirectContentsStream(const CFX_ByteString& key,
174 CPDF_Document* pDocument) { 174 CPDF_Document* pDocument) {
175 CPDF_Stream* pNewContents = new CPDF_Stream( 175 CPDF_Stream* pNewContents = pDocument->NewIndirect<CPDF_Stream>(
176 nullptr, 0, new CPDF_Dictionary(pDocument->GetByteStringPool())); 176 nullptr, 0, new CPDF_Dictionary(pDocument->GetByteStringPool()));
177 CFX_ByteString sStream; 177 CFX_ByteString sStream;
178 sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str()); 178 sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str());
179 pNewContents->SetData(sStream.raw_str(), sStream.GetLength()); 179 pNewContents->SetData(sStream.raw_str(), sStream.GetLength());
180 return pDocument->AddIndirectObject(pNewContents); 180 return pNewContents->GetObjNum();
181 } 181 }
182 182
183 void SetPageContents(const CFX_ByteString& key, 183 void SetPageContents(const CFX_ByteString& key,
184 CPDF_Dictionary* pPage, 184 CPDF_Dictionary* pPage,
185 CPDF_Document* pDocument) { 185 CPDF_Document* pDocument) {
186 CPDF_Array* pContentsArray = nullptr; 186 CPDF_Array* pContentsArray = nullptr;
187 CPDF_Stream* pContentsStream = pPage->GetStreamFor("Contents"); 187 CPDF_Stream* pContentsStream = pPage->GetStreamFor("Contents");
188 if (!pContentsStream) { 188 if (!pContentsStream) {
189 pContentsArray = pPage->GetArrayFor("Contents"); 189 pContentsArray = pPage->GetArrayFor("Contents");
190 if (!pContentsArray) { 190 if (!pContentsArray) {
191 if (!key.IsEmpty()) { 191 if (!key.IsEmpty()) {
192 pPage->SetReferenceFor("Contents", pDocument, 192 pPage->SetReferenceFor("Contents", pDocument,
193 NewIndirectContentsStream(key, pDocument)); 193 NewIndirectContentsStream(key, pDocument));
194 } 194 }
195 return; 195 return;
196 } 196 }
197 } 197 }
198 pPage->ConvertToIndirectObjectFor("Contents", pDocument); 198 pPage->ConvertToIndirectObjectFor("Contents", pDocument);
199 if (!pContentsArray) { 199 if (!pContentsArray) {
200 pContentsArray = new CPDF_Array; 200 pContentsArray = pDocument->NewIndirect<CPDF_Array>();
201 CPDF_StreamAcc acc; 201 CPDF_StreamAcc acc;
202 acc.LoadAllData(pContentsStream); 202 acc.LoadAllData(pContentsStream);
203 CFX_ByteString sStream = "q\n"; 203 CFX_ByteString sStream = "q\n";
204 CFX_ByteString sBody = 204 CFX_ByteString sBody =
205 CFX_ByteString((const FX_CHAR*)acc.GetData(), acc.GetSize()); 205 CFX_ByteString((const FX_CHAR*)acc.GetData(), acc.GetSize());
206 sStream = sStream + sBody + "\nQ"; 206 sStream = sStream + sBody + "\nQ";
207 pContentsStream->SetData(sStream.raw_str(), sStream.GetLength()); 207 pContentsStream->SetData(sStream.raw_str(), sStream.GetLength());
208 pContentsArray->AddReference(pDocument, pContentsStream->GetObjNum()); 208 pContentsArray->AddReference(pDocument, pContentsStream->GetObjNum());
209 pPage->SetReferenceFor("Contents", pDocument, 209 pPage->SetReferenceFor("Contents", pDocument, pContentsArray);
210 pDocument->AddIndirectObject(pContentsArray));
211 } 210 }
212 if (!key.IsEmpty()) { 211 if (!key.IsEmpty()) {
213 pContentsArray->AddReference(pDocument, 212 pContentsArray->AddReference(pDocument,
214 NewIndirectContentsStream(key, pDocument)); 213 NewIndirectContentsStream(key, pDocument));
215 } 214 }
216 } 215 }
217 216
218 CFX_Matrix GetMatrix(CFX_FloatRect rcAnnot, 217 CFX_Matrix GetMatrix(CFX_FloatRect rcAnnot,
219 CFX_FloatRect rcStream, 218 CFX_FloatRect rcStream,
220 const CFX_Matrix& matrix) { 219 const CFX_Matrix& matrix) {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 pCropBox->Add(new CPDF_Number(rcOriginalCB.top)); 285 pCropBox->Add(new CPDF_Number(rcOriginalCB.top));
287 pPageDict->SetFor("ArtBox", pCropBox); 286 pPageDict->SetFor("ArtBox", pCropBox);
288 } 287 }
289 288
290 CPDF_Dictionary* pRes = pPageDict->GetDictFor("Resources"); 289 CPDF_Dictionary* pRes = pPageDict->GetDictFor("Resources");
291 if (!pRes) { 290 if (!pRes) {
292 pRes = new CPDF_Dictionary(pDocument->GetByteStringPool()); 291 pRes = new CPDF_Dictionary(pDocument->GetByteStringPool());
293 pPageDict->SetFor("Resources", pRes); 292 pPageDict->SetFor("Resources", pRes);
294 } 293 }
295 294
296 CPDF_Stream* pNewXObject = new CPDF_Stream( 295 CPDF_Stream* pNewXObject = pDocument->NewIndirect<CPDF_Stream>(
297 nullptr, 0, new CPDF_Dictionary(pDocument->GetByteStringPool())); 296 nullptr, 0, new CPDF_Dictionary(pDocument->GetByteStringPool()));
298 297
299 uint32_t dwObjNum = pDocument->AddIndirectObject(pNewXObject); 298 uint32_t dwObjNum = pNewXObject->GetObjNum();
300 CPDF_Dictionary* pPageXObject = pRes->GetDictFor("XObject"); 299 CPDF_Dictionary* pPageXObject = pRes->GetDictFor("XObject");
301 if (!pPageXObject) { 300 if (!pPageXObject) {
302 pPageXObject = new CPDF_Dictionary(pDocument->GetByteStringPool()); 301 pPageXObject = new CPDF_Dictionary(pDocument->GetByteStringPool());
303 pRes->SetFor("XObject", pPageXObject); 302 pRes->SetFor("XObject", pPageXObject);
304 } 303 }
305 304
306 CFX_ByteString key = ""; 305 CFX_ByteString key = "";
307 int nStreams = pdfium::CollectionSize<int>(ObjectArray); 306 int nStreams = pdfium::CollectionSize<int>(ObjectArray);
308 if (nStreams > 0) { 307 if (nStreams > 0) {
309 for (int iKey = 0; /*iKey < 100*/; iKey++) { 308 for (int iKey = 0; /*iKey < 100*/; iKey++) {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 else if (pAPDic->KeyExist("BBox")) 375 else if (pAPDic->KeyExist("BBox"))
377 rcStream = pAPDic->GetRectFor("BBox"); 376 rcStream = pAPDic->GetRectFor("BBox");
378 377
379 if (rcStream.IsEmpty()) 378 if (rcStream.IsEmpty())
380 continue; 379 continue;
381 380
382 CPDF_Object* pObj = pAPStream; 381 CPDF_Object* pObj = pAPStream;
383 if (pObj->IsInline()) { 382 if (pObj->IsInline()) {
384 std::unique_ptr<CPDF_Object> pNew = pObj->Clone(); 383 std::unique_ptr<CPDF_Object> pNew = pObj->Clone();
385 pObj = pNew.get(); 384 pObj = pNew.get();
386 pDocument->AddIndirectObject(pNew.release()); 385 pDocument->AddIndirectObject(std::move(pNew));
387 } 386 }
388 387
389 CPDF_Dictionary* pObjDic = pObj->GetDict(); 388 CPDF_Dictionary* pObjDic = pObj->GetDict();
390 if (pObjDic) { 389 if (pObjDic) {
391 pObjDic->SetNameFor("Type", "XObject"); 390 pObjDic->SetNameFor("Type", "XObject");
392 pObjDic->SetNameFor("Subtype", "Form"); 391 pObjDic->SetNameFor("Subtype", "Form");
393 } 392 }
394 393
395 CPDF_Dictionary* pXObject = pNewXORes->GetDictFor("XObject"); 394 CPDF_Dictionary* pXObject = pNewXORes->GetDictFor("XObject");
396 if (!pXObject) { 395 if (!pXObject) {
(...skipping 23 matching lines...) Expand all
420 CFX_ByteString sTemp; 419 CFX_ByteString sTemp;
421 CFX_Matrix m = GetMatrix(rcAnnot, rcStream, matrix); 420 CFX_Matrix m = GetMatrix(rcAnnot, rcStream, matrix);
422 sTemp.Format("q %f 0 0 %f %f %f cm /%s Do Q\n", m.a, m.d, m.e, m.f, 421 sTemp.Format("q %f 0 0 %f %f %f cm /%s Do Q\n", m.a, m.d, m.e, m.f,
423 sFormName.c_str()); 422 sFormName.c_str());
424 sStream += sTemp; 423 sStream += sTemp;
425 pNewXObject->SetData(sStream.raw_str(), sStream.GetLength()); 424 pNewXObject->SetData(sStream.raw_str(), sStream.GetLength());
426 } 425 }
427 pPageDict->RemoveFor("Annots"); 426 pPageDict->RemoveFor("Annots");
428 return FLATTEN_SUCCESS; 427 return FLATTEN_SUCCESS;
429 } 428 }
OLDNEW
« no previous file with comments | « fpdfsdk/formfiller/cba_fontmap.cpp ('k') | fpdfsdk/fpdf_transformpage.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698