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 <memory> | 9 #include <memory> |
10 | 10 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 | 94 |
95 std::unique_ptr<ObjectNumberMap> pObjNumberMap(new ObjectNumberMap); | 95 std::unique_ptr<ObjectNumberMap> pObjNumberMap(new ObjectNumberMap); |
96 | 96 |
97 for (int i = 0; i < nPageNum->GetSize(); ++i) { | 97 for (int i = 0; i < nPageNum->GetSize(); ++i) { |
98 CPDF_Dictionary* pCurPageDict = pDestPDFDoc->CreateNewPage(curpage); | 98 CPDF_Dictionary* pCurPageDict = pDestPDFDoc->CreateNewPage(curpage); |
99 CPDF_Dictionary* pSrcPageDict = pSrcPDFDoc->GetPage(nPageNum->GetAt(i) - 1); | 99 CPDF_Dictionary* pSrcPageDict = pSrcPDFDoc->GetPage(nPageNum->GetAt(i) - 1); |
100 if (!pSrcPageDict || !pCurPageDict) | 100 if (!pSrcPageDict || !pCurPageDict) |
101 return FALSE; | 101 return FALSE; |
102 | 102 |
103 // Clone the page dictionary | 103 // Clone the page dictionary |
104 FX_POSITION SrcPos = pSrcPageDict->GetStartPos(); | 104 for (const auto& it : *pSrcPageDict) { |
105 while (SrcPos) { | 105 const CFX_ByteString& cbSrcKeyStr = it.first; |
106 CFX_ByteString cbSrcKeyStr; | 106 CPDF_Object* pObj = it.second; |
107 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 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 case PDFOBJ_REFERENCE: { | 206 case PDFOBJ_REFERENCE: { |
208 CPDF_Reference* pReference = pObj->AsReference(); | 207 CPDF_Reference* pReference = pObj->AsReference(); |
209 FX_DWORD newobjnum = GetNewObjId(pDoc, pObjNumberMap, pReference); | 208 FX_DWORD newobjnum = GetNewObjId(pDoc, pObjNumberMap, pReference); |
210 if (newobjnum == 0) | 209 if (newobjnum == 0) |
211 return FALSE; | 210 return FALSE; |
212 pReference->SetRef(pDoc, newobjnum); | 211 pReference->SetRef(pDoc, newobjnum); |
213 break; | 212 break; |
214 } | 213 } |
215 case PDFOBJ_DICTIONARY: { | 214 case PDFOBJ_DICTIONARY: { |
216 CPDF_Dictionary* pDict = pObj->AsDictionary(); | 215 CPDF_Dictionary* pDict = pObj->AsDictionary(); |
217 | 216 for (const auto& it : *pDict) { |
218 FX_POSITION pos = pDict->GetStartPos(); | 217 const CFX_ByteString& key = it.first; |
219 while (pos) { | 218 CPDF_Object* pNextObj = it.second; |
220 CFX_ByteString key(""); | |
221 CPDF_Object* pNextObj = pDict->GetNextElement(pos, key); | |
222 if (!FXSYS_strcmp(key, "Parent") || !FXSYS_strcmp(key, "Prev") || | 219 if (!FXSYS_strcmp(key, "Parent") || !FXSYS_strcmp(key, "Prev") || |
223 !FXSYS_strcmp(key, "First")) { | 220 !FXSYS_strcmp(key, "First")) { |
224 continue; | 221 continue; |
225 } | 222 } |
226 if (pNextObj) { | 223 if (pNextObj) { |
227 if (!UpdateReference(pNextObj, pDoc, pObjNumberMap)) | 224 if (!UpdateReference(pNextObj, pDoc, pObjNumberMap)) |
228 pDict->RemoveAt(key); | 225 pDict->RemoveAt(key); |
229 } else { | 226 } else { |
230 return FALSE; | 227 return FALSE; |
231 } | 228 } |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 if (!pSrcDict) | 396 if (!pSrcDict) |
400 return FALSE; | 397 return FALSE; |
401 | 398 |
402 CPDF_Dictionary* pDstDict = pDstDoc->GetRoot(); | 399 CPDF_Dictionary* pDstDict = pDstDoc->GetRoot(); |
403 if (!pDstDict) | 400 if (!pDstDict) |
404 return FALSE; | 401 return FALSE; |
405 | 402 |
406 pDstDict->SetAt("ViewerPreferences", pSrcDict->Clone(TRUE)); | 403 pDstDict->SetAt("ViewerPreferences", pSrcDict->Clone(TRUE)); |
407 return TRUE; | 404 return TRUE; |
408 } | 405 } |
OLD | NEW |