| 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 "../include/fsdk_define.h" | 8 #include "../include/fsdk_define.h" |
| 9 #include "../include/fpdfxfa/fpdfxfa_doc.h" | 9 #include "../include/fpdfxfa/fpdfxfa_doc.h" |
| 10 | 10 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 CFX_ByteString producerstr; | 52 CFX_ByteString producerstr; |
| 53 producerstr.Format("PDFium"); | 53 producerstr.Format("PDFium"); |
| 54 DInfoDict->SetAt("Producer", new CPDF_String(producerstr)); | 54 DInfoDict->SetAt("Producer", new CPDF_String(producerstr)); |
| 55 | 55 |
| 56 // Set type//////////////////////////////////////////////////////////////// | 56 // Set type//////////////////////////////////////////////////////////////// |
| 57 CFX_ByteString cbRootType = pNewRoot->GetString("Type", ""); | 57 CFX_ByteString cbRootType = pNewRoot->GetString("Type", ""); |
| 58 if (cbRootType.Equal("")) { | 58 if (cbRootType.Equal("")) { |
| 59 pNewRoot->SetAt("Type", new CPDF_Name("Catalog")); | 59 pNewRoot->SetAt("Type", new CPDF_Name("Catalog")); |
| 60 } | 60 } |
| 61 | 61 |
| 62 CPDF_Dictionary* pNewPages = | 62 CPDF_Dictionary* pNewPages = ToDictionary( |
| 63 (CPDF_Dictionary*)(pNewRoot->GetElement("Pages") | 63 pNewRoot->GetElement("Pages") ? pNewRoot->GetElement("Pages")->GetDirect() |
| 64 ? pNewRoot->GetElement("Pages")->GetDirect() | 64 : nullptr); |
| 65 : NULL); | 65 |
| 66 if (!pNewPages) { | 66 if (!pNewPages) { |
| 67 pNewPages = new CPDF_Dictionary; | 67 pNewPages = new CPDF_Dictionary; |
| 68 FX_DWORD NewPagesON = pDestPDFDoc->AddIndirectObject(pNewPages); | 68 FX_DWORD NewPagesON = pDestPDFDoc->AddIndirectObject(pNewPages); |
| 69 pNewRoot->SetAt("Pages", new CPDF_Reference(pDestPDFDoc, NewPagesON)); | 69 pNewRoot->SetAt("Pages", new CPDF_Reference(pDestPDFDoc, NewPagesON)); |
| 70 } | 70 } |
| 71 | 71 |
| 72 CFX_ByteString cbPageType = pNewPages->GetString("Type", ""); | 72 CFX_ByteString cbPageType = pNewPages->GetString("Type", ""); |
| 73 if (cbPageType.Equal("")) { | 73 if (cbPageType.Equal("")) { |
| 74 pNewPages->SetAt("Type", new CPDF_Name("Pages")); | 74 pNewPages->SetAt("Type", new CPDF_Name("Pages")); |
| 75 } | 75 } |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 CFX_ByteString nSrctag) { | 184 CFX_ByteString nSrctag) { |
| 185 if (!pDict || !pDict->KeyExist("Type") || nSrctag.IsEmpty()) | 185 if (!pDict || !pDict->KeyExist("Type") || nSrctag.IsEmpty()) |
| 186 return NULL; | 186 return NULL; |
| 187 | 187 |
| 188 CPDF_Object* pType = pDict->GetElement("Type")->GetDirect(); | 188 CPDF_Object* pType = pDict->GetElement("Type")->GetDirect(); |
| 189 if (!pType || pType->GetType() != PDFOBJ_NAME) | 189 if (!pType || pType->GetType() != PDFOBJ_NAME) |
| 190 return NULL; | 190 return NULL; |
| 191 | 191 |
| 192 if (pType->GetString().Compare("Page")) | 192 if (pType->GetString().Compare("Page")) |
| 193 return NULL; | 193 return NULL; |
| 194 | |
| 195 if (!pDict->KeyExist("Parent")) | 194 if (!pDict->KeyExist("Parent")) |
| 196 return NULL; | 195 return NULL; |
| 197 CPDF_Object* pParent = pDict->GetElement("Parent")->GetDirect(); | |
| 198 if (!pParent || pParent->GetType() != PDFOBJ_DICTIONARY) | |
| 199 return NULL; | |
| 200 | 196 |
| 201 CPDF_Dictionary* pp = (CPDF_Dictionary*)pParent; | 197 CPDF_Dictionary* pp = ToDictionary(pDict->GetElement("Parent")->GetDirect()); |
| 198 if (!pp) |
| 199 return nullptr; |
| 202 | 200 |
| 203 if (pDict->KeyExist((const char*)nSrctag)) | 201 if (pDict->KeyExist((const char*)nSrctag)) |
| 204 return pDict->GetElement((const char*)nSrctag); | 202 return pDict->GetElement((const char*)nSrctag); |
| 203 |
| 205 while (pp) { | 204 while (pp) { |
| 206 if (pp->KeyExist((const char*)nSrctag)) | 205 if (pp->KeyExist((const char*)nSrctag)) |
| 207 return pp->GetElement((const char*)nSrctag); | 206 return pp->GetElement((const char*)nSrctag); |
| 208 if (pp->KeyExist("Parent")) { | 207 if (!pp->KeyExist("Parent")) { |
| 209 pp = (CPDF_Dictionary*)pp->GetElement("Parent")->GetDirect(); | |
| 210 if (pp->GetType() == PDFOBJ_NULL) | |
| 211 break; | |
| 212 } else | |
| 213 break; | 208 break; |
| 209 } |
| 210 pp = ToDictionary(pp->GetElement("Parent")->GetDirect()); |
| 214 } | 211 } |
| 215 | 212 return nullptr; |
| 216 return NULL; | |
| 217 } | 213 } |
| 218 | 214 |
| 219 FX_BOOL CPDF_PageOrganizer::UpdateReference(CPDF_Object* pObj, | 215 FX_BOOL CPDF_PageOrganizer::UpdateReference(CPDF_Object* pObj, |
| 220 CPDF_Document* pDoc, | 216 CPDF_Document* pDoc, |
| 221 CFX_MapPtrToPtr* pMapPtrToPtr) { | 217 CFX_MapPtrToPtr* pMapPtrToPtr) { |
| 222 switch (pObj->GetType()) { | 218 switch (pObj->GetType()) { |
| 223 case PDFOBJ_REFERENCE: { | 219 case PDFOBJ_REFERENCE: { |
| 224 CPDF_Reference* pReference = (CPDF_Reference*)pObj; | 220 CPDF_Reference* pReference = (CPDF_Reference*)pObj; |
| 225 int newobjnum = GetNewObjId(pDoc, pMapPtrToPtr, pReference); | 221 int newobjnum = GetNewObjId(pDoc, pMapPtrToPtr, pReference); |
| 226 if (newobjnum == 0) | 222 if (newobjnum == 0) |
| 227 return FALSE; | 223 return FALSE; |
| 228 pReference->SetRef(pDoc, newobjnum); //, 0); | 224 pReference->SetRef(pDoc, newobjnum); //, 0); |
| 229 break; | 225 break; |
| 230 } | 226 } |
| 231 case PDFOBJ_DICTIONARY: { | 227 case PDFOBJ_DICTIONARY: { |
| 232 CPDF_Dictionary* pDict = (CPDF_Dictionary*)pObj; | 228 CPDF_Dictionary* pDict = pObj->AsDictionary(); |
| 233 | 229 |
| 234 FX_POSITION pos = pDict->GetStartPos(); | 230 FX_POSITION pos = pDict->GetStartPos(); |
| 235 while (pos) { | 231 while (pos) { |
| 236 CFX_ByteString key(""); | 232 CFX_ByteString key(""); |
| 237 CPDF_Object* pNextObj = pDict->GetNextElement(pos, key); | 233 CPDF_Object* pNextObj = pDict->GetNextElement(pos, key); |
| 238 if (!FXSYS_strcmp(key, "Parent") || !FXSYS_strcmp(key, "Prev") || | 234 if (!FXSYS_strcmp(key, "Parent") || !FXSYS_strcmp(key, "Prev") || |
| 239 !FXSYS_strcmp(key, "First")) | 235 !FXSYS_strcmp(key, "First")) |
| 240 continue; | 236 continue; |
| 241 if (pNextObj) { | 237 if (pNextObj) { |
| 242 if (!UpdateReference(pNextObj, pDoc, pMapPtrToPtr)) | 238 if (!UpdateReference(pNextObj, pDoc, pMapPtrToPtr)) |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 CPDF_Object* pDirect = pRef->GetDirect(); | 289 CPDF_Object* pDirect = pRef->GetDirect(); |
| 294 if (!pDirect) { | 290 if (!pDirect) { |
| 295 return 0; | 291 return 0; |
| 296 } | 292 } |
| 297 | 293 |
| 298 CPDF_Object* pClone = pDirect->Clone(); | 294 CPDF_Object* pClone = pDirect->Clone(); |
| 299 if (!pClone) { | 295 if (!pClone) { |
| 300 return 0; | 296 return 0; |
| 301 } | 297 } |
| 302 | 298 |
| 303 if (pClone->GetType() == PDFOBJ_DICTIONARY) { | 299 if (CPDF_Dictionary* pDictClone = pClone->AsDictionary()) { |
| 304 CPDF_Dictionary* pDictClone = (CPDF_Dictionary*)pClone; | |
| 305 if (pDictClone->KeyExist("Type")) { | 300 if (pDictClone->KeyExist("Type")) { |
| 306 CFX_ByteString strType = pDictClone->GetString("Type"); | 301 CFX_ByteString strType = pDictClone->GetString("Type"); |
| 307 if (!FXSYS_stricmp(strType, "Pages")) { | 302 if (!FXSYS_stricmp(strType, "Pages")) { |
| 308 pDictClone->Release(); | 303 pDictClone->Release(); |
| 309 return 4; | 304 return 4; |
| 310 } else if (!FXSYS_stricmp(strType, "Page")) { | 305 } else if (!FXSYS_stricmp(strType, "Page")) { |
| 311 pDictClone->Release(); | 306 pDictClone->Release(); |
| 312 return 0; | 307 return 0; |
| 313 } | 308 } |
| 314 } | 309 } |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 if (!pSrcDict) | 413 if (!pSrcDict) |
| 419 return FALSE; | 414 return FALSE; |
| 420 | 415 |
| 421 CPDF_Dictionary* pDstDict = pDstDoc->GetRoot(); | 416 CPDF_Dictionary* pDstDict = pDstDoc->GetRoot(); |
| 422 if (!pDstDict) | 417 if (!pDstDict) |
| 423 return FALSE; | 418 return FALSE; |
| 424 | 419 |
| 425 pDstDict->SetAt(FX_BSTRC("ViewerPreferences"), pSrcDict->Clone(TRUE)); | 420 pDstDict->SetAt(FX_BSTRC("ViewerPreferences"), pSrcDict->Clone(TRUE)); |
| 426 return TRUE; | 421 return TRUE; |
| 427 } | 422 } |
| OLD | NEW |