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