OLD | NEW |
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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 "FPDF_PAGEOBJ_IMAGE/CPDF_PageObject::IMAGE mismatch"); | 50 "FPDF_PAGEOBJ_IMAGE/CPDF_PageObject::IMAGE mismatch"); |
51 static_assert(FPDF_PAGEOBJ_SHADING == CPDF_PageObject::SHADING, | 51 static_assert(FPDF_PAGEOBJ_SHADING == CPDF_PageObject::SHADING, |
52 "FPDF_PAGEOBJ_SHADING/CPDF_PageObject::SHADING mismatch"); | 52 "FPDF_PAGEOBJ_SHADING/CPDF_PageObject::SHADING mismatch"); |
53 static_assert(FPDF_PAGEOBJ_FORM == CPDF_PageObject::FORM, | 53 static_assert(FPDF_PAGEOBJ_FORM == CPDF_PageObject::FORM, |
54 "FPDF_PAGEOBJ_FORM/CPDF_PageObject::FORM mismatch"); | 54 "FPDF_PAGEOBJ_FORM/CPDF_PageObject::FORM mismatch"); |
55 | 55 |
56 bool IsPageObject(CPDF_Page* pPage) { | 56 bool IsPageObject(CPDF_Page* pPage) { |
57 if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type")) | 57 if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type")) |
58 return false; | 58 return false; |
59 | 59 |
60 CPDF_Object* pObject = pPage->m_pFormDict->GetObjectBy("Type")->GetDirect(); | 60 CPDF_Object* pObject = pPage->m_pFormDict->GetObjectFor("Type")->GetDirect(); |
61 return pObject && !pObject->GetString().Compare("Page"); | 61 return pObject && !pObject->GetString().Compare("Page"); |
62 } | 62 } |
63 | 63 |
64 } // namespace | 64 } // namespace |
65 | 65 |
66 DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_CreateNewDocument() { | 66 DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_CreateNewDocument() { |
67 CPDF_Document* pDoc = new CPDF_Document(nullptr); | 67 CPDF_Document* pDoc = new CPDF_Document(nullptr); |
68 pDoc->CreateNewDoc(); | 68 pDoc->CreateNewDoc(); |
69 time_t currentTime; | 69 time_t currentTime; |
70 | 70 |
71 CFX_ByteString DateStr; | 71 CFX_ByteString DateStr; |
72 | 72 |
73 if (FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS)) { | 73 if (FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS)) { |
74 if (-1 != time(¤tTime)) { | 74 if (-1 != time(¤tTime)) { |
75 tm* pTM = localtime(¤tTime); | 75 tm* pTM = localtime(¤tTime); |
76 if (pTM) { | 76 if (pTM) { |
77 DateStr.Format("D:%04d%02d%02d%02d%02d%02d", pTM->tm_year + 1900, | 77 DateStr.Format("D:%04d%02d%02d%02d%02d%02d", pTM->tm_year + 1900, |
78 pTM->tm_mon + 1, pTM->tm_mday, pTM->tm_hour, pTM->tm_min, | 78 pTM->tm_mon + 1, pTM->tm_mday, pTM->tm_hour, pTM->tm_min, |
79 pTM->tm_sec); | 79 pTM->tm_sec); |
80 } | 80 } |
81 } | 81 } |
82 } | 82 } |
83 | 83 |
84 CPDF_Dictionary* pInfoDict = nullptr; | 84 CPDF_Dictionary* pInfoDict = nullptr; |
85 pInfoDict = pDoc->GetInfo(); | 85 pInfoDict = pDoc->GetInfo(); |
86 if (pInfoDict) { | 86 if (pInfoDict) { |
87 if (FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS)) | 87 if (FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS)) |
88 pInfoDict->SetAt("CreationDate", new CPDF_String(DateStr, FALSE)); | 88 pInfoDict->SetFor("CreationDate", new CPDF_String(DateStr, FALSE)); |
89 pInfoDict->SetAt("Creator", new CPDF_String(L"PDFium")); | 89 pInfoDict->SetFor("Creator", new CPDF_String(L"PDFium")); |
90 } | 90 } |
91 | 91 |
92 return FPDFDocumentFromCPDFDocument(pDoc); | 92 return FPDFDocumentFromCPDFDocument(pDoc); |
93 } | 93 } |
94 | 94 |
95 DLLEXPORT void STDCALL FPDFPage_Delete(FPDF_DOCUMENT document, int page_index) { | 95 DLLEXPORT void STDCALL FPDFPage_Delete(FPDF_DOCUMENT document, int page_index) { |
96 if (UnderlyingDocumentType* pDoc = UnderlyingFromFPDFDocument(document)) | 96 if (UnderlyingDocumentType* pDoc = UnderlyingFromFPDFDocument(document)) |
97 pDoc->DeletePage(page_index); | 97 pDoc->DeletePage(page_index); |
98 } | 98 } |
99 | 99 |
100 DLLEXPORT FPDF_PAGE STDCALL FPDFPage_New(FPDF_DOCUMENT document, | 100 DLLEXPORT FPDF_PAGE STDCALL FPDFPage_New(FPDF_DOCUMENT document, |
101 int page_index, | 101 int page_index, |
102 double width, | 102 double width, |
103 double height) { | 103 double height) { |
104 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); | 104 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
105 if (!pDoc) | 105 if (!pDoc) |
106 return nullptr; | 106 return nullptr; |
107 | 107 |
108 page_index = std::min(std::max(page_index, 0), pDoc->GetPageCount()); | 108 page_index = std::min(std::max(page_index, 0), pDoc->GetPageCount()); |
109 CPDF_Dictionary* pPageDict = pDoc->CreateNewPage(page_index); | 109 CPDF_Dictionary* pPageDict = pDoc->CreateNewPage(page_index); |
110 if (!pPageDict) | 110 if (!pPageDict) |
111 return nullptr; | 111 return nullptr; |
112 | 112 |
113 CPDF_Array* pMediaBoxArray = new CPDF_Array; | 113 CPDF_Array* pMediaBoxArray = new CPDF_Array; |
114 pMediaBoxArray->Add(new CPDF_Number(0)); | 114 pMediaBoxArray->Add(new CPDF_Number(0)); |
115 pMediaBoxArray->Add(new CPDF_Number(0)); | 115 pMediaBoxArray->Add(new CPDF_Number(0)); |
116 pMediaBoxArray->Add(new CPDF_Number(FX_FLOAT(width))); | 116 pMediaBoxArray->Add(new CPDF_Number(FX_FLOAT(width))); |
117 pMediaBoxArray->Add(new CPDF_Number(FX_FLOAT(height))); | 117 pMediaBoxArray->Add(new CPDF_Number(FX_FLOAT(height))); |
118 | 118 |
119 pPageDict->SetAt("MediaBox", pMediaBoxArray); | 119 pPageDict->SetFor("MediaBox", pMediaBoxArray); |
120 pPageDict->SetAt("Rotate", new CPDF_Number(0)); | 120 pPageDict->SetFor("Rotate", new CPDF_Number(0)); |
121 pPageDict->SetAt("Resources", new CPDF_Dictionary); | 121 pPageDict->SetFor("Resources", new CPDF_Dictionary); |
122 | 122 |
123 #ifdef PDF_ENABLE_XFA | 123 #ifdef PDF_ENABLE_XFA |
124 CPDFXFA_Page* pPage = | 124 CPDFXFA_Page* pPage = |
125 new CPDFXFA_Page((CPDFXFA_Document*)document, page_index); | 125 new CPDFXFA_Page((CPDFXFA_Document*)document, page_index); |
126 pPage->LoadPDFPage(pPageDict); | 126 pPage->LoadPDFPage(pPageDict); |
127 #else // PDF_ENABLE_XFA | 127 #else // PDF_ENABLE_XFA |
128 CPDF_Page* pPage = new CPDF_Page(pDoc, pPageDict, true); | 128 CPDF_Page* pPage = new CPDF_Page(pDoc, pPageDict, true); |
129 pPage->ParseContent(); | 129 pPage->ParseContent(); |
130 #endif // PDF_ENABLE_XFA | 130 #endif // PDF_ENABLE_XFA |
131 | 131 |
132 return pPage; | 132 return pPage; |
133 } | 133 } |
134 | 134 |
135 DLLEXPORT int STDCALL FPDFPage_GetRotation(FPDF_PAGE page) { | 135 DLLEXPORT int STDCALL FPDFPage_GetRotation(FPDF_PAGE page) { |
136 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); | 136 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
137 if (!IsPageObject(pPage)) | 137 if (!IsPageObject(pPage)) |
138 return -1; | 138 return -1; |
139 | 139 |
140 CPDF_Dictionary* pDict = pPage->m_pFormDict; | 140 CPDF_Dictionary* pDict = pPage->m_pFormDict; |
141 while (pDict) { | 141 while (pDict) { |
142 if (pDict->KeyExist("Rotate")) { | 142 if (pDict->KeyExist("Rotate")) { |
143 CPDF_Object* pRotateObj = pDict->GetObjectBy("Rotate")->GetDirect(); | 143 CPDF_Object* pRotateObj = pDict->GetObjectFor("Rotate")->GetDirect(); |
144 return pRotateObj ? pRotateObj->GetInteger() / 90 : 0; | 144 return pRotateObj ? pRotateObj->GetInteger() / 90 : 0; |
145 } | 145 } |
146 if (!pDict->KeyExist("Parent")) | 146 if (!pDict->KeyExist("Parent")) |
147 break; | 147 break; |
148 | 148 |
149 pDict = ToDictionary(pDict->GetObjectBy("Parent")->GetDirect()); | 149 pDict = ToDictionary(pDict->GetObjectFor("Parent")->GetDirect()); |
150 } | 150 } |
151 | 151 |
152 return 0; | 152 return 0; |
153 } | 153 } |
154 | 154 |
155 DLLEXPORT void STDCALL FPDFPage_InsertObject(FPDF_PAGE page, | 155 DLLEXPORT void STDCALL FPDFPage_InsertObject(FPDF_PAGE page, |
156 FPDF_PAGEOBJECT page_obj) { | 156 FPDF_PAGEOBJECT page_obj) { |
157 CPDF_PageObject* pPageObj = reinterpret_cast<CPDF_PageObject*>(page_obj); | 157 CPDF_PageObject* pPageObj = reinterpret_cast<CPDF_PageObject*>(page_obj); |
158 if (!pPageObj) | 158 if (!pPageObj) |
159 return; | 159 return; |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 return; | 287 return; |
288 | 288 |
289 CPDF_AnnotList AnnotList(pPage); | 289 CPDF_AnnotList AnnotList(pPage); |
290 for (size_t i = 0; i < AnnotList.Count(); ++i) { | 290 for (size_t i = 0; i < AnnotList.Count(); ++i) { |
291 CPDF_Annot* pAnnot = AnnotList.GetAt(i); | 291 CPDF_Annot* pAnnot = AnnotList.GetAt(i); |
292 // transformAnnots Rectangle | 292 // transformAnnots Rectangle |
293 CFX_FloatRect rect = pAnnot->GetRect(); | 293 CFX_FloatRect rect = pAnnot->GetRect(); |
294 CFX_Matrix matrix((FX_FLOAT)a, (FX_FLOAT)b, (FX_FLOAT)c, (FX_FLOAT)d, | 294 CFX_Matrix matrix((FX_FLOAT)a, (FX_FLOAT)b, (FX_FLOAT)c, (FX_FLOAT)d, |
295 (FX_FLOAT)e, (FX_FLOAT)f); | 295 (FX_FLOAT)e, (FX_FLOAT)f); |
296 rect.Transform(&matrix); | 296 rect.Transform(&matrix); |
297 CPDF_Array* pRectArray = pAnnot->GetAnnotDict()->GetArrayBy("Rect"); | 297 CPDF_Array* pRectArray = pAnnot->GetAnnotDict()->GetArrayFor("Rect"); |
298 if (!pRectArray) | 298 if (!pRectArray) |
299 pRectArray = new CPDF_Array; | 299 pRectArray = new CPDF_Array; |
300 pRectArray->SetAt(0, new CPDF_Number(rect.left)); | 300 pRectArray->SetAt(0, new CPDF_Number(rect.left)); |
301 pRectArray->SetAt(1, new CPDF_Number(rect.bottom)); | 301 pRectArray->SetAt(1, new CPDF_Number(rect.bottom)); |
302 pRectArray->SetAt(2, new CPDF_Number(rect.right)); | 302 pRectArray->SetAt(2, new CPDF_Number(rect.right)); |
303 pRectArray->SetAt(3, new CPDF_Number(rect.top)); | 303 pRectArray->SetAt(3, new CPDF_Number(rect.top)); |
304 pAnnot->GetAnnotDict()->SetAt("Rect", pRectArray); | 304 pAnnot->GetAnnotDict()->SetFor("Rect", pRectArray); |
305 | 305 |
306 // Transform AP's rectangle | 306 // Transform AP's rectangle |
307 // To Do | 307 // To Do |
308 } | 308 } |
309 } | 309 } |
310 | 310 |
311 DLLEXPORT void STDCALL FPDFPage_SetRotation(FPDF_PAGE page, int rotate) { | 311 DLLEXPORT void STDCALL FPDFPage_SetRotation(FPDF_PAGE page, int rotate) { |
312 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); | 312 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
313 if (!IsPageObject(pPage)) | 313 if (!IsPageObject(pPage)) |
314 return; | 314 return; |
315 | 315 |
316 CPDF_Dictionary* pDict = pPage->m_pFormDict; | 316 CPDF_Dictionary* pDict = pPage->m_pFormDict; |
317 rotate %= 4; | 317 rotate %= 4; |
318 pDict->SetAt("Rotate", new CPDF_Number(rotate * 90)); | 318 pDict->SetFor("Rotate", new CPDF_Number(rotate * 90)); |
319 } | 319 } |
OLD | NEW |