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

Side by Side Diff: fpdfsdk/fpdf_flatten.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/cpdfsdk_baannot.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
11 #include "core/fpdfapi/page/cpdf_page.h" 11 #include "core/fpdfapi/page/cpdf_page.h"
12 #include "core/fpdfapi/page/cpdf_pageobject.h" 12 #include "core/fpdfapi/page/cpdf_pageobject.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_stream.h" 17 #include "core/fpdfapi/parser/cpdf_stream.h"
17 #include "core/fpdfapi/parser/cpdf_stream_acc.h" 18 #include "core/fpdfapi/parser/cpdf_stream_acc.h"
18 #include "core/fpdfdoc/cpdf_annot.h" 19 #include "core/fpdfdoc/cpdf_annot.h"
19 #include "fpdfsdk/fsdk_define.h" 20 #include "fpdfsdk/fsdk_define.h"
20 #include "third_party/base/stl_util.h" 21 #include "third_party/base/stl_util.h"
21 22
22 enum FPDF_TYPE { MAX, MIN }; 23 enum FPDF_TYPE { MAX, MIN };
23 enum FPDF_VALUE { TOP, LEFT, RIGHT, BOTTOM }; 24 enum FPDF_VALUE { TOP, LEFT, RIGHT, BOTTOM };
24 25
25 namespace { 26 namespace {
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 pPage->ConvertToIndirectObjectFor("Contents", pDocument); 199 pPage->ConvertToIndirectObjectFor("Contents", pDocument);
199 if (!pContentsArray) { 200 if (!pContentsArray) {
200 pContentsArray = pDocument->NewIndirect<CPDF_Array>(); 201 pContentsArray = pDocument->NewIndirect<CPDF_Array>();
201 CPDF_StreamAcc acc; 202 CPDF_StreamAcc acc;
202 acc.LoadAllData(pContentsStream); 203 acc.LoadAllData(pContentsStream);
203 CFX_ByteString sStream = "q\n"; 204 CFX_ByteString sStream = "q\n";
204 CFX_ByteString sBody = 205 CFX_ByteString sBody =
205 CFX_ByteString((const FX_CHAR*)acc.GetData(), acc.GetSize()); 206 CFX_ByteString((const FX_CHAR*)acc.GetData(), acc.GetSize());
206 sStream = sStream + sBody + "\nQ"; 207 sStream = sStream + sBody + "\nQ";
207 pContentsStream->SetData(sStream.raw_str(), sStream.GetLength()); 208 pContentsStream->SetData(sStream.raw_str(), sStream.GetLength());
208 pContentsArray->AddReference(pDocument, pContentsStream->GetObjNum()); 209 pContentsArray->AddNew<CPDF_Reference>(pDocument,
210 pContentsStream->GetObjNum());
209 pPage->SetReferenceFor("Contents", pDocument, pContentsArray); 211 pPage->SetReferenceFor("Contents", pDocument, pContentsArray);
210 } 212 }
211 if (!key.IsEmpty()) { 213 if (!key.IsEmpty()) {
212 pContentsArray->AddReference(pDocument, 214 pContentsArray->AddNew<CPDF_Reference>(
213 NewIndirectContentsStream(key, pDocument)); 215 pDocument, NewIndirectContentsStream(key, pDocument));
214 } 216 }
215 } 217 }
216 218
217 CFX_Matrix GetMatrix(CFX_FloatRect rcAnnot, 219 CFX_Matrix GetMatrix(CFX_FloatRect rcAnnot,
218 CFX_FloatRect rcStream, 220 CFX_FloatRect rcStream,
219 const CFX_Matrix& matrix) { 221 const CFX_Matrix& matrix) {
220 if (rcStream.IsEmpty()) 222 if (rcStream.IsEmpty())
221 return CFX_Matrix(); 223 return CFX_Matrix();
222 224
223 matrix.TransformRect(rcStream); 225 matrix.TransformRect(rcStream);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 rcMerger.right = std::min(rcMerger.right, rcOriginalMB.right); 265 rcMerger.right = std::min(rcMerger.right, rcOriginalMB.right);
264 rcMerger.bottom = std::max(rcMerger.bottom, rcOriginalMB.bottom); 266 rcMerger.bottom = std::max(rcMerger.bottom, rcOriginalMB.bottom);
265 rcMerger.top = std::min(rcMerger.top, rcOriginalMB.top); 267 rcMerger.top = std::min(rcMerger.top, rcOriginalMB.top);
266 if (pPageDict->KeyExist("ArtBox")) 268 if (pPageDict->KeyExist("ArtBox"))
267 rcOriginalCB = pPageDict->GetRectFor("ArtBox"); 269 rcOriginalCB = pPageDict->GetRectFor("ArtBox");
268 else 270 else
269 rcOriginalCB = rcOriginalMB; 271 rcOriginalCB = rcOriginalMB;
270 272
271 if (!rcOriginalMB.IsEmpty()) { 273 if (!rcOriginalMB.IsEmpty()) {
272 CPDF_Array* pMediaBox = new CPDF_Array(); 274 CPDF_Array* pMediaBox = new CPDF_Array();
273 pMediaBox->Add(new CPDF_Number(rcOriginalMB.left)); 275 pMediaBox->AddNew<CPDF_Number>(rcOriginalMB.left);
274 pMediaBox->Add(new CPDF_Number(rcOriginalMB.bottom)); 276 pMediaBox->AddNew<CPDF_Number>(rcOriginalMB.bottom);
275 pMediaBox->Add(new CPDF_Number(rcOriginalMB.right)); 277 pMediaBox->AddNew<CPDF_Number>(rcOriginalMB.right);
276 pMediaBox->Add(new CPDF_Number(rcOriginalMB.top)); 278 pMediaBox->AddNew<CPDF_Number>(rcOriginalMB.top);
277 pPageDict->SetFor("MediaBox", pMediaBox); 279 pPageDict->SetFor("MediaBox", pMediaBox);
278 } 280 }
279 281
280 if (!rcOriginalCB.IsEmpty()) { 282 if (!rcOriginalCB.IsEmpty()) {
281 CPDF_Array* pCropBox = new CPDF_Array(); 283 CPDF_Array* pCropBox = new CPDF_Array();
282 pCropBox->Add(new CPDF_Number(rcOriginalCB.left)); 284 pCropBox->AddNew<CPDF_Number>(rcOriginalCB.left);
283 pCropBox->Add(new CPDF_Number(rcOriginalCB.bottom)); 285 pCropBox->AddNew<CPDF_Number>(rcOriginalCB.bottom);
284 pCropBox->Add(new CPDF_Number(rcOriginalCB.right)); 286 pCropBox->AddNew<CPDF_Number>(rcOriginalCB.right);
285 pCropBox->Add(new CPDF_Number(rcOriginalCB.top)); 287 pCropBox->AddNew<CPDF_Number>(rcOriginalCB.top);
286 pPageDict->SetFor("ArtBox", pCropBox); 288 pPageDict->SetFor("ArtBox", pCropBox);
287 } 289 }
288 290
289 CPDF_Dictionary* pRes = pPageDict->GetDictFor("Resources"); 291 CPDF_Dictionary* pRes = pPageDict->GetDictFor("Resources");
290 if (!pRes) { 292 if (!pRes) {
291 pRes = new CPDF_Dictionary(pDocument->GetByteStringPool()); 293 pRes = new CPDF_Dictionary(pDocument->GetByteStringPool());
292 pPageDict->SetFor("Resources", pRes); 294 pPageDict->SetFor("Resources", pRes);
293 } 295 }
294 296
295 CPDF_Stream* pNewXObject = pDocument->NewIndirect<CPDF_Stream>( 297 CPDF_Stream* pNewXObject = pDocument->NewIndirect<CPDF_Stream>(
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 CFX_ByteString sTemp; 421 CFX_ByteString sTemp;
420 CFX_Matrix m = GetMatrix(rcAnnot, rcStream, matrix); 422 CFX_Matrix m = GetMatrix(rcAnnot, rcStream, matrix);
421 sTemp.Format("q %f 0 0 %f %f %f cm /%s Do Q\n", m.a, m.d, m.e, m.f, 423 sTemp.Format("q %f 0 0 %f %f %f cm /%s Do Q\n", m.a, m.d, m.e, m.f,
422 sFormName.c_str()); 424 sFormName.c_str());
423 sStream += sTemp; 425 sStream += sTemp;
424 pNewXObject->SetData(sStream.raw_str(), sStream.GetLength()); 426 pNewXObject->SetData(sStream.raw_str(), sStream.GetLength());
425 } 427 }
426 pPageDict->RemoveFor("Annots"); 428 pPageDict->RemoveFor("Annots");
427 return FLATTEN_SUCCESS; 429 return FLATTEN_SUCCESS;
428 } 430 }
OLDNEW
« no previous file with comments | « fpdfsdk/cpdfsdk_baannot.cpp ('k') | fpdfsdk/fpdf_transformpage.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698