| 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 "fpdfsdk/include/fsdk_define.h" | 9 #include "fpdfsdk/include/fsdk_define.h" |
| 10 #include "third_party/base/nonstd_unique_ptr.h" | 10 #include "third_party/base/nonstd_unique_ptr.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 | 36 |
| 37 FX_BOOL CPDF_PageOrganizer::PDFDocInit(CPDF_Document* pDestPDFDoc, | 37 FX_BOOL CPDF_PageOrganizer::PDFDocInit(CPDF_Document* pDestPDFDoc, |
| 38 CPDF_Document* pSrcPDFDoc) { | 38 CPDF_Document* pSrcPDFDoc) { |
| 39 if (!pDestPDFDoc || !pSrcPDFDoc) | 39 if (!pDestPDFDoc || !pSrcPDFDoc) |
| 40 return FALSE; | 40 return FALSE; |
| 41 | 41 |
| 42 CPDF_Dictionary* pNewRoot = pDestPDFDoc->GetRoot(); | 42 CPDF_Dictionary* pNewRoot = pDestPDFDoc->GetRoot(); |
| 43 if (!pNewRoot) | 43 if (!pNewRoot) |
| 44 return FALSE; | 44 return FALSE; |
| 45 | 45 |
| 46 // Set the document information//////////////////////////////////////////// | 46 // Set the document information |
| 47 | |
| 48 CPDF_Dictionary* DInfoDict = pDestPDFDoc->GetInfo(); | 47 CPDF_Dictionary* DInfoDict = pDestPDFDoc->GetInfo(); |
| 49 if (!DInfoDict) | 48 if (!DInfoDict) |
| 50 return FALSE; | 49 return FALSE; |
| 51 | 50 |
| 52 CFX_ByteString producerstr; | 51 CFX_ByteString producerstr; |
| 53 producerstr.Format("PDFium"); | 52 producerstr.Format("PDFium"); |
| 54 DInfoDict->SetAt("Producer", new CPDF_String(producerstr)); | 53 DInfoDict->SetAt("Producer", new CPDF_String(producerstr, FALSE)); |
| 55 | 54 |
| 56 // Set type//////////////////////////////////////////////////////////////// | 55 // Set type |
| 57 CFX_ByteString cbRootType = pNewRoot->GetString("Type", ""); | 56 CFX_ByteString cbRootType = pNewRoot->GetString("Type", ""); |
| 58 if (cbRootType.Equal("")) { | 57 if (cbRootType.Equal("")) { |
| 59 pNewRoot->SetAt("Type", new CPDF_Name("Catalog")); | 58 pNewRoot->SetAt("Type", new CPDF_Name("Catalog")); |
| 60 } | 59 } |
| 61 | 60 |
| 62 CPDF_Object* pElement = pNewRoot->GetElement("Pages"); | 61 CPDF_Object* pElement = pNewRoot->GetElement("Pages"); |
| 63 CPDF_Dictionary* pNewPages = | 62 CPDF_Dictionary* pNewPages = |
| 64 pElement ? ToDictionary(pElement->GetDirect()) : nullptr; | 63 pElement ? ToDictionary(pElement->GetDirect()) : nullptr; |
| 65 if (!pNewPages) { | 64 if (!pNewPages) { |
| 66 pNewPages = new CPDF_Dictionary; | 65 pNewPages = new CPDF_Dictionary; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 93 int curpage = nIndex; | 92 int curpage = nIndex; |
| 94 | 93 |
| 95 nonstd::unique_ptr<ObjectNumberMap> pObjNumberMap(new ObjectNumberMap); | 94 nonstd::unique_ptr<ObjectNumberMap> pObjNumberMap(new ObjectNumberMap); |
| 96 | 95 |
| 97 for (int i = 0; i < nPageNum->GetSize(); ++i) { | 96 for (int i = 0; i < nPageNum->GetSize(); ++i) { |
| 98 CPDF_Dictionary* pCurPageDict = pDestPDFDoc->CreateNewPage(curpage); | 97 CPDF_Dictionary* pCurPageDict = pDestPDFDoc->CreateNewPage(curpage); |
| 99 CPDF_Dictionary* pSrcPageDict = pSrcPDFDoc->GetPage(nPageNum->GetAt(i) - 1); | 98 CPDF_Dictionary* pSrcPageDict = pSrcPDFDoc->GetPage(nPageNum->GetAt(i) - 1); |
| 100 if (!pSrcPageDict || !pCurPageDict) | 99 if (!pSrcPageDict || !pCurPageDict) |
| 101 return FALSE; | 100 return FALSE; |
| 102 | 101 |
| 103 // Clone the page dictionary/////////// | 102 // Clone the page dictionary |
| 104 FX_POSITION SrcPos = pSrcPageDict->GetStartPos(); | 103 FX_POSITION SrcPos = pSrcPageDict->GetStartPos(); |
| 105 while (SrcPos) { | 104 while (SrcPos) { |
| 106 CFX_ByteString cbSrcKeyStr; | 105 CFX_ByteString cbSrcKeyStr; |
| 107 CPDF_Object* pObj = pSrcPageDict->GetNextElement(SrcPos, cbSrcKeyStr); | 106 CPDF_Object* pObj = pSrcPageDict->GetNextElement(SrcPos, cbSrcKeyStr); |
| 108 if (cbSrcKeyStr.Compare(("Type")) && cbSrcKeyStr.Compare(("Parent"))) { | 107 if (cbSrcKeyStr.Compare(("Type")) && cbSrcKeyStr.Compare(("Parent"))) { |
| 109 if (pCurPageDict->KeyExist(cbSrcKeyStr)) | 108 if (pCurPageDict->KeyExist(cbSrcKeyStr)) |
| 110 pCurPageDict->RemoveAt(cbSrcKeyStr); | 109 pCurPageDict->RemoveAt(cbSrcKeyStr); |
| 111 pCurPageDict->SetAt(cbSrcKeyStr, pObj->Clone()); | 110 pCurPageDict->SetAt(cbSrcKeyStr, pObj->Clone()); |
| 112 } | 111 } |
| 113 } | 112 } |
| 114 | 113 |
| 115 // inheritable item/////////////////////// | 114 // inheritable item |
| 116 CPDF_Object* pInheritable = nullptr; | 115 CPDF_Object* pInheritable = nullptr; |
| 117 // 1 MediaBox //required | 116 // 1 MediaBox //required |
| 118 if (!pCurPageDict->KeyExist("MediaBox")) { | 117 if (!pCurPageDict->KeyExist("MediaBox")) { |
| 119 pInheritable = PageDictGetInheritableTag(pSrcPageDict, "MediaBox"); | 118 pInheritable = PageDictGetInheritableTag(pSrcPageDict, "MediaBox"); |
| 120 if (!pInheritable) { | 119 if (!pInheritable) { |
| 121 // Search the "CropBox" from source page dictionary, | 120 // Search the "CropBox" from source page dictionary, |
| 122 // if not exists,we take the letter size. | 121 // if not exists,we take the letter size. |
| 123 pInheritable = PageDictGetInheritableTag(pSrcPageDict, "CropBox"); | 122 pInheritable = PageDictGetInheritableTag(pSrcPageDict, "CropBox"); |
| 124 if (pInheritable) { | 123 if (pInheritable) { |
| 125 pCurPageDict->SetAt("MediaBox", pInheritable->Clone()); | 124 pCurPageDict->SetAt("MediaBox", pInheritable->Clone()); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 149 if (pInheritable) | 148 if (pInheritable) |
| 150 pCurPageDict->SetAt("CropBox", pInheritable->Clone()); | 149 pCurPageDict->SetAt("CropBox", pInheritable->Clone()); |
| 151 } | 150 } |
| 152 // 4 Rotate //Optional | 151 // 4 Rotate //Optional |
| 153 if (!pCurPageDict->KeyExist("Rotate")) { | 152 if (!pCurPageDict->KeyExist("Rotate")) { |
| 154 pInheritable = PageDictGetInheritableTag(pSrcPageDict, "Rotate"); | 153 pInheritable = PageDictGetInheritableTag(pSrcPageDict, "Rotate"); |
| 155 if (pInheritable) | 154 if (pInheritable) |
| 156 pCurPageDict->SetAt("Rotate", pInheritable->Clone()); | 155 pCurPageDict->SetAt("Rotate", pInheritable->Clone()); |
| 157 } | 156 } |
| 158 | 157 |
| 159 ///////////////////////////////////////////// | |
| 160 // Update the reference | 158 // Update the reference |
| 161 FX_DWORD dwOldPageObj = pSrcPageDict->GetObjNum(); | 159 FX_DWORD dwOldPageObj = pSrcPageDict->GetObjNum(); |
| 162 FX_DWORD dwNewPageObj = pCurPageDict->GetObjNum(); | 160 FX_DWORD dwNewPageObj = pCurPageDict->GetObjNum(); |
| 163 | 161 |
| 164 (*pObjNumberMap)[dwOldPageObj] = dwNewPageObj; | 162 (*pObjNumberMap)[dwOldPageObj] = dwNewPageObj; |
| 165 | 163 |
| 166 UpdateReference(pCurPageDict, pDestPDFDoc, pObjNumberMap.get()); | 164 UpdateReference(pCurPageDict, pDestPDFDoc, pObjNumberMap.get()); |
| 167 ++curpage; | 165 ++curpage; |
| 168 } | 166 } |
| 169 | 167 |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 if (!pSrcDict) | 398 if (!pSrcDict) |
| 401 return FALSE; | 399 return FALSE; |
| 402 | 400 |
| 403 CPDF_Dictionary* pDstDict = pDstDoc->GetRoot(); | 401 CPDF_Dictionary* pDstDict = pDstDoc->GetRoot(); |
| 404 if (!pDstDict) | 402 if (!pDstDict) |
| 405 return FALSE; | 403 return FALSE; |
| 406 | 404 |
| 407 pDstDict->SetAt("ViewerPreferences", pSrcDict->Clone(TRUE)); | 405 pDstDict->SetAt("ViewerPreferences", pSrcDict->Clone(TRUE)); |
| 408 return TRUE; | 406 return TRUE; |
| 409 } | 407 } |
| OLD | NEW |