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

Side by Side Diff: fpdfsdk/fpdfeditpage.cpp

Issue 2510223002: Make CPDF_Dictionary use unique pointers. (Closed)
Patch Set: rebase 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 DateStr.Format("D:%04d%02d%02d%02d%02d%02d", pTM->tm_year + 1900, 76 DateStr.Format("D:%04d%02d%02d%02d%02d%02d", pTM->tm_year + 1900,
77 pTM->tm_mon + 1, pTM->tm_mday, pTM->tm_hour, pTM->tm_min, 77 pTM->tm_mon + 1, pTM->tm_mday, pTM->tm_hour, pTM->tm_min,
78 pTM->tm_sec); 78 pTM->tm_sec);
79 } 79 }
80 } 80 }
81 } 81 }
82 82
83 CPDF_Dictionary* pInfoDict = nullptr; 83 CPDF_Dictionary* pInfoDict = nullptr;
84 pInfoDict = pDoc->GetInfo(); 84 pInfoDict = pDoc->GetInfo();
85 if (pInfoDict) { 85 if (pInfoDict) {
86 if (FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS)) { 86 if (FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS))
87 pInfoDict->SetFor("CreationDate", 87 pInfoDict->SetNewFor<CPDF_String>("CreationDate", DateStr, false);
88 new CPDF_String(nullptr, DateStr, false)); 88 pInfoDict->SetNewFor<CPDF_String>("Creator", L"PDFium");
89 }
90 pInfoDict->SetFor("Creator", new CPDF_String(L"PDFium"));
91 } 89 }
92 90
93 return FPDFDocumentFromCPDFDocument(pDoc); 91 return FPDFDocumentFromCPDFDocument(pDoc);
94 } 92 }
95 93
96 DLLEXPORT void STDCALL FPDFPage_Delete(FPDF_DOCUMENT document, int page_index) { 94 DLLEXPORT void STDCALL FPDFPage_Delete(FPDF_DOCUMENT document, int page_index) {
97 if (UnderlyingDocumentType* pDoc = UnderlyingFromFPDFDocument(document)) 95 if (UnderlyingDocumentType* pDoc = UnderlyingFromFPDFDocument(document))
98 pDoc->DeletePage(page_index); 96 pDoc->DeletePage(page_index);
99 } 97 }
100 98
101 DLLEXPORT FPDF_PAGE STDCALL FPDFPage_New(FPDF_DOCUMENT document, 99 DLLEXPORT FPDF_PAGE STDCALL FPDFPage_New(FPDF_DOCUMENT document,
102 int page_index, 100 int page_index,
103 double width, 101 double width,
104 double height) { 102 double height) {
105 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); 103 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
106 if (!pDoc) 104 if (!pDoc)
107 return nullptr; 105 return nullptr;
108 106
109 page_index = std::min(std::max(page_index, 0), pDoc->GetPageCount()); 107 page_index = std::min(std::max(page_index, 0), pDoc->GetPageCount());
110 CPDF_Dictionary* pPageDict = pDoc->CreateNewPage(page_index); 108 CPDF_Dictionary* pPageDict = pDoc->CreateNewPage(page_index);
111 if (!pPageDict) 109 if (!pPageDict)
112 return nullptr; 110 return nullptr;
113 111
114 CPDF_Array* pMediaBoxArray = new CPDF_Array; 112 CPDF_Array* pMediaBoxArray = pPageDict->SetNewFor<CPDF_Array>("MediaBox");
115 pMediaBoxArray->AddNew<CPDF_Number>(0); 113 pMediaBoxArray->AddNew<CPDF_Number>(0);
116 pMediaBoxArray->AddNew<CPDF_Number>(0); 114 pMediaBoxArray->AddNew<CPDF_Number>(0);
117 pMediaBoxArray->AddNew<CPDF_Number>(static_cast<FX_FLOAT>(width)); 115 pMediaBoxArray->AddNew<CPDF_Number>(static_cast<FX_FLOAT>(width));
118 pMediaBoxArray->AddNew<CPDF_Number>(static_cast<FX_FLOAT>(height)); 116 pMediaBoxArray->AddNew<CPDF_Number>(static_cast<FX_FLOAT>(height));
119 pPageDict->SetFor("MediaBox", pMediaBoxArray); 117 pPageDict->SetNewFor<CPDF_Number>("Rotate", 0);
120 pPageDict->SetFor("Rotate", new CPDF_Number(0)); 118 pPageDict->SetNewFor<CPDF_Dictionary>("Resources");
121 pPageDict->SetFor("Resources",
122 new CPDF_Dictionary(pDoc->GetByteStringPool()));
123 119
124 #ifdef PDF_ENABLE_XFA 120 #ifdef PDF_ENABLE_XFA
125 CPDFXFA_Page* pPage = 121 CPDFXFA_Page* pPage =
126 new CPDFXFA_Page(static_cast<CPDFXFA_Context*>(document), page_index); 122 new CPDFXFA_Page(static_cast<CPDFXFA_Context*>(document), page_index);
127 pPage->LoadPDFPage(pPageDict); 123 pPage->LoadPDFPage(pPageDict);
128 #else // PDF_ENABLE_XFA 124 #else // PDF_ENABLE_XFA
129 CPDF_Page* pPage = new CPDF_Page(pDoc, pPageDict, true); 125 CPDF_Page* pPage = new CPDF_Page(pDoc, pPageDict, true);
130 pPage->ParseContent(); 126 pPage->ParseContent();
131 #endif // PDF_ENABLE_XFA 127 #endif // PDF_ENABLE_XFA
132 128
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 285
290 CPDF_AnnotList AnnotList(pPage); 286 CPDF_AnnotList AnnotList(pPage);
291 for (size_t i = 0; i < AnnotList.Count(); ++i) { 287 for (size_t i = 0; i < AnnotList.Count(); ++i) {
292 CPDF_Annot* pAnnot = AnnotList.GetAt(i); 288 CPDF_Annot* pAnnot = AnnotList.GetAt(i);
293 CFX_FloatRect rect = pAnnot->GetRect(); // transformAnnots Rectangle 289 CFX_FloatRect rect = pAnnot->GetRect(); // transformAnnots Rectangle
294 CFX_Matrix matrix((FX_FLOAT)a, (FX_FLOAT)b, (FX_FLOAT)c, (FX_FLOAT)d, 290 CFX_Matrix matrix((FX_FLOAT)a, (FX_FLOAT)b, (FX_FLOAT)c, (FX_FLOAT)d,
295 (FX_FLOAT)e, (FX_FLOAT)f); 291 (FX_FLOAT)e, (FX_FLOAT)f);
296 rect.Transform(&matrix); 292 rect.Transform(&matrix);
297 293
298 CPDF_Array* pRectArray = pAnnot->GetAnnotDict()->GetArrayFor("Rect"); 294 CPDF_Array* pRectArray = pAnnot->GetAnnotDict()->GetArrayFor("Rect");
299 if (!pRectArray) { 295 if (!pRectArray)
300 pRectArray = new CPDF_Array; 296 pRectArray = pAnnot->GetAnnotDict()->SetNewFor<CPDF_Array>("Rect");
301 pAnnot->GetAnnotDict()->SetFor("Rect", pRectArray); 297
302 }
303 pRectArray->SetNewAt<CPDF_Number>(0, rect.left); 298 pRectArray->SetNewAt<CPDF_Number>(0, rect.left);
304 pRectArray->SetNewAt<CPDF_Number>(1, rect.bottom); 299 pRectArray->SetNewAt<CPDF_Number>(1, rect.bottom);
305 pRectArray->SetNewAt<CPDF_Number>(2, rect.right); 300 pRectArray->SetNewAt<CPDF_Number>(2, rect.right);
306 pRectArray->SetNewAt<CPDF_Number>(3, rect.top); 301 pRectArray->SetNewAt<CPDF_Number>(3, rect.top);
307 302
308 // TODO: Transform AP's rectangle 303 // TODO: Transform AP's rectangle
309 } 304 }
310 } 305 }
311 306
312 DLLEXPORT void STDCALL FPDFPage_SetRotation(FPDF_PAGE page, int rotate) { 307 DLLEXPORT void STDCALL FPDFPage_SetRotation(FPDF_PAGE page, int rotate) {
313 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); 308 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
314 if (!IsPageObject(pPage)) 309 if (!IsPageObject(pPage))
315 return; 310 return;
316 311
317 CPDF_Dictionary* pDict = pPage->m_pFormDict; 312 CPDF_Dictionary* pDict = pPage->m_pFormDict;
318 rotate %= 4; 313 rotate %= 4;
319 pDict->SetFor("Rotate", new CPDF_Number(rotate * 90)); 314 pDict->SetNewFor<CPDF_Number>("Rotate", rotate * 90);
320 } 315 }
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