| 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 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 DInfoDict->SetAt("Producer", new CPDF_String(producerstr)); | 53 DInfoDict->SetAt("Producer", new CPDF_String(producerstr)); |
| 54 | 54 |
| 55 // Set type//////////////////////////////////////////////////////////////// | 55 // Set type//////////////////////////////////////////////////////////////// |
| 56 CFX_ByteString cbRootType = pNewRoot->GetString("Type", ""); | 56 CFX_ByteString cbRootType = pNewRoot->GetString("Type", ""); |
| 57 if (cbRootType.Equal("")) { | 57 if (cbRootType.Equal("")) { |
| 58 pNewRoot->SetAt("Type", new CPDF_Name("Catalog")); | 58 pNewRoot->SetAt("Type", new CPDF_Name("Catalog")); |
| 59 } | 59 } |
| 60 | 60 |
| 61 CPDF_Object* pElement = pNewRoot->GetElement("Pages"); | 61 CPDF_Object* pElement = pNewRoot->GetElement("Pages"); |
| 62 CPDF_Dictionary* pNewPages = | 62 CPDF_Dictionary* pNewPages = |
| 63 pElement ? (CPDF_Dictionary*)pElement->GetDirect() : nullptr; | 63 pElement ? ToDictionary(pElement->GetDirect()) : nullptr; |
| 64 if (!pNewPages) { | 64 if (!pNewPages) { |
| 65 pNewPages = new CPDF_Dictionary; | 65 pNewPages = new CPDF_Dictionary; |
| 66 FX_DWORD NewPagesON = pDestPDFDoc->AddIndirectObject(pNewPages); | 66 FX_DWORD NewPagesON = pDestPDFDoc->AddIndirectObject(pNewPages); |
| 67 pNewRoot->SetAt("Pages", new CPDF_Reference(pDestPDFDoc, NewPagesON)); | 67 pNewRoot->SetAt("Pages", new CPDF_Reference(pDestPDFDoc, NewPagesON)); |
| 68 } | 68 } |
| 69 | 69 |
| 70 CFX_ByteString cbPageType = pNewPages->GetString("Type", ""); | 70 CFX_ByteString cbPageType = pNewPages->GetString("Type", ""); |
| 71 if (cbPageType.Equal("")) { | 71 if (cbPageType.Equal("")) { |
| 72 pNewPages->SetAt("Type", new CPDF_Name("Pages")); | 72 pNewPages->SetAt("Type", new CPDF_Name("Pages")); |
| 73 } | 73 } |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 return nullptr; | 176 return nullptr; |
| 177 if (!pDict->KeyExist("Parent") || !pDict->KeyExist("Type")) | 177 if (!pDict->KeyExist("Parent") || !pDict->KeyExist("Type")) |
| 178 return nullptr; | 178 return nullptr; |
| 179 | 179 |
| 180 CPDF_Object* pType = pDict->GetElement("Type")->GetDirect(); | 180 CPDF_Object* pType = pDict->GetElement("Type")->GetDirect(); |
| 181 if (!pType || pType->GetType() != PDFOBJ_NAME) | 181 if (!pType || pType->GetType() != PDFOBJ_NAME) |
| 182 return nullptr; | 182 return nullptr; |
| 183 if (pType->GetString().Compare("Page")) | 183 if (pType->GetString().Compare("Page")) |
| 184 return nullptr; | 184 return nullptr; |
| 185 | 185 |
| 186 CPDF_Object* pParent = pDict->GetElement("Parent")->GetDirect(); | 186 CPDF_Dictionary* pp = ToDictionary(pDict->GetElement("Parent")->GetDirect()); |
| 187 if (!pParent || pParent->GetType() != PDFOBJ_DICTIONARY) | 187 if (!pp) |
| 188 return nullptr; | 188 return nullptr; |
| 189 | 189 |
| 190 if (pDict->KeyExist((const char*)nSrctag)) | 190 if (pDict->KeyExist((const char*)nSrctag)) |
| 191 return pDict->GetElement((const char*)nSrctag); | 191 return pDict->GetElement((const char*)nSrctag); |
| 192 | 192 |
| 193 CPDF_Dictionary* pp = (CPDF_Dictionary*)pParent; | |
| 194 while (pp) { | 193 while (pp) { |
| 195 if (pp->KeyExist((const char*)nSrctag)) { | 194 if (pp->KeyExist((const char*)nSrctag)) { |
| 196 return pp->GetElement((const char*)nSrctag); | 195 return pp->GetElement((const char*)nSrctag); |
| 197 } | 196 } |
| 198 if (!pp->KeyExist("Parent")) { | 197 if (!pp->KeyExist("Parent")) { |
| 199 break; | 198 break; |
| 200 } | 199 } |
| 201 pp = (CPDF_Dictionary*)pp->GetElement("Parent")->GetDirect(); | 200 pp = ToDictionary(pp->GetElement("Parent")->GetDirect()); |
| 202 if (pp->GetType() == PDFOBJ_NULL) { | |
| 203 break; | |
| 204 } | |
| 205 } | 201 } |
| 206 | |
| 207 return nullptr; | 202 return nullptr; |
| 208 } | 203 } |
| 209 | 204 |
| 210 FX_BOOL CPDF_PageOrganizer::UpdateReference(CPDF_Object* pObj, | 205 FX_BOOL CPDF_PageOrganizer::UpdateReference(CPDF_Object* pObj, |
| 211 CPDF_Document* pDoc, | 206 CPDF_Document* pDoc, |
| 212 ObjectNumberMap* pObjNumberMap) { | 207 ObjectNumberMap* pObjNumberMap) { |
| 213 switch (pObj->GetType()) { | 208 switch (pObj->GetType()) { |
| 214 case PDFOBJ_REFERENCE: { | 209 case PDFOBJ_REFERENCE: { |
| 215 CPDF_Reference* pReference = (CPDF_Reference*)pObj; | 210 CPDF_Reference* pReference = (CPDF_Reference*)pObj; |
| 216 FX_DWORD newobjnum = GetNewObjId(pDoc, pObjNumberMap, pReference); | 211 FX_DWORD newobjnum = GetNewObjId(pDoc, pObjNumberMap, pReference); |
| 217 if (newobjnum == 0) | 212 if (newobjnum == 0) |
| 218 return FALSE; | 213 return FALSE; |
| 219 pReference->SetRef(pDoc, newobjnum); | 214 pReference->SetRef(pDoc, newobjnum); |
| 220 break; | 215 break; |
| 221 } | 216 } |
| 222 case PDFOBJ_DICTIONARY: { | 217 case PDFOBJ_DICTIONARY: { |
| 223 CPDF_Dictionary* pDict = (CPDF_Dictionary*)pObj; | 218 CPDF_Dictionary* pDict = pObj->AsDictionary(); |
| 224 | 219 |
| 225 FX_POSITION pos = pDict->GetStartPos(); | 220 FX_POSITION pos = pDict->GetStartPos(); |
| 226 while (pos) { | 221 while (pos) { |
| 227 CFX_ByteString key(""); | 222 CFX_ByteString key(""); |
| 228 CPDF_Object* pNextObj = pDict->GetNextElement(pos, key); | 223 CPDF_Object* pNextObj = pDict->GetNextElement(pos, key); |
| 229 if (!FXSYS_strcmp(key, "Parent") || !FXSYS_strcmp(key, "Prev") || | 224 if (!FXSYS_strcmp(key, "Parent") || !FXSYS_strcmp(key, "Prev") || |
| 230 !FXSYS_strcmp(key, "First")) { | 225 !FXSYS_strcmp(key, "First")) { |
| 231 continue; | 226 continue; |
| 232 } | 227 } |
| 233 if (pNextObj) { | 228 if (pNextObj) { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 return dwNewObjNum; | 279 return dwNewObjNum; |
| 285 | 280 |
| 286 CPDF_Object* pDirect = pRef->GetDirect(); | 281 CPDF_Object* pDirect = pRef->GetDirect(); |
| 287 if (!pDirect) | 282 if (!pDirect) |
| 288 return 0; | 283 return 0; |
| 289 | 284 |
| 290 CPDF_Object* pClone = pDirect->Clone(); | 285 CPDF_Object* pClone = pDirect->Clone(); |
| 291 if (!pClone) | 286 if (!pClone) |
| 292 return 0; | 287 return 0; |
| 293 | 288 |
| 294 if (pClone->GetType() == PDFOBJ_DICTIONARY) { | 289 if (CPDF_Dictionary* pDictClone = pClone->AsDictionary()) { |
| 295 CPDF_Dictionary* pDictClone = (CPDF_Dictionary*)pClone; | |
| 296 if (pDictClone->KeyExist("Type")) { | 290 if (pDictClone->KeyExist("Type")) { |
| 297 CFX_ByteString strType = pDictClone->GetString("Type"); | 291 CFX_ByteString strType = pDictClone->GetString("Type"); |
| 298 if (!FXSYS_stricmp(strType, "Pages")) { | 292 if (!FXSYS_stricmp(strType, "Pages")) { |
| 299 pDictClone->Release(); | 293 pDictClone->Release(); |
| 300 return 4; | 294 return 4; |
| 301 } | 295 } |
| 302 if (!FXSYS_stricmp(strType, "Page")) { | 296 if (!FXSYS_stricmp(strType, "Page")) { |
| 303 pDictClone->Release(); | 297 pDictClone->Release(); |
| 304 return 0; | 298 return 0; |
| 305 } | 299 } |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 if (!pSrcDict) | 402 if (!pSrcDict) |
| 409 return FALSE; | 403 return FALSE; |
| 410 | 404 |
| 411 CPDF_Dictionary* pDstDict = pDstDoc->GetRoot(); | 405 CPDF_Dictionary* pDstDict = pDstDoc->GetRoot(); |
| 412 if (!pDstDict) | 406 if (!pDstDict) |
| 413 return FALSE; | 407 return FALSE; |
| 414 | 408 |
| 415 pDstDict->SetAt(FX_BSTRC("ViewerPreferences"), pSrcDict->Clone(TRUE)); | 409 pDstDict->SetAt(FX_BSTRC("ViewerPreferences"), pSrcDict->Clone(TRUE)); |
| 416 return TRUE; | 410 return TRUE; |
| 417 } | 411 } |
| OLD | NEW |