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> |
(...skipping 10 matching lines...) Expand all Loading... |
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<FX_DWORD, FX_DWORD>; | 25 using ObjectNumberMap = std::map<FX_DWORD, FX_DWORD>; |
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 FX_BOOL PDFDocInit(CPDF_Document* pDestPDFDoc, CPDF_Document* pSrcPDFDoc); |
30 FX_BOOL ExportPage(CPDF_Document* pSrcPDFDoc, | 30 FX_BOOL ExportPage(CPDF_Document* pSrcPDFDoc, |
31 std::vector<FX_WORD>* 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 CFX_ByteString nSrctag); | 35 CFX_ByteString nSrctag); |
36 FX_BOOL UpdateReference(CPDF_Object* pObj, | 36 FX_BOOL UpdateReference(CPDF_Object* pObj, |
37 CPDF_Document* pDoc, | 37 CPDF_Document* pDoc, |
38 ObjectNumberMap* pObjNumberMap); | 38 ObjectNumberMap* pObjNumberMap); |
39 FX_DWORD GetNewObjId(CPDF_Document* pDoc, | 39 FX_DWORD GetNewObjId(CPDF_Document* pDoc, |
40 ObjectNumberMap* pObjNumberMap, | 40 ObjectNumberMap* pObjNumberMap, |
41 CPDF_Reference* pRef); | 41 CPDF_Reference* pRef); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 FX_DWORD Kidsobjnum = pDestPDFDoc->AddIndirectObject(pNewKids); | 89 FX_DWORD Kidsobjnum = pDestPDFDoc->AddIndirectObject(pNewKids); |
90 | 90 |
91 pNewPages->SetAt("Kids", new CPDF_Reference(pDestPDFDoc, Kidsobjnum)); | 91 pNewPages->SetAt("Kids", new CPDF_Reference(pDestPDFDoc, Kidsobjnum)); |
92 pNewPages->SetAt("Count", new CPDF_Number(0)); | 92 pNewPages->SetAt("Count", new CPDF_Number(0)); |
93 } | 93 } |
94 | 94 |
95 return TRUE; | 95 return TRUE; |
96 } | 96 } |
97 | 97 |
98 FX_BOOL CPDF_PageOrganizer::ExportPage(CPDF_Document* pSrcPDFDoc, | 98 FX_BOOL CPDF_PageOrganizer::ExportPage(CPDF_Document* pSrcPDFDoc, |
99 std::vector<FX_WORD>* pPageNums, | 99 std::vector<uint16_t>* pPageNums, |
100 CPDF_Document* pDestPDFDoc, | 100 CPDF_Document* pDestPDFDoc, |
101 int nIndex) { | 101 int nIndex) { |
102 int curpage = nIndex; | 102 int curpage = nIndex; |
103 std::unique_ptr<ObjectNumberMap> pObjNumberMap(new ObjectNumberMap); | 103 std::unique_ptr<ObjectNumberMap> pObjNumberMap(new ObjectNumberMap); |
104 int nSize = pdfium::CollectionSize<int>(*pPageNums); | 104 int nSize = pdfium::CollectionSize<int>(*pPageNums); |
105 for (int i = 0; i < nSize; ++i) { | 105 for (int i = 0; i < nSize; ++i) { |
106 CPDF_Dictionary* pCurPageDict = pDestPDFDoc->CreateNewPage(curpage); | 106 CPDF_Dictionary* pCurPageDict = pDestPDFDoc->CreateNewPage(curpage); |
107 CPDF_Dictionary* pSrcPageDict = pSrcPDFDoc->GetPage(pPageNums->at(i) - 1); | 107 CPDF_Dictionary* pSrcPageDict = pSrcPDFDoc->GetPage(pPageNums->at(i) - 1); |
108 if (!pSrcPageDict || !pCurPageDict) | 108 if (!pSrcPageDict || !pCurPageDict) |
109 return FALSE; | 109 return FALSE; |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 dwNewObjNum = pDoc->AddIndirectObject(pClone); | 307 dwNewObjNum = pDoc->AddIndirectObject(pClone); |
308 (*pObjNumberMap)[dwObjnum] = dwNewObjNum; | 308 (*pObjNumberMap)[dwObjnum] = dwNewObjNum; |
309 if (!UpdateReference(pClone, pDoc, pObjNumberMap)) { | 309 if (!UpdateReference(pClone, pDoc, pObjNumberMap)) { |
310 pClone->Release(); | 310 pClone->Release(); |
311 return 0; | 311 return 0; |
312 } | 312 } |
313 return dwNewObjNum; | 313 return dwNewObjNum; |
314 } | 314 } |
315 | 315 |
316 FPDF_BOOL ParserPageRangeString(CFX_ByteString rangstring, | 316 FPDF_BOOL ParserPageRangeString(CFX_ByteString rangstring, |
317 std::vector<FX_WORD>* pageArray, | 317 std::vector<uint16_t>* pageArray, |
318 int nCount) { | 318 int nCount) { |
319 if (rangstring.GetLength() != 0) { | 319 if (rangstring.GetLength() != 0) { |
320 rangstring.Remove(' '); | 320 rangstring.Remove(' '); |
321 int nLength = rangstring.GetLength(); | 321 int nLength = rangstring.GetLength(); |
322 CFX_ByteString cbCompareString("0123456789-,"); | 322 CFX_ByteString cbCompareString("0123456789-,"); |
323 for (int i = 0; i < nLength; ++i) { | 323 for (int i = 0; i < nLength; ++i) { |
324 if (cbCompareString.Find(rangstring[i]) == -1) | 324 if (cbCompareString.Find(rangstring[i]) == -1) |
325 return FALSE; | 325 return FALSE; |
326 } | 326 } |
327 CFX_ByteString cbMidRange; | 327 CFX_ByteString cbMidRange; |
328 int nStringFrom = 0; | 328 int nStringFrom = 0; |
329 int nStringTo = 0; | 329 int nStringTo = 0; |
330 while (nStringTo < nLength) { | 330 while (nStringTo < nLength) { |
331 nStringTo = rangstring.Find(',', nStringFrom); | 331 nStringTo = rangstring.Find(',', nStringFrom); |
332 if (nStringTo == -1) | 332 if (nStringTo == -1) |
333 nStringTo = nLength; | 333 nStringTo = nLength; |
334 cbMidRange = rangstring.Mid(nStringFrom, nStringTo - nStringFrom); | 334 cbMidRange = rangstring.Mid(nStringFrom, nStringTo - nStringFrom); |
335 int nMid = cbMidRange.Find('-'); | 335 int nMid = cbMidRange.Find('-'); |
336 if (nMid == -1) { | 336 if (nMid == -1) { |
337 long lPageNum = atol(cbMidRange); | 337 long lPageNum = atol(cbMidRange); |
338 if (lPageNum <= 0 || lPageNum > nCount) | 338 if (lPageNum <= 0 || lPageNum > nCount) |
339 return FALSE; | 339 return FALSE; |
340 pageArray->push_back((FX_WORD)lPageNum); | 340 pageArray->push_back((uint16_t)lPageNum); |
341 } else { | 341 } else { |
342 int nStartPageNum = atol(cbMidRange.Mid(0, nMid)); | 342 int nStartPageNum = atol(cbMidRange.Mid(0, nMid)); |
343 if (nStartPageNum == 0) | 343 if (nStartPageNum == 0) |
344 return FALSE; | 344 return FALSE; |
345 | 345 |
346 ++nMid; | 346 ++nMid; |
347 int nEnd = cbMidRange.GetLength() - nMid; | 347 int nEnd = cbMidRange.GetLength() - nMid; |
348 if (nEnd == 0) | 348 if (nEnd == 0) |
349 return FALSE; | 349 return FALSE; |
350 | 350 |
(...skipping 17 matching lines...) Expand all Loading... |
368 FPDF_BYTESTRING pagerange, | 368 FPDF_BYTESTRING pagerange, |
369 int index) { | 369 int index) { |
370 CPDF_Document* pDestDoc = CPDFDocumentFromFPDFDocument(dest_doc); | 370 CPDF_Document* pDestDoc = CPDFDocumentFromFPDFDocument(dest_doc); |
371 if (!dest_doc) | 371 if (!dest_doc) |
372 return FALSE; | 372 return FALSE; |
373 | 373 |
374 CPDF_Document* pSrcDoc = CPDFDocumentFromFPDFDocument(src_doc); | 374 CPDF_Document* pSrcDoc = CPDFDocumentFromFPDFDocument(src_doc); |
375 if (!pSrcDoc) | 375 if (!pSrcDoc) |
376 return FALSE; | 376 return FALSE; |
377 | 377 |
378 std::vector<FX_WORD> pageArray; | 378 std::vector<uint16_t> pageArray; |
379 int nCount = pSrcDoc->GetPageCount(); | 379 int nCount = pSrcDoc->GetPageCount(); |
380 if (pagerange) { | 380 if (pagerange) { |
381 if (!ParserPageRangeString(pagerange, &pageArray, nCount)) | 381 if (!ParserPageRangeString(pagerange, &pageArray, nCount)) |
382 return FALSE; | 382 return FALSE; |
383 } else { | 383 } else { |
384 for (int i = 1; i <= nCount; ++i) { | 384 for (int i = 1; i <= nCount; ++i) { |
385 pageArray.push_back(i); | 385 pageArray.push_back(i); |
386 } | 386 } |
387 } | 387 } |
388 | 388 |
(...skipping 17 matching lines...) Expand all Loading... |
406 if (!pSrcDict) | 406 if (!pSrcDict) |
407 return FALSE; | 407 return FALSE; |
408 | 408 |
409 CPDF_Dictionary* pDstDict = pDstDoc->GetRoot(); | 409 CPDF_Dictionary* pDstDict = pDstDoc->GetRoot(); |
410 if (!pDstDict) | 410 if (!pDstDict) |
411 return FALSE; | 411 return FALSE; |
412 | 412 |
413 pDstDict->SetAt("ViewerPreferences", pSrcDict->Clone(TRUE)); | 413 pDstDict->SetAt("ViewerPreferences", pSrcDict->Clone(TRUE)); |
414 return TRUE; | 414 return TRUE; |
415 } | 415 } |
OLD | NEW |