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 #include "../../third_party/base/nonstd_unique_ptr.h" | 8 #include "../../third_party/base/nonstd_unique_ptr.h" |
9 #include "../include/fsdk_define.h" | 9 #include "../include/fsdk_define.h" |
10 | 10 |
11 class CPDF_PageOrganizer | 11 class CPDF_PageOrganizer |
12 { | 12 { |
13 public: | 13 public: |
14 using ObjectNumberMap = std::map<FX_DWORD, FX_DWORD>; | 14 using ObjectNumberMap = std::map<FX_DWORD, FX_DWORD>; |
15 CPDF_PageOrganizer(); | 15 CPDF_PageOrganizer(); |
16 ~CPDF_PageOrganizer(); | 16 ~CPDF_PageOrganizer(); |
17 | 17 |
18 FX_BOOL PDFDocInit(CPDF_Document* pDestPDFDoc, CPDF_Document* pSrcPDFDoc); | 18 bool PDFDocInit(CPDF_Document* pDestPDFDoc, CPDF_Document* pSrcPDFDoc); |
19 FX_BOOL ExportPage(CPDF_Document* pSrcPDFDoc, | 19 bool ExportPage(CPDF_Document* pSrcPDFDoc, |
20 CFX_WordArray* nPageNum, | 20 CFX_WordArray* nPageNum, |
21 CPDF_Document* pDestPDFDoc, | 21 CPDF_Document* pDestPDFDoc, |
22 int nIndex); | 22 int nIndex); |
23 CPDF_Object* PageDictGetInheritableTag(CPDF_Dictionary* pDict, | 23 CPDF_Object* PageDictGetInheritableTag(CPDF_Dictionary* pDict, |
24 CFX_ByteString nSrctag); | 24 CFX_ByteString nSrctag); |
25 FX_BOOL UpdateReference(CPDF_Object* pObj, | 25 bool UpdateReference(CPDF_Object* pObj, |
26 CPDF_Document* pDoc, | 26 CPDF_Document* pDoc, |
27 ObjectNumberMap* pObjNumberMap); | 27 ObjectNumberMap* pObjNumberMap); |
28 FX_DWORD GetNewObjId(CPDF_Document* pDoc, | 28 FX_DWORD GetNewObjId(CPDF_Document* pDoc, |
29 ObjectNumberMap* pObjNumberMap, | 29 ObjectNumberMap* pObjNumberMap, |
30 CPDF_Reference* pRef); | 30 CPDF_Reference* pRef); |
31 }; | 31 }; |
32 | 32 |
33 | 33 |
34 CPDF_PageOrganizer::CPDF_PageOrganizer() | 34 CPDF_PageOrganizer::CPDF_PageOrganizer() |
35 { | 35 { |
36 } | 36 } |
37 | 37 |
38 CPDF_PageOrganizer::~CPDF_PageOrganizer() | 38 CPDF_PageOrganizer::~CPDF_PageOrganizer() |
39 { | 39 { |
40 } | 40 } |
41 | 41 |
42 FX_BOOL CPDF_PageOrganizer::PDFDocInit(CPDF_Document* pDestPDFDoc, | 42 bool CPDF_PageOrganizer::PDFDocInit(CPDF_Document* pDestPDFDoc, |
43 CPDF_Document* pSrcPDFDoc) | 43 CPDF_Document* pSrcPDFDoc) |
44 { | 44 { |
45 if (!pDestPDFDoc || !pSrcPDFDoc) | 45 if (!pDestPDFDoc || !pSrcPDFDoc) |
46 return FALSE; | 46 return false; |
47 | 47 |
48 CPDF_Dictionary* pNewRoot = pDestPDFDoc->GetRoot(); | 48 CPDF_Dictionary* pNewRoot = pDestPDFDoc->GetRoot(); |
49 if (!pNewRoot) | 49 if (!pNewRoot) |
50 return FALSE; | 50 return false; |
51 | 51 |
52 //Set the document information//////////////////////////////////////////// | 52 //Set the document information//////////////////////////////////////////// |
53 | 53 |
54 CPDF_Dictionary* DInfoDict = pDestPDFDoc->GetInfo(); | 54 CPDF_Dictionary* DInfoDict = pDestPDFDoc->GetInfo(); |
55 if (!DInfoDict) | 55 if (!DInfoDict) |
56 return FALSE; | 56 return false; |
57 | 57 |
58 CFX_ByteString producerstr; | 58 CFX_ByteString producerstr; |
59 producerstr.Format("PDFium"); | 59 producerstr.Format("PDFium"); |
60 DInfoDict->SetAt("Producer", new CPDF_String(producerstr)); | 60 DInfoDict->SetAt("Producer", new CPDF_String(producerstr)); |
61 | 61 |
62 //Set type//////////////////////////////////////////////////////////////// | 62 //Set type//////////////////////////////////////////////////////////////// |
63 CFX_ByteString cbRootType = pNewRoot->GetString("Type", ""); | 63 CFX_ByteString cbRootType = pNewRoot->GetString("Type", ""); |
64 if (cbRootType.Equal("") ) { | 64 if (cbRootType.Equal("") ) { |
65 pNewRoot->SetAt("Type", new CPDF_Name("Catalog")); | 65 pNewRoot->SetAt("Type", new CPDF_Name("Catalog")); |
66 } | 66 } |
(...skipping 15 matching lines...) Expand all Loading... |
82 CPDF_Array* pKeysArray = pNewPages->GetArray("Kids"); | 82 CPDF_Array* pKeysArray = pNewPages->GetArray("Kids"); |
83 if (!pKeysArray) { | 83 if (!pKeysArray) { |
84 CPDF_Array* pNewKids = new CPDF_Array; | 84 CPDF_Array* pNewKids = new CPDF_Array; |
85 FX_DWORD Kidsobjnum = -1; | 85 FX_DWORD Kidsobjnum = -1; |
86 Kidsobjnum = pDestPDFDoc->AddIndirectObject(pNewKids); | 86 Kidsobjnum = pDestPDFDoc->AddIndirectObject(pNewKids); |
87 | 87 |
88 pNewPages->SetAt("Kids", new CPDF_Reference(pDestPDFDoc, Kidsobjnum)); | 88 pNewPages->SetAt("Kids", new CPDF_Reference(pDestPDFDoc, Kidsobjnum)); |
89 pNewPages->SetAt("Count", new CPDF_Number(0)); | 89 pNewPages->SetAt("Count", new CPDF_Number(0)); |
90 } | 90 } |
91 | 91 |
92 return TRUE; | 92 return true; |
93 } | 93 } |
94 | 94 |
95 FX_BOOL CPDF_PageOrganizer::ExportPage(CPDF_Document* pSrcPDFDoc, | 95 bool CPDF_PageOrganizer::ExportPage(CPDF_Document* pSrcPDFDoc, |
96 CFX_WordArray* nPageNum, | 96 CFX_WordArray* nPageNum, |
97 CPDF_Document* pDestPDFDoc, | 97 CPDF_Document* pDestPDFDoc, |
98 int nIndex) | 98 int nIndex) |
99 { | 99 { |
100 int curpage = nIndex; | 100 int curpage = nIndex; |
101 | 101 |
102 nonstd::unique_ptr<ObjectNumberMap> pObjNumberMap(new ObjectNumberMap); | 102 nonstd::unique_ptr<ObjectNumberMap> pObjNumberMap(new ObjectNumberMap); |
103 | 103 |
104 for (int i = 0; i < nPageNum->GetSize(); ++i) { | 104 for (int i = 0; i < nPageNum->GetSize(); ++i) { |
105 CPDF_Dictionary* pCurPageDict = pDestPDFDoc->CreateNewPage(curpage); | 105 CPDF_Dictionary* pCurPageDict = pDestPDFDoc->CreateNewPage(curpage); |
106 CPDF_Dictionary* pSrcPageDict = | 106 CPDF_Dictionary* pSrcPageDict = |
107 pSrcPDFDoc->GetPage(nPageNum->GetAt(i) - 1); | 107 pSrcPDFDoc->GetPage(nPageNum->GetAt(i) - 1); |
108 if (!pSrcPageDict || !pCurPageDict) | 108 if (!pSrcPageDict || !pCurPageDict) |
109 return FALSE; | 109 return false; |
110 | 110 |
111 // Clone the page dictionary/////////// | 111 // Clone the page dictionary/////////// |
112 FX_POSITION SrcPos = pSrcPageDict->GetStartPos(); | 112 FX_POSITION SrcPos = pSrcPageDict->GetStartPos(); |
113 while (SrcPos) { | 113 while (SrcPos) { |
114 CFX_ByteString cbSrcKeyStr; | 114 CFX_ByteString cbSrcKeyStr; |
115 CPDF_Object* pObj = pSrcPageDict->GetNextElement(SrcPos, | 115 CPDF_Object* pObj = pSrcPageDict->GetNextElement(SrcPos, |
116 cbSrcKeyStr); | 116 cbSrcKeyStr); |
117 if (cbSrcKeyStr.Compare(("Type")) && | 117 if (cbSrcKeyStr.Compare(("Type")) && |
118 cbSrcKeyStr.Compare(("Parent"))) { | 118 cbSrcKeyStr.Compare(("Parent"))) { |
119 if (pCurPageDict->KeyExist(cbSrcKeyStr)) | 119 if (pCurPageDict->KeyExist(cbSrcKeyStr)) |
(...skipping 24 matching lines...) Expand all Loading... |
144 pCurPageDict->SetAt("MediaBox", pArray); | 144 pCurPageDict->SetAt("MediaBox", pArray); |
145 } | 145 } |
146 } else { | 146 } else { |
147 pCurPageDict->SetAt("MediaBox", pInheritable->Clone()); | 147 pCurPageDict->SetAt("MediaBox", pInheritable->Clone()); |
148 } | 148 } |
149 } | 149 } |
150 //2 Resources //required | 150 //2 Resources //required |
151 if (!pCurPageDict->KeyExist("Resources")) { | 151 if (!pCurPageDict->KeyExist("Resources")) { |
152 pInheritable = PageDictGetInheritableTag(pSrcPageDict, "Resources"); | 152 pInheritable = PageDictGetInheritableTag(pSrcPageDict, "Resources"); |
153 if (!pInheritable) | 153 if (!pInheritable) |
154 return FALSE; | 154 return false; |
155 pCurPageDict->SetAt("Resources", pInheritable->Clone()); | 155 pCurPageDict->SetAt("Resources", pInheritable->Clone()); |
156 } | 156 } |
157 //3 CropBox //Optional | 157 //3 CropBox //Optional |
158 if (!pCurPageDict->KeyExist("CropBox")) { | 158 if (!pCurPageDict->KeyExist("CropBox")) { |
159 pInheritable = PageDictGetInheritableTag(pSrcPageDict, "CropBox"); | 159 pInheritable = PageDictGetInheritableTag(pSrcPageDict, "CropBox"); |
160 if (pInheritable) | 160 if (pInheritable) |
161 pCurPageDict->SetAt("CropBox", pInheritable->Clone()); | 161 pCurPageDict->SetAt("CropBox", pInheritable->Clone()); |
162 } | 162 } |
163 //4 Rotate //Optional | 163 //4 Rotate //Optional |
164 if (!pCurPageDict->KeyExist("Rotate")) { | 164 if (!pCurPageDict->KeyExist("Rotate")) { |
165 pInheritable = PageDictGetInheritableTag(pSrcPageDict, "Rotate"); | 165 pInheritable = PageDictGetInheritableTag(pSrcPageDict, "Rotate"); |
166 if (pInheritable) | 166 if (pInheritable) |
167 pCurPageDict->SetAt("Rotate", pInheritable->Clone()); | 167 pCurPageDict->SetAt("Rotate", pInheritable->Clone()); |
168 } | 168 } |
169 | 169 |
170 ///////////////////////////////////////////// | 170 ///////////////////////////////////////////// |
171 //Update the reference | 171 //Update the reference |
172 FX_DWORD dwOldPageObj = pSrcPageDict->GetObjNum(); | 172 FX_DWORD dwOldPageObj = pSrcPageDict->GetObjNum(); |
173 FX_DWORD dwNewPageObj = pCurPageDict->GetObjNum(); | 173 FX_DWORD dwNewPageObj = pCurPageDict->GetObjNum(); |
174 | 174 |
175 (*pObjNumberMap)[dwOldPageObj] = dwNewPageObj; | 175 (*pObjNumberMap)[dwOldPageObj] = dwNewPageObj; |
176 | 176 |
177 UpdateReference(pCurPageDict, pDestPDFDoc, pObjNumberMap.get()); | 177 UpdateReference(pCurPageDict, pDestPDFDoc, pObjNumberMap.get()); |
178 ++curpage; | 178 ++curpage; |
179 } | 179 } |
180 | 180 |
181 return TRUE; | 181 return true; |
182 } | 182 } |
183 | 183 |
184 CPDF_Object* CPDF_PageOrganizer::PageDictGetInheritableTag( | 184 CPDF_Object* CPDF_PageOrganizer::PageDictGetInheritableTag( |
185 CPDF_Dictionary* pDict, | 185 CPDF_Dictionary* pDict, |
186 CFX_ByteString nSrctag) | 186 CFX_ByteString nSrctag) |
187 { | 187 { |
188 if (!pDict || !pDict->KeyExist("Type") || nSrctag.IsEmpty()) | 188 if (!pDict || !pDict->KeyExist("Type") || nSrctag.IsEmpty()) |
189 return nullptr; | 189 return nullptr; |
190 if (!pDict->KeyExist("Parent")) | 190 if (!pDict->KeyExist("Parent")) |
191 return nullptr; | 191 return nullptr; |
(...skipping 21 matching lines...) Expand all Loading... |
213 if (pp->GetType() == PDFOBJ_NULL) | 213 if (pp->GetType() == PDFOBJ_NULL) |
214 break; | 214 break; |
215 } else { | 215 } else { |
216 break; | 216 break; |
217 } | 217 } |
218 } | 218 } |
219 | 219 |
220 return nullptr; | 220 return nullptr; |
221 } | 221 } |
222 | 222 |
223 FX_BOOL CPDF_PageOrganizer::UpdateReference(CPDF_Object* pObj, | 223 bool CPDF_PageOrganizer::UpdateReference(CPDF_Object* pObj, |
224 CPDF_Document* pDoc, | 224 CPDF_Document* pDoc, |
225 ObjectNumberMap* pObjNumberMap) | 225 ObjectNumberMap* pObjNumberMap) |
226 { | 226 { |
227 switch (pObj->GetType()) { | 227 switch (pObj->GetType()) { |
228 case PDFOBJ_REFERENCE: { | 228 case PDFOBJ_REFERENCE: { |
229 CPDF_Reference* pReference = (CPDF_Reference*)pObj; | 229 CPDF_Reference* pReference = (CPDF_Reference*)pObj; |
230 FX_DWORD newobjnum = GetNewObjId(pDoc, pObjNumberMap, pReference); | 230 FX_DWORD newobjnum = GetNewObjId(pDoc, pObjNumberMap, pReference); |
231 if (newobjnum == 0) | 231 if (newobjnum == 0) |
232 return FALSE; | 232 return false; |
233 pReference->SetRef(pDoc, newobjnum); | 233 pReference->SetRef(pDoc, newobjnum); |
234 break; | 234 break; |
235 } | 235 } |
236 case PDFOBJ_DICTIONARY: { | 236 case PDFOBJ_DICTIONARY: { |
237 CPDF_Dictionary* pDict = (CPDF_Dictionary*)pObj; | 237 CPDF_Dictionary* pDict = (CPDF_Dictionary*)pObj; |
238 | 238 |
239 FX_POSITION pos = pDict->GetStartPos(); | 239 FX_POSITION pos = pDict->GetStartPos(); |
240 while (pos) { | 240 while (pos) { |
241 CFX_ByteString key(""); | 241 CFX_ByteString key(""); |
242 CPDF_Object* pNextObj = pDict->GetNextElement(pos, key); | 242 CPDF_Object* pNextObj = pDict->GetNextElement(pos, key); |
243 if (!FXSYS_strcmp(key, "Parent") || | 243 if (!FXSYS_strcmp(key, "Parent") || |
244 !FXSYS_strcmp(key, "Prev") || | 244 !FXSYS_strcmp(key, "Prev") || |
245 !FXSYS_strcmp(key, "First")) { | 245 !FXSYS_strcmp(key, "First")) { |
246 continue; | 246 continue; |
247 } | 247 } |
248 if (pNextObj) { | 248 if (pNextObj) { |
249 if (!UpdateReference(pNextObj, pDoc, pObjNumberMap)) | 249 if (!UpdateReference(pNextObj, pDoc, pObjNumberMap)) |
250 pDict->RemoveAt(key); | 250 pDict->RemoveAt(key); |
251 } else { | 251 } else { |
252 return FALSE; | 252 return false; |
253 } | 253 } |
254 } | 254 } |
255 break; | 255 break; |
256 } | 256 } |
257 case PDFOBJ_ARRAY: { | 257 case PDFOBJ_ARRAY: { |
258 CPDF_Array* pArray = (CPDF_Array*)pObj; | 258 CPDF_Array* pArray = (CPDF_Array*)pObj; |
259 FX_DWORD count = pArray->GetCount(); | 259 FX_DWORD count = pArray->GetCount(); |
260 for (FX_DWORD i = 0; i < count; ++i) { | 260 for (FX_DWORD i = 0; i < count; ++i) { |
261 CPDF_Object* pNextObj = pArray->GetElement(i); | 261 CPDF_Object* pNextObj = pArray->GetElement(i); |
262 if (pNextObj) { | 262 if (pNextObj) { |
263 if (!UpdateReference(pNextObj, pDoc, pObjNumberMap)) | 263 if (!UpdateReference(pNextObj, pDoc, pObjNumberMap)) |
264 return FALSE; | 264 return false; |
265 } else { | 265 } else { |
266 return FALSE; | 266 return false; |
267 } | 267 } |
268 } | 268 } |
269 break; | 269 break; |
270 } | 270 } |
271 case PDFOBJ_STREAM: { | 271 case PDFOBJ_STREAM: { |
272 CPDF_Stream* pStream = (CPDF_Stream*)pObj; | 272 CPDF_Stream* pStream = (CPDF_Stream*)pObj; |
273 CPDF_Dictionary* pDict = pStream->GetDict(); | 273 CPDF_Dictionary* pDict = pStream->GetDict(); |
274 if (pDict) { | 274 if (pDict) { |
275 if (!UpdateReference(pDict, pDoc, pObjNumberMap)) | 275 if (!UpdateReference(pDict, pDoc, pObjNumberMap)) |
276 return FALSE; | 276 return false; |
277 } else { | 277 } else { |
278 return FALSE; | 278 return false; |
279 } | 279 } |
280 break; | 280 break; |
281 } | 281 } |
282 default: | 282 default: |
283 break; | 283 break; |
284 } | 284 } |
285 | 285 |
286 return TRUE; | 286 return true; |
287 } | 287 } |
288 | 288 |
289 FX_DWORD CPDF_PageOrganizer::GetNewObjId(CPDF_Document* pDoc, | 289 FX_DWORD CPDF_PageOrganizer::GetNewObjId(CPDF_Document* pDoc, |
290 ObjectNumberMap* pObjNumberMap, | 290 ObjectNumberMap* pObjNumberMap, |
291 CPDF_Reference* pRef) | 291 CPDF_Reference* pRef) |
292 { | 292 { |
293 if (!pRef) | 293 if (!pRef) |
294 return 0; | 294 return 0; |
295 | 295 |
296 FX_DWORD dwObjnum = pRef->GetRefObjNum(); | 296 FX_DWORD dwObjnum = pRef->GetRefObjNum(); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 FPDF_BOOL ParserPageRangeString(CFX_ByteString rangstring, | 335 FPDF_BOOL ParserPageRangeString(CFX_ByteString rangstring, |
336 CFX_WordArray* pageArray, | 336 CFX_WordArray* pageArray, |
337 int nCount) | 337 int nCount) |
338 { | 338 { |
339 if (rangstring.GetLength() != 0) { | 339 if (rangstring.GetLength() != 0) { |
340 rangstring.Remove(' '); | 340 rangstring.Remove(' '); |
341 int nLength = rangstring.GetLength(); | 341 int nLength = rangstring.GetLength(); |
342 CFX_ByteString cbCompareString("0123456789-,"); | 342 CFX_ByteString cbCompareString("0123456789-,"); |
343 for (int i = 0; i < nLength; ++i) { | 343 for (int i = 0; i < nLength; ++i) { |
344 if (cbCompareString.Find(rangstring[i]) == -1) | 344 if (cbCompareString.Find(rangstring[i]) == -1) |
345 return FALSE; | 345 return false; |
346 } | 346 } |
347 CFX_ByteString cbMidRange; | 347 CFX_ByteString cbMidRange; |
348 int nStringFrom = 0; | 348 int nStringFrom = 0; |
349 int nStringTo = 0; | 349 int nStringTo = 0; |
350 while (nStringTo < nLength) { | 350 while (nStringTo < nLength) { |
351 nStringTo = rangstring.Find(',', nStringFrom); | 351 nStringTo = rangstring.Find(',', nStringFrom); |
352 if (nStringTo == -1) | 352 if (nStringTo == -1) |
353 nStringTo = nLength; | 353 nStringTo = nLength; |
354 cbMidRange = rangstring.Mid(nStringFrom, nStringTo - nStringFrom); | 354 cbMidRange = rangstring.Mid(nStringFrom, nStringTo - nStringFrom); |
355 int nMid = cbMidRange.Find('-'); | 355 int nMid = cbMidRange.Find('-'); |
356 if (nMid == -1) { | 356 if (nMid == -1) { |
357 long lPageNum = atol(cbMidRange); | 357 long lPageNum = atol(cbMidRange); |
358 if (lPageNum <= 0 || lPageNum > nCount) | 358 if (lPageNum <= 0 || lPageNum > nCount) |
359 return FALSE; | 359 return false; |
360 pageArray->Add((FX_WORD)lPageNum); | 360 pageArray->Add((FX_WORD)lPageNum); |
361 } else { | 361 } else { |
362 int nStartPageNum = atol(cbMidRange.Mid(0, nMid)); | 362 int nStartPageNum = atol(cbMidRange.Mid(0, nMid)); |
363 if (nStartPageNum == 0) | 363 if (nStartPageNum == 0) |
364 return FALSE; | 364 return false; |
365 | 365 |
366 ++nMid; | 366 ++nMid; |
367 int nEnd = cbMidRange.GetLength() - nMid; | 367 int nEnd = cbMidRange.GetLength() - nMid; |
368 if (nEnd == 0) | 368 if (nEnd == 0) |
369 return FALSE; | 369 return false; |
370 | 370 |
371 int nEndPageNum = atol(cbMidRange.Mid(nMid, nEnd)); | 371 int nEndPageNum = atol(cbMidRange.Mid(nMid, nEnd)); |
372 if (nStartPageNum < 0 || | 372 if (nStartPageNum < 0 || |
373 nStartPageNum >nEndPageNum || | 373 nStartPageNum >nEndPageNum || |
374 nEndPageNum > nCount) { | 374 nEndPageNum > nCount) { |
375 return FALSE; | 375 return false; |
376 } else { | 376 } else { |
377 for (int i = nStartPageNum; i <= nEndPageNum; ++i) { | 377 for (int i = nStartPageNum; i <= nEndPageNum; ++i) { |
378 pageArray->Add(i); | 378 pageArray->Add(i); |
379 } | 379 } |
380 } | 380 } |
381 } | 381 } |
382 nStringFrom = nStringTo + 1; | 382 nStringFrom = nStringTo + 1; |
383 } | 383 } |
384 } | 384 } |
385 return TRUE; | 385 return true; |
386 } | 386 } |
387 | 387 |
388 DLLEXPORT FPDF_BOOL STDCALL FPDF_ImportPages(FPDF_DOCUMENT dest_doc, | 388 DLLEXPORT FPDF_BOOL STDCALL FPDF_ImportPages(FPDF_DOCUMENT dest_doc, |
389 FPDF_DOCUMENT src_doc, | 389 FPDF_DOCUMENT src_doc, |
390 FPDF_BYTESTRING pagerange, | 390 FPDF_BYTESTRING pagerange, |
391 int index) | 391 int index) |
392 { | 392 { |
393 if (!dest_doc || !src_doc) | 393 if (!dest_doc || !src_doc) |
394 return FALSE; | 394 return false; |
395 | 395 |
396 CFX_WordArray pageArray; | 396 CFX_WordArray pageArray; |
397 CPDF_Document* pSrcDoc = (CPDF_Document*)src_doc; | 397 CPDF_Document* pSrcDoc = (CPDF_Document*)src_doc; |
398 int nCount = pSrcDoc->GetPageCount(); | 398 int nCount = pSrcDoc->GetPageCount(); |
399 if (pagerange) { | 399 if (pagerange) { |
400 if (!ParserPageRangeString(pagerange,&pageArray,nCount)) | 400 if (!ParserPageRangeString(pagerange,&pageArray,nCount)) |
401 return FALSE; | 401 return false; |
402 } else { | 402 } else { |
403 for (int i = 1; i <= nCount; ++i) { | 403 for (int i = 1; i <= nCount; ++i) { |
404 pageArray.Add(i); | 404 pageArray.Add(i); |
405 } | 405 } |
406 } | 406 } |
407 | 407 |
408 CPDF_Document* pDestDoc = (CPDF_Document*)dest_doc; | 408 CPDF_Document* pDestDoc = (CPDF_Document*)dest_doc; |
409 CPDF_PageOrganizer pageOrg; | 409 CPDF_PageOrganizer pageOrg; |
410 | 410 |
411 pageOrg.PDFDocInit(pDestDoc, pSrcDoc); | 411 pageOrg.PDFDocInit(pDestDoc, pSrcDoc); |
412 | 412 |
413 return pageOrg.ExportPage(pSrcDoc,&pageArray,pDestDoc,index); | 413 return pageOrg.ExportPage(pSrcDoc,&pageArray,pDestDoc,index); |
414 } | 414 } |
415 | 415 |
416 DLLEXPORT FPDF_BOOL STDCALL FPDF_CopyViewerPreferences(FPDF_DOCUMENT dest_doc, | 416 DLLEXPORT FPDF_BOOL STDCALL FPDF_CopyViewerPreferences(FPDF_DOCUMENT dest_doc, |
417 FPDF_DOCUMENT src_doc) | 417 FPDF_DOCUMENT src_doc) |
418 { | 418 { |
419 if (!src_doc || !dest_doc) | 419 if (!src_doc || !dest_doc) |
420 return false; | 420 return false; |
421 | 421 |
422 CPDF_Document* pSrcDoc = (CPDF_Document*)src_doc; | 422 CPDF_Document* pSrcDoc = (CPDF_Document*)src_doc; |
423 CPDF_Dictionary* pSrcDict = pSrcDoc->GetRoot(); | 423 CPDF_Dictionary* pSrcDict = pSrcDoc->GetRoot(); |
424 pSrcDict = pSrcDict->GetDict(FX_BSTRC("ViewerPreferences"));; | 424 pSrcDict = pSrcDict->GetDict(FX_BSTRC("ViewerPreferences"));; |
425 if (!pSrcDict) | 425 if (!pSrcDict) |
426 return FALSE; | 426 return false; |
427 | 427 |
428 CPDF_Document* pDstDoc = (CPDF_Document*)dest_doc; | 428 CPDF_Document* pDstDoc = (CPDF_Document*)dest_doc; |
429 CPDF_Dictionary* pDstDict = pDstDoc->GetRoot(); | 429 CPDF_Dictionary* pDstDict = pDstDoc->GetRoot(); |
430 if (!pDstDict) | 430 if (!pDstDict) |
431 return FALSE; | 431 return false; |
432 pDstDict->SetAt(FX_BSTRC("ViewerPreferences"), pSrcDict->Clone(TRUE)); | 432 pDstDict->SetAt(FX_BSTRC("ViewerPreferences"), pSrcDict->Clone(true)); |
433 return TRUE; | 433 return true; |
434 } | 434 } |
OLD | NEW |