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

Side by Side Diff: fpdfsdk/fpdfeditpage.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/fpdfdoc_unittest.cpp ('k') | fpdfsdk/fpdfppo.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_edit.h" 7 #include "public/fpdf_edit.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); 103 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
104 if (!pDoc) 104 if (!pDoc)
105 return nullptr; 105 return nullptr;
106 106
107 page_index = std::min(std::max(page_index, 0), pDoc->GetPageCount()); 107 page_index = std::min(std::max(page_index, 0), pDoc->GetPageCount());
108 CPDF_Dictionary* pPageDict = pDoc->CreateNewPage(page_index); 108 CPDF_Dictionary* pPageDict = pDoc->CreateNewPage(page_index);
109 if (!pPageDict) 109 if (!pPageDict)
110 return nullptr; 110 return nullptr;
111 111
112 CPDF_Array* pMediaBoxArray = new CPDF_Array; 112 CPDF_Array* pMediaBoxArray = new CPDF_Array;
113 pMediaBoxArray->Add(new CPDF_Number(0)); 113 pMediaBoxArray->AddNew<CPDF_Number>(0);
114 pMediaBoxArray->Add(new CPDF_Number(0)); 114 pMediaBoxArray->AddNew<CPDF_Number>(0);
115 pMediaBoxArray->Add(new CPDF_Number(FX_FLOAT(width))); 115 pMediaBoxArray->AddNew<CPDF_Number>(static_cast<FX_FLOAT>(width));
116 pMediaBoxArray->Add(new CPDF_Number(FX_FLOAT(height))); 116 pMediaBoxArray->AddNew<CPDF_Number>(static_cast<FX_FLOAT>(height));
117 pPageDict->SetFor("MediaBox", pMediaBoxArray); 117 pPageDict->SetFor("MediaBox", pMediaBoxArray);
118 pPageDict->SetFor("Rotate", new CPDF_Number(0)); 118 pPageDict->SetFor("Rotate", new CPDF_Number(0));
119 pPageDict->SetFor("Resources", 119 pPageDict->SetFor("Resources",
120 new CPDF_Dictionary(pDoc->GetByteStringPool())); 120 new CPDF_Dictionary(pDoc->GetByteStringPool()));
121 121
122 #ifdef PDF_ENABLE_XFA 122 #ifdef PDF_ENABLE_XFA
123 CPDFXFA_Page* pPage = 123 CPDFXFA_Page* pPage =
124 new CPDFXFA_Page(static_cast<CPDFXFA_Context*>(document), page_index); 124 new CPDFXFA_Page(static_cast<CPDFXFA_Context*>(document), page_index);
125 pPage->LoadPDFPage(pPageDict); 125 pPage->LoadPDFPage(pPageDict);
126 #else // PDF_ENABLE_XFA 126 #else // PDF_ENABLE_XFA
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 CFX_FloatRect rect = pAnnot->GetRect(); // transformAnnots Rectangle 291 CFX_FloatRect rect = pAnnot->GetRect(); // transformAnnots Rectangle
292 CFX_Matrix matrix((FX_FLOAT)a, (FX_FLOAT)b, (FX_FLOAT)c, (FX_FLOAT)d, 292 CFX_Matrix matrix((FX_FLOAT)a, (FX_FLOAT)b, (FX_FLOAT)c, (FX_FLOAT)d,
293 (FX_FLOAT)e, (FX_FLOAT)f); 293 (FX_FLOAT)e, (FX_FLOAT)f);
294 rect.Transform(&matrix); 294 rect.Transform(&matrix);
295 295
296 CPDF_Array* pRectArray = pAnnot->GetAnnotDict()->GetArrayFor("Rect"); 296 CPDF_Array* pRectArray = pAnnot->GetAnnotDict()->GetArrayFor("Rect");
297 if (!pRectArray) { 297 if (!pRectArray) {
298 pRectArray = new CPDF_Array; 298 pRectArray = new CPDF_Array;
299 pAnnot->GetAnnotDict()->SetFor("Rect", pRectArray); 299 pAnnot->GetAnnotDict()->SetFor("Rect", pRectArray);
300 } 300 }
301 pRectArray->SetAt(0, new CPDF_Number(rect.left)); 301 pRectArray->SetNewAt<CPDF_Number>(0, rect.left);
302 pRectArray->SetAt(1, new CPDF_Number(rect.bottom)); 302 pRectArray->SetNewAt<CPDF_Number>(1, rect.bottom);
303 pRectArray->SetAt(2, new CPDF_Number(rect.right)); 303 pRectArray->SetNewAt<CPDF_Number>(2, rect.right);
304 pRectArray->SetAt(3, new CPDF_Number(rect.top)); 304 pRectArray->SetNewAt<CPDF_Number>(3, rect.top);
305 305
306 // TODO: Transform AP's rectangle 306 // TODO: Transform AP's rectangle
307 } 307 }
308 } 308 }
309 309
310 DLLEXPORT void STDCALL FPDFPage_SetRotation(FPDF_PAGE page, int rotate) { 310 DLLEXPORT void STDCALL FPDFPage_SetRotation(FPDF_PAGE page, int rotate) {
311 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); 311 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
312 if (!IsPageObject(pPage)) 312 if (!IsPageObject(pPage))
313 return; 313 return;
314 314
315 CPDF_Dictionary* pDict = pPage->m_pFormDict; 315 CPDF_Dictionary* pDict = pPage->m_pFormDict;
316 rotate %= 4; 316 rotate %= 4;
317 pDict->SetFor("Rotate", new CPDF_Number(rotate * 90)); 317 pDict->SetFor("Rotate", new CPDF_Number(rotate * 90));
318 } 318 }
OLDNEW
« no previous file with comments | « fpdfsdk/fpdfdoc_unittest.cpp ('k') | fpdfsdk/fpdfppo.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698