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_ppo.h" | 7 #include "public/fpdf_ppo.h" |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <memory> | 10 #include <memory> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
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_name.h" | 15 #include "core/fpdfapi/parser/cpdf_name.h" |
16 #include "core/fpdfapi/parser/cpdf_number.h" | 16 #include "core/fpdfapi/parser/cpdf_number.h" |
17 #include "core/fpdfapi/parser/cpdf_reference.h" | 17 #include "core/fpdfapi/parser/cpdf_reference.h" |
18 #include "core/fpdfapi/parser/cpdf_stream.h" | 18 #include "core/fpdfapi/parser/cpdf_stream.h" |
19 #include "core/fpdfapi/parser/cpdf_string.h" | 19 #include "core/fpdfapi/parser/cpdf_string.h" |
20 #include "fpdfsdk/fsdk_define.h" | 20 #include "fpdfsdk/fsdk_define.h" |
21 #include "third_party/base/stl_util.h" | 21 #include "third_party/base/stl_util.h" |
22 | 22 |
23 class CPDF_PageOrganizer { | 23 class CPDF_PageOrganizer { |
24 public: | 24 public: |
25 using ObjectNumberMap = std::map<uint32_t, uint32_t>; | 25 using ObjectNumberMap = std::map<uint32_t, uint32_t>; |
26 CPDF_PageOrganizer(); | 26 CPDF_PageOrganizer(); |
27 ~CPDF_PageOrganizer(); | 27 ~CPDF_PageOrganizer(); |
28 | 28 |
29 FX_BOOL PDFDocInit(CPDF_Document* pDestPDFDoc, CPDF_Document* pSrcPDFDoc); | 29 bool PDFDocInit(CPDF_Document* pDestPDFDoc, CPDF_Document* pSrcPDFDoc); |
30 FX_BOOL ExportPage(CPDF_Document* pSrcPDFDoc, | 30 bool ExportPage(CPDF_Document* pSrcPDFDoc, |
31 std::vector<uint16_t>* pPageNums, | 31 std::vector<uint16_t>* pPageNums, |
32 CPDF_Document* pDestPDFDoc, | 32 CPDF_Document* pDestPDFDoc, |
33 int nIndex); | 33 int nIndex); |
34 CPDF_Object* PageDictGetInheritableTag(CPDF_Dictionary* pDict, | 34 CPDF_Object* PageDictGetInheritableTag(CPDF_Dictionary* pDict, |
35 const CFX_ByteString& bsSrctag); | 35 const CFX_ByteString& bsSrctag); |
36 FX_BOOL UpdateReference(CPDF_Object* pObj, | 36 bool UpdateReference(CPDF_Object* pObj, |
37 CPDF_Document* pDoc, | 37 CPDF_Document* pDoc, |
38 ObjectNumberMap* pObjNumberMap); | 38 ObjectNumberMap* pObjNumberMap); |
39 uint32_t GetNewObjId(CPDF_Document* pDoc, | 39 uint32_t GetNewObjId(CPDF_Document* pDoc, |
40 ObjectNumberMap* pObjNumberMap, | 40 ObjectNumberMap* pObjNumberMap, |
41 CPDF_Reference* pRef); | 41 CPDF_Reference* pRef); |
42 }; | 42 }; |
43 | 43 |
44 CPDF_PageOrganizer::CPDF_PageOrganizer() {} | 44 CPDF_PageOrganizer::CPDF_PageOrganizer() {} |
45 | 45 |
46 CPDF_PageOrganizer::~CPDF_PageOrganizer() {} | 46 CPDF_PageOrganizer::~CPDF_PageOrganizer() {} |
47 | 47 |
48 FX_BOOL CPDF_PageOrganizer::PDFDocInit(CPDF_Document* pDestPDFDoc, | 48 bool CPDF_PageOrganizer::PDFDocInit(CPDF_Document* pDestPDFDoc, |
49 CPDF_Document* pSrcPDFDoc) { | 49 CPDF_Document* pSrcPDFDoc) { |
50 if (!pDestPDFDoc || !pSrcPDFDoc) | 50 if (!pDestPDFDoc || !pSrcPDFDoc) |
51 return FALSE; | 51 return false; |
52 | 52 |
53 CPDF_Dictionary* pNewRoot = pDestPDFDoc->GetRoot(); | 53 CPDF_Dictionary* pNewRoot = pDestPDFDoc->GetRoot(); |
54 if (!pNewRoot) | 54 if (!pNewRoot) |
55 return FALSE; | 55 return false; |
56 | 56 |
57 CPDF_Dictionary* DInfoDict = pDestPDFDoc->GetInfo(); | 57 CPDF_Dictionary* DInfoDict = pDestPDFDoc->GetInfo(); |
58 if (!DInfoDict) | 58 if (!DInfoDict) |
59 return FALSE; | 59 return false; |
60 | 60 |
61 CFX_ByteString producerstr; | 61 CFX_ByteString producerstr; |
62 producerstr.Format("PDFium"); | 62 producerstr.Format("PDFium"); |
63 DInfoDict->SetFor("Producer", new CPDF_String(producerstr, FALSE)); | 63 DInfoDict->SetFor("Producer", new CPDF_String(producerstr, false)); |
64 | 64 |
65 CFX_ByteString cbRootType = pNewRoot->GetStringFor("Type", ""); | 65 CFX_ByteString cbRootType = pNewRoot->GetStringFor("Type", ""); |
66 if (cbRootType.IsEmpty()) | 66 if (cbRootType.IsEmpty()) |
67 pNewRoot->SetFor("Type", new CPDF_Name("Catalog")); | 67 pNewRoot->SetFor("Type", new CPDF_Name("Catalog")); |
68 | 68 |
69 CPDF_Object* pElement = pNewRoot->GetObjectFor("Pages"); | 69 CPDF_Object* pElement = pNewRoot->GetObjectFor("Pages"); |
70 CPDF_Dictionary* pNewPages = | 70 CPDF_Dictionary* pNewPages = |
71 pElement ? ToDictionary(pElement->GetDirect()) : nullptr; | 71 pElement ? ToDictionary(pElement->GetDirect()) : nullptr; |
72 if (!pNewPages) { | 72 if (!pNewPages) { |
73 pNewPages = new CPDF_Dictionary(pDestPDFDoc->GetByteStringPool()); | 73 pNewPages = new CPDF_Dictionary(pDestPDFDoc->GetByteStringPool()); |
74 pNewRoot->SetReferenceFor("Pages", pDestPDFDoc, | 74 pNewRoot->SetReferenceFor("Pages", pDestPDFDoc, |
75 pDestPDFDoc->AddIndirectObject(pNewPages)); | 75 pDestPDFDoc->AddIndirectObject(pNewPages)); |
76 } | 76 } |
77 | 77 |
78 CFX_ByteString cbPageType = pNewPages->GetStringFor("Type", ""); | 78 CFX_ByteString cbPageType = pNewPages->GetStringFor("Type", ""); |
79 if (cbPageType == "") { | 79 if (cbPageType == "") { |
80 pNewPages->SetFor("Type", new CPDF_Name("Pages")); | 80 pNewPages->SetFor("Type", new CPDF_Name("Pages")); |
81 } | 81 } |
82 | 82 |
83 if (!pNewPages->GetArrayFor("Kids")) { | 83 if (!pNewPages->GetArrayFor("Kids")) { |
84 pNewPages->SetIntegerFor("Count", 0); | 84 pNewPages->SetIntegerFor("Count", 0); |
85 pNewPages->SetReferenceFor("Kids", pDestPDFDoc, | 85 pNewPages->SetReferenceFor("Kids", pDestPDFDoc, |
86 pDestPDFDoc->AddIndirectObject(new CPDF_Array)); | 86 pDestPDFDoc->AddIndirectObject(new CPDF_Array)); |
87 } | 87 } |
88 | 88 |
89 return TRUE; | 89 return true; |
90 } | 90 } |
91 | 91 |
92 FX_BOOL CPDF_PageOrganizer::ExportPage(CPDF_Document* pSrcPDFDoc, | 92 bool CPDF_PageOrganizer::ExportPage(CPDF_Document* pSrcPDFDoc, |
93 std::vector<uint16_t>* pPageNums, | 93 std::vector<uint16_t>* pPageNums, |
94 CPDF_Document* pDestPDFDoc, | 94 CPDF_Document* pDestPDFDoc, |
95 int nIndex) { | 95 int nIndex) { |
96 int curpage = nIndex; | 96 int curpage = nIndex; |
97 std::unique_ptr<ObjectNumberMap> pObjNumberMap(new ObjectNumberMap); | 97 std::unique_ptr<ObjectNumberMap> pObjNumberMap(new ObjectNumberMap); |
98 int nSize = pdfium::CollectionSize<int>(*pPageNums); | 98 int nSize = pdfium::CollectionSize<int>(*pPageNums); |
99 for (int i = 0; i < nSize; ++i) { | 99 for (int i = 0; i < nSize; ++i) { |
100 CPDF_Dictionary* pCurPageDict = pDestPDFDoc->CreateNewPage(curpage); | 100 CPDF_Dictionary* pCurPageDict = pDestPDFDoc->CreateNewPage(curpage); |
101 CPDF_Dictionary* pSrcPageDict = pSrcPDFDoc->GetPage(pPageNums->at(i) - 1); | 101 CPDF_Dictionary* pSrcPageDict = pSrcPDFDoc->GetPage(pPageNums->at(i) - 1); |
102 if (!pSrcPageDict || !pCurPageDict) | 102 if (!pSrcPageDict || !pCurPageDict) |
103 return FALSE; | 103 return false; |
104 | 104 |
105 // Clone the page dictionary | 105 // Clone the page dictionary |
106 for (const auto& it : *pSrcPageDict) { | 106 for (const auto& it : *pSrcPageDict) { |
107 const CFX_ByteString& cbSrcKeyStr = it.first; | 107 const CFX_ByteString& cbSrcKeyStr = it.first; |
108 CPDF_Object* pObj = it.second; | 108 CPDF_Object* pObj = it.second; |
109 if (cbSrcKeyStr.Compare(("Type")) && cbSrcKeyStr.Compare(("Parent"))) { | 109 if (cbSrcKeyStr.Compare(("Type")) && cbSrcKeyStr.Compare(("Parent"))) { |
110 if (pCurPageDict->KeyExist(cbSrcKeyStr)) | 110 if (pCurPageDict->KeyExist(cbSrcKeyStr)) |
111 pCurPageDict->RemoveFor(cbSrcKeyStr); | 111 pCurPageDict->RemoveFor(cbSrcKeyStr); |
112 pCurPageDict->SetFor(cbSrcKeyStr, pObj->Clone()); | 112 pCurPageDict->SetFor(cbSrcKeyStr, pObj->Clone()); |
113 } | 113 } |
(...skipping 20 matching lines...) Expand all Loading... |
134 pCurPageDict->SetFor("MediaBox", pArray); | 134 pCurPageDict->SetFor("MediaBox", pArray); |
135 } | 135 } |
136 } else { | 136 } else { |
137 pCurPageDict->SetFor("MediaBox", pInheritable->Clone()); | 137 pCurPageDict->SetFor("MediaBox", pInheritable->Clone()); |
138 } | 138 } |
139 } | 139 } |
140 // 2 Resources //required | 140 // 2 Resources //required |
141 if (!pCurPageDict->KeyExist("Resources")) { | 141 if (!pCurPageDict->KeyExist("Resources")) { |
142 pInheritable = PageDictGetInheritableTag(pSrcPageDict, "Resources"); | 142 pInheritable = PageDictGetInheritableTag(pSrcPageDict, "Resources"); |
143 if (!pInheritable) | 143 if (!pInheritable) |
144 return FALSE; | 144 return false; |
145 pCurPageDict->SetFor("Resources", pInheritable->Clone()); | 145 pCurPageDict->SetFor("Resources", pInheritable->Clone()); |
146 } | 146 } |
147 // 3 CropBox //Optional | 147 // 3 CropBox //Optional |
148 if (!pCurPageDict->KeyExist("CropBox")) { | 148 if (!pCurPageDict->KeyExist("CropBox")) { |
149 pInheritable = PageDictGetInheritableTag(pSrcPageDict, "CropBox"); | 149 pInheritable = PageDictGetInheritableTag(pSrcPageDict, "CropBox"); |
150 if (pInheritable) | 150 if (pInheritable) |
151 pCurPageDict->SetFor("CropBox", pInheritable->Clone()); | 151 pCurPageDict->SetFor("CropBox", pInheritable->Clone()); |
152 } | 152 } |
153 // 4 Rotate //Optional | 153 // 4 Rotate //Optional |
154 if (!pCurPageDict->KeyExist("Rotate")) { | 154 if (!pCurPageDict->KeyExist("Rotate")) { |
155 pInheritable = PageDictGetInheritableTag(pSrcPageDict, "Rotate"); | 155 pInheritable = PageDictGetInheritableTag(pSrcPageDict, "Rotate"); |
156 if (pInheritable) | 156 if (pInheritable) |
157 pCurPageDict->SetFor("Rotate", pInheritable->Clone()); | 157 pCurPageDict->SetFor("Rotate", pInheritable->Clone()); |
158 } | 158 } |
159 | 159 |
160 // Update the reference | 160 // Update the reference |
161 uint32_t dwOldPageObj = pSrcPageDict->GetObjNum(); | 161 uint32_t dwOldPageObj = pSrcPageDict->GetObjNum(); |
162 uint32_t dwNewPageObj = pCurPageDict->GetObjNum(); | 162 uint32_t dwNewPageObj = pCurPageDict->GetObjNum(); |
163 | 163 |
164 (*pObjNumberMap)[dwOldPageObj] = dwNewPageObj; | 164 (*pObjNumberMap)[dwOldPageObj] = dwNewPageObj; |
165 | 165 |
166 UpdateReference(pCurPageDict, pDestPDFDoc, pObjNumberMap.get()); | 166 UpdateReference(pCurPageDict, pDestPDFDoc, pObjNumberMap.get()); |
167 ++curpage; | 167 ++curpage; |
168 } | 168 } |
169 | 169 |
170 return TRUE; | 170 return true; |
171 } | 171 } |
172 | 172 |
173 CPDF_Object* CPDF_PageOrganizer::PageDictGetInheritableTag( | 173 CPDF_Object* CPDF_PageOrganizer::PageDictGetInheritableTag( |
174 CPDF_Dictionary* pDict, | 174 CPDF_Dictionary* pDict, |
175 const CFX_ByteString& bsSrcTag) { | 175 const CFX_ByteString& bsSrcTag) { |
176 if (!pDict || bsSrcTag.IsEmpty()) | 176 if (!pDict || bsSrcTag.IsEmpty()) |
177 return nullptr; | 177 return nullptr; |
178 if (!pDict->KeyExist("Parent") || !pDict->KeyExist("Type")) | 178 if (!pDict->KeyExist("Parent") || !pDict->KeyExist("Type")) |
179 return nullptr; | 179 return nullptr; |
180 | 180 |
(...skipping 14 matching lines...) Expand all Loading... |
195 while (pp) { | 195 while (pp) { |
196 if (pp->KeyExist(bsSrcTag)) | 196 if (pp->KeyExist(bsSrcTag)) |
197 return pp->GetObjectFor(bsSrcTag); | 197 return pp->GetObjectFor(bsSrcTag); |
198 if (!pp->KeyExist("Parent")) | 198 if (!pp->KeyExist("Parent")) |
199 break; | 199 break; |
200 pp = ToDictionary(pp->GetObjectFor("Parent")->GetDirect()); | 200 pp = ToDictionary(pp->GetObjectFor("Parent")->GetDirect()); |
201 } | 201 } |
202 return nullptr; | 202 return nullptr; |
203 } | 203 } |
204 | 204 |
205 FX_BOOL CPDF_PageOrganizer::UpdateReference(CPDF_Object* pObj, | 205 bool CPDF_PageOrganizer::UpdateReference(CPDF_Object* pObj, |
206 CPDF_Document* pDoc, | 206 CPDF_Document* pDoc, |
207 ObjectNumberMap* pObjNumberMap) { | 207 ObjectNumberMap* pObjNumberMap) { |
208 switch (pObj->GetType()) { | 208 switch (pObj->GetType()) { |
209 case CPDF_Object::REFERENCE: { | 209 case CPDF_Object::REFERENCE: { |
210 CPDF_Reference* pReference = pObj->AsReference(); | 210 CPDF_Reference* pReference = pObj->AsReference(); |
211 uint32_t newobjnum = GetNewObjId(pDoc, pObjNumberMap, pReference); | 211 uint32_t newobjnum = GetNewObjId(pDoc, pObjNumberMap, pReference); |
212 if (newobjnum == 0) | 212 if (newobjnum == 0) |
213 return FALSE; | 213 return false; |
214 pReference->SetRef(pDoc, newobjnum); | 214 pReference->SetRef(pDoc, newobjnum); |
215 break; | 215 break; |
216 } | 216 } |
217 case CPDF_Object::DICTIONARY: { | 217 case CPDF_Object::DICTIONARY: { |
218 CPDF_Dictionary* pDict = pObj->AsDictionary(); | 218 CPDF_Dictionary* pDict = pObj->AsDictionary(); |
219 auto it = pDict->begin(); | 219 auto it = pDict->begin(); |
220 while (it != pDict->end()) { | 220 while (it != pDict->end()) { |
221 const CFX_ByteString& key = it->first; | 221 const CFX_ByteString& key = it->first; |
222 CPDF_Object* pNextObj = it->second; | 222 CPDF_Object* pNextObj = it->second; |
223 ++it; | 223 ++it; |
224 if (key == "Parent" || key == "Prev" || key == "First") | 224 if (key == "Parent" || key == "Prev" || key == "First") |
225 continue; | 225 continue; |
226 if (!pNextObj) | 226 if (!pNextObj) |
227 return FALSE; | 227 return false; |
228 if (!UpdateReference(pNextObj, pDoc, pObjNumberMap)) | 228 if (!UpdateReference(pNextObj, pDoc, pObjNumberMap)) |
229 pDict->RemoveFor(key); | 229 pDict->RemoveFor(key); |
230 } | 230 } |
231 break; | 231 break; |
232 } | 232 } |
233 case CPDF_Object::ARRAY: { | 233 case CPDF_Object::ARRAY: { |
234 CPDF_Array* pArray = pObj->AsArray(); | 234 CPDF_Array* pArray = pObj->AsArray(); |
235 for (size_t i = 0; i < pArray->GetCount(); ++i) { | 235 for (size_t i = 0; i < pArray->GetCount(); ++i) { |
236 CPDF_Object* pNextObj = pArray->GetObjectAt(i); | 236 CPDF_Object* pNextObj = pArray->GetObjectAt(i); |
237 if (!pNextObj) | 237 if (!pNextObj) |
238 return FALSE; | 238 return false; |
239 if (!UpdateReference(pNextObj, pDoc, pObjNumberMap)) | 239 if (!UpdateReference(pNextObj, pDoc, pObjNumberMap)) |
240 return FALSE; | 240 return false; |
241 } | 241 } |
242 break; | 242 break; |
243 } | 243 } |
244 case CPDF_Object::STREAM: { | 244 case CPDF_Object::STREAM: { |
245 CPDF_Stream* pStream = pObj->AsStream(); | 245 CPDF_Stream* pStream = pObj->AsStream(); |
246 CPDF_Dictionary* pDict = pStream->GetDict(); | 246 CPDF_Dictionary* pDict = pStream->GetDict(); |
247 if (pDict) { | 247 if (pDict) { |
248 if (!UpdateReference(pDict, pDoc, pObjNumberMap)) | 248 if (!UpdateReference(pDict, pDoc, pObjNumberMap)) |
249 return FALSE; | 249 return false; |
250 } else { | 250 } else { |
251 return FALSE; | 251 return false; |
252 } | 252 } |
253 break; | 253 break; |
254 } | 254 } |
255 default: | 255 default: |
256 break; | 256 break; |
257 } | 257 } |
258 | 258 |
259 return TRUE; | 259 return true; |
260 } | 260 } |
261 | 261 |
262 uint32_t CPDF_PageOrganizer::GetNewObjId(CPDF_Document* pDoc, | 262 uint32_t CPDF_PageOrganizer::GetNewObjId(CPDF_Document* pDoc, |
263 ObjectNumberMap* pObjNumberMap, | 263 ObjectNumberMap* pObjNumberMap, |
264 CPDF_Reference* pRef) { | 264 CPDF_Reference* pRef) { |
265 if (!pRef) | 265 if (!pRef) |
266 return 0; | 266 return 0; |
267 | 267 |
268 uint32_t dwObjnum = pRef->GetRefObjNum(); | 268 uint32_t dwObjnum = pRef->GetRefObjNum(); |
269 uint32_t dwNewObjNum = 0; | 269 uint32_t dwNewObjNum = 0; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 | 305 |
306 FPDF_BOOL ParserPageRangeString(CFX_ByteString rangstring, | 306 FPDF_BOOL ParserPageRangeString(CFX_ByteString rangstring, |
307 std::vector<uint16_t>* pageArray, | 307 std::vector<uint16_t>* pageArray, |
308 int nCount) { | 308 int nCount) { |
309 if (rangstring.GetLength() != 0) { | 309 if (rangstring.GetLength() != 0) { |
310 rangstring.Remove(' '); | 310 rangstring.Remove(' '); |
311 int nLength = rangstring.GetLength(); | 311 int nLength = rangstring.GetLength(); |
312 CFX_ByteString cbCompareString("0123456789-,"); | 312 CFX_ByteString cbCompareString("0123456789-,"); |
313 for (int i = 0; i < nLength; ++i) { | 313 for (int i = 0; i < nLength; ++i) { |
314 if (cbCompareString.Find(rangstring[i]) == -1) | 314 if (cbCompareString.Find(rangstring[i]) == -1) |
315 return FALSE; | 315 return false; |
316 } | 316 } |
317 CFX_ByteString cbMidRange; | 317 CFX_ByteString cbMidRange; |
318 int nStringFrom = 0; | 318 int nStringFrom = 0; |
319 int nStringTo = 0; | 319 int nStringTo = 0; |
320 while (nStringTo < nLength) { | 320 while (nStringTo < nLength) { |
321 nStringTo = rangstring.Find(',', nStringFrom); | 321 nStringTo = rangstring.Find(',', nStringFrom); |
322 if (nStringTo == -1) | 322 if (nStringTo == -1) |
323 nStringTo = nLength; | 323 nStringTo = nLength; |
324 cbMidRange = rangstring.Mid(nStringFrom, nStringTo - nStringFrom); | 324 cbMidRange = rangstring.Mid(nStringFrom, nStringTo - nStringFrom); |
325 int nMid = cbMidRange.Find('-'); | 325 int nMid = cbMidRange.Find('-'); |
326 if (nMid == -1) { | 326 if (nMid == -1) { |
327 long lPageNum = atol(cbMidRange.c_str()); | 327 long lPageNum = atol(cbMidRange.c_str()); |
328 if (lPageNum <= 0 || lPageNum > nCount) | 328 if (lPageNum <= 0 || lPageNum > nCount) |
329 return FALSE; | 329 return false; |
330 pageArray->push_back((uint16_t)lPageNum); | 330 pageArray->push_back((uint16_t)lPageNum); |
331 } else { | 331 } else { |
332 int nStartPageNum = atol(cbMidRange.Mid(0, nMid).c_str()); | 332 int nStartPageNum = atol(cbMidRange.Mid(0, nMid).c_str()); |
333 if (nStartPageNum == 0) | 333 if (nStartPageNum == 0) |
334 return FALSE; | 334 return false; |
335 | 335 |
336 ++nMid; | 336 ++nMid; |
337 int nEnd = cbMidRange.GetLength() - nMid; | 337 int nEnd = cbMidRange.GetLength() - nMid; |
338 if (nEnd == 0) | 338 if (nEnd == 0) |
339 return FALSE; | 339 return false; |
340 | 340 |
341 int nEndPageNum = atol(cbMidRange.Mid(nMid, nEnd).c_str()); | 341 int nEndPageNum = atol(cbMidRange.Mid(nMid, nEnd).c_str()); |
342 if (nStartPageNum < 0 || nStartPageNum > nEndPageNum || | 342 if (nStartPageNum < 0 || nStartPageNum > nEndPageNum || |
343 nEndPageNum > nCount) { | 343 nEndPageNum > nCount) { |
344 return FALSE; | 344 return false; |
345 } | 345 } |
346 for (int i = nStartPageNum; i <= nEndPageNum; ++i) { | 346 for (int i = nStartPageNum; i <= nEndPageNum; ++i) { |
347 pageArray->push_back(i); | 347 pageArray->push_back(i); |
348 } | 348 } |
349 } | 349 } |
350 nStringFrom = nStringTo + 1; | 350 nStringFrom = nStringTo + 1; |
351 } | 351 } |
352 } | 352 } |
353 return TRUE; | 353 return true; |
354 } | 354 } |
355 | 355 |
356 DLLEXPORT FPDF_BOOL STDCALL FPDF_ImportPages(FPDF_DOCUMENT dest_doc, | 356 DLLEXPORT FPDF_BOOL STDCALL FPDF_ImportPages(FPDF_DOCUMENT dest_doc, |
357 FPDF_DOCUMENT src_doc, | 357 FPDF_DOCUMENT src_doc, |
358 FPDF_BYTESTRING pagerange, | 358 FPDF_BYTESTRING pagerange, |
359 int index) { | 359 int index) { |
360 CPDF_Document* pDestDoc = CPDFDocumentFromFPDFDocument(dest_doc); | 360 CPDF_Document* pDestDoc = CPDFDocumentFromFPDFDocument(dest_doc); |
361 if (!dest_doc) | 361 if (!dest_doc) |
362 return FALSE; | 362 return false; |
363 | 363 |
364 CPDF_Document* pSrcDoc = CPDFDocumentFromFPDFDocument(src_doc); | 364 CPDF_Document* pSrcDoc = CPDFDocumentFromFPDFDocument(src_doc); |
365 if (!pSrcDoc) | 365 if (!pSrcDoc) |
366 return FALSE; | 366 return false; |
367 | 367 |
368 std::vector<uint16_t> pageArray; | 368 std::vector<uint16_t> pageArray; |
369 int nCount = pSrcDoc->GetPageCount(); | 369 int nCount = pSrcDoc->GetPageCount(); |
370 if (pagerange) { | 370 if (pagerange) { |
371 if (!ParserPageRangeString(pagerange, &pageArray, nCount)) | 371 if (!ParserPageRangeString(pagerange, &pageArray, nCount)) |
372 return FALSE; | 372 return false; |
373 } else { | 373 } else { |
374 for (int i = 1; i <= nCount; ++i) { | 374 for (int i = 1; i <= nCount; ++i) { |
375 pageArray.push_back(i); | 375 pageArray.push_back(i); |
376 } | 376 } |
377 } | 377 } |
378 | 378 |
379 CPDF_PageOrganizer pageOrg; | 379 CPDF_PageOrganizer pageOrg; |
380 pageOrg.PDFDocInit(pDestDoc, pSrcDoc); | 380 pageOrg.PDFDocInit(pDestDoc, pSrcDoc); |
381 return pageOrg.ExportPage(pSrcDoc, &pageArray, pDestDoc, index); | 381 return pageOrg.ExportPage(pSrcDoc, &pageArray, pDestDoc, index); |
382 } | 382 } |
383 | 383 |
384 DLLEXPORT FPDF_BOOL STDCALL FPDF_CopyViewerPreferences(FPDF_DOCUMENT dest_doc, | 384 DLLEXPORT FPDF_BOOL STDCALL FPDF_CopyViewerPreferences(FPDF_DOCUMENT dest_doc, |
385 FPDF_DOCUMENT src_doc) { | 385 FPDF_DOCUMENT src_doc) { |
386 CPDF_Document* pDstDoc = CPDFDocumentFromFPDFDocument(dest_doc); | 386 CPDF_Document* pDstDoc = CPDFDocumentFromFPDFDocument(dest_doc); |
387 if (!pDstDoc) | 387 if (!pDstDoc) |
388 return FALSE; | 388 return false; |
389 | 389 |
390 CPDF_Document* pSrcDoc = CPDFDocumentFromFPDFDocument(src_doc); | 390 CPDF_Document* pSrcDoc = CPDFDocumentFromFPDFDocument(src_doc); |
391 if (!pSrcDoc) | 391 if (!pSrcDoc) |
392 return FALSE; | 392 return false; |
393 | 393 |
394 CPDF_Dictionary* pSrcDict = pSrcDoc->GetRoot(); | 394 CPDF_Dictionary* pSrcDict = pSrcDoc->GetRoot(); |
395 pSrcDict = pSrcDict->GetDictFor("ViewerPreferences"); | 395 pSrcDict = pSrcDict->GetDictFor("ViewerPreferences"); |
396 if (!pSrcDict) | 396 if (!pSrcDict) |
397 return FALSE; | 397 return false; |
398 | 398 |
399 CPDF_Dictionary* pDstDict = pDstDoc->GetRoot(); | 399 CPDF_Dictionary* pDstDict = pDstDoc->GetRoot(); |
400 if (!pDstDict) | 400 if (!pDstDict) |
401 return FALSE; | 401 return false; |
402 | 402 |
403 pDstDict->SetFor("ViewerPreferences", pSrcDict->CloneDirectObject()); | 403 pDstDict->SetFor("ViewerPreferences", pSrcDict->CloneDirectObject()); |
404 return TRUE; | 404 return true; |
405 } | 405 } |
OLD | NEW |