Chromium Code Reviews| 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 <map> | 9 #include <map> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 102 if (!pSrcPageDict || !pCurPageDict) | 102 if (!pSrcPageDict || !pCurPageDict) |
| 103 return false; | 103 return false; |
| 104 | 104 |
| 105 // Clone the page dictionary | 105 // Clone the page dictionary |
| 106 for (const auto& it : *pSrcPageDict) { | 106 for (const auto& it : *pSrcPageDict) { |
| 107 const CFX_ByteString& cbSrcKeyStr = it.first; | 107 const CFX_ByteString& cbSrcKeyStr = it.first; |
| 108 CPDF_Object* pObj = it.second; | 108 CPDF_Object* pObj = it.second; |
| 109 if (cbSrcKeyStr.Compare(("Type")) && cbSrcKeyStr.Compare(("Parent"))) { | 109 if (cbSrcKeyStr.Compare(("Type")) && cbSrcKeyStr.Compare(("Parent"))) { |
| 110 if (pCurPageDict->KeyExist(cbSrcKeyStr)) | 110 if (pCurPageDict->KeyExist(cbSrcKeyStr)) |
| 111 pCurPageDict->RemoveFor(cbSrcKeyStr); | 111 pCurPageDict->RemoveFor(cbSrcKeyStr); |
| 112 pCurPageDict->SetFor(cbSrcKeyStr, pObj->Clone()); | 112 pCurPageDict->SetFor(cbSrcKeyStr, pObj->Clone().release()); |
| 113 } | 113 } |
| 114 } | 114 } |
| 115 | 115 |
| 116 // inheritable item | 116 // inheritable item |
| 117 CPDF_Object* pInheritable = nullptr; | 117 CPDF_Object* pInheritable = nullptr; |
| 118 // 1 MediaBox //required | 118 // 1 MediaBox //required |
| 119 if (!pCurPageDict->KeyExist("MediaBox")) { | 119 if (!pCurPageDict->KeyExist("MediaBox")) { |
| 120 pInheritable = PageDictGetInheritableTag(pSrcPageDict, "MediaBox"); | 120 pInheritable = PageDictGetInheritableTag(pSrcPageDict, "MediaBox"); |
| 121 if (!pInheritable) { | 121 if (!pInheritable) { |
| 122 // Search the "CropBox" from source page dictionary, | 122 // Search the "CropBox" from source page dictionary, |
| 123 // if not exists,we take the letter size. | 123 // if not exists,we take the letter size. |
| 124 pInheritable = PageDictGetInheritableTag(pSrcPageDict, "CropBox"); | 124 pInheritable = PageDictGetInheritableTag(pSrcPageDict, "CropBox"); |
| 125 if (pInheritable) { | 125 if (pInheritable) { |
| 126 pCurPageDict->SetFor("MediaBox", pInheritable->Clone()); | 126 pCurPageDict->SetFor("MediaBox", pInheritable->Clone().release()); |
| 127 } else { | 127 } else { |
| 128 // Make the default size to be letter size (8.5'x11') | 128 // Make the default size to be letter size (8.5'x11') |
| 129 CPDF_Array* pArray = new CPDF_Array; | 129 CPDF_Array* pArray = new CPDF_Array; |
| 130 pArray->AddNumber(0); | 130 pArray->AddNumber(0); |
| 131 pArray->AddNumber(0); | 131 pArray->AddNumber(0); |
| 132 pArray->AddNumber(612); | 132 pArray->AddNumber(612); |
| 133 pArray->AddNumber(792); | 133 pArray->AddNumber(792); |
| 134 pCurPageDict->SetFor("MediaBox", pArray); | 134 pCurPageDict->SetFor("MediaBox", pArray); |
| 135 } | 135 } |
| 136 } else { | 136 } else { |
| 137 pCurPageDict->SetFor("MediaBox", pInheritable->Clone()); | 137 pCurPageDict->SetFor("MediaBox", pInheritable->Clone().release()); |
| 138 } | 138 } |
| 139 } | 139 } |
| 140 // 2 Resources //required | 140 // 2 Resources //required |
| 141 if (!pCurPageDict->KeyExist("Resources")) { | 141 if (!pCurPageDict->KeyExist("Resources")) { |
| 142 pInheritable = PageDictGetInheritableTag(pSrcPageDict, "Resources"); | 142 pInheritable = PageDictGetInheritableTag(pSrcPageDict, "Resources"); |
| 143 if (!pInheritable) | 143 if (!pInheritable) |
| 144 return false; | 144 return false; |
| 145 pCurPageDict->SetFor("Resources", pInheritable->Clone()); | 145 pCurPageDict->SetFor("Resources", pInheritable->Clone().release()); |
| 146 } | 146 } |
| 147 // 3 CropBox //Optional | 147 // 3 CropBox //Optional |
| 148 if (!pCurPageDict->KeyExist("CropBox")) { | 148 if (!pCurPageDict->KeyExist("CropBox")) { |
| 149 pInheritable = PageDictGetInheritableTag(pSrcPageDict, "CropBox"); | 149 pInheritable = PageDictGetInheritableTag(pSrcPageDict, "CropBox"); |
| 150 if (pInheritable) | 150 if (pInheritable) |
| 151 pCurPageDict->SetFor("CropBox", pInheritable->Clone()); | 151 pCurPageDict->SetFor("CropBox", pInheritable->Clone().release()); |
| 152 } | 152 } |
| 153 // 4 Rotate //Optional | 153 // 4 Rotate //Optional |
| 154 if (!pCurPageDict->KeyExist("Rotate")) { | 154 if (!pCurPageDict->KeyExist("Rotate")) { |
| 155 pInheritable = PageDictGetInheritableTag(pSrcPageDict, "Rotate"); | 155 pInheritable = PageDictGetInheritableTag(pSrcPageDict, "Rotate"); |
| 156 if (pInheritable) | 156 if (pInheritable) |
| 157 pCurPageDict->SetFor("Rotate", pInheritable->Clone()); | 157 pCurPageDict->SetFor("Rotate", pInheritable->Clone().release()); |
| 158 } | 158 } |
| 159 | 159 |
| 160 // Update the reference | 160 // Update the reference |
| 161 uint32_t dwOldPageObj = pSrcPageDict->GetObjNum(); | 161 uint32_t dwOldPageObj = pSrcPageDict->GetObjNum(); |
| 162 uint32_t dwNewPageObj = pCurPageDict->GetObjNum(); | 162 uint32_t dwNewPageObj = pCurPageDict->GetObjNum(); |
| 163 | |
| 164 (*pObjNumberMap)[dwOldPageObj] = dwNewPageObj; | 163 (*pObjNumberMap)[dwOldPageObj] = dwNewPageObj; |
| 165 | |
| 166 UpdateReference(pCurPageDict, pDestPDFDoc, pObjNumberMap.get()); | 164 UpdateReference(pCurPageDict, pDestPDFDoc, pObjNumberMap.get()); |
| 167 ++curpage; | 165 ++curpage; |
| 168 } | 166 } |
| 169 | 167 |
| 170 return true; | 168 return true; |
| 171 } | 169 } |
| 172 | 170 |
| 173 CPDF_Object* CPDF_PageOrganizer::PageDictGetInheritableTag( | 171 CPDF_Object* CPDF_PageOrganizer::PageDictGetInheritableTag( |
| 174 CPDF_Dictionary* pDict, | 172 CPDF_Dictionary* pDict, |
| 175 const CFX_ByteString& bsSrcTag) { | 173 const CFX_ByteString& bsSrcTag) { |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 270 const auto it = pObjNumberMap->find(dwObjnum); | 268 const auto it = pObjNumberMap->find(dwObjnum); |
| 271 if (it != pObjNumberMap->end()) | 269 if (it != pObjNumberMap->end()) |
| 272 dwNewObjNum = it->second; | 270 dwNewObjNum = it->second; |
| 273 if (dwNewObjNum) | 271 if (dwNewObjNum) |
| 274 return dwNewObjNum; | 272 return dwNewObjNum; |
| 275 | 273 |
| 276 CPDF_Object* pDirect = pRef->GetDirect(); | 274 CPDF_Object* pDirect = pRef->GetDirect(); |
| 277 if (!pDirect) | 275 if (!pDirect) |
| 278 return 0; | 276 return 0; |
| 279 | 277 |
| 280 CPDF_Object* pClone = pDirect->Clone(); | 278 std::unique_ptr<CPDF_Object> pClone = pDirect->Clone(); |
| 281 if (!pClone) | 279 if (!pClone) |
|
Lei Zhang
2016/11/08 18:55:43
BTW, there's a few places where we check for cloni
Tom Sepez
2016/11/09 18:20:46
There's a few places where we return nullptr if we
| |
| 282 return 0; | 280 return 0; |
| 283 | 281 |
| 284 if (CPDF_Dictionary* pDictClone = pClone->AsDictionary()) { | 282 if (CPDF_Dictionary* pDictClone = pClone->AsDictionary()) { |
| 285 if (pDictClone->KeyExist("Type")) { | 283 if (pDictClone->KeyExist("Type")) { |
| 286 CFX_ByteString strType = pDictClone->GetStringFor("Type"); | 284 CFX_ByteString strType = pDictClone->GetStringFor("Type"); |
| 287 if (!FXSYS_stricmp(strType.c_str(), "Pages")) { | 285 if (!FXSYS_stricmp(strType.c_str(), "Pages")) |
| 288 delete pDictClone; | |
| 289 return 4; | 286 return 4; |
| 290 } | 287 if (!FXSYS_stricmp(strType.c_str(), "Page")) |
| 291 if (!FXSYS_stricmp(strType.c_str(), "Page")) { | |
| 292 delete pDictClone; | |
| 293 return 0; | 288 return 0; |
| 294 } | |
| 295 } | 289 } |
| 296 } | 290 } |
| 297 dwNewObjNum = pDoc->AddIndirectObject(pClone); | 291 dwNewObjNum = pDoc->AddIndirectObject(pClone.get()); |
| 298 (*pObjNumberMap)[dwObjnum] = dwNewObjNum; | 292 (*pObjNumberMap)[dwObjnum] = dwNewObjNum; |
| 299 if (!UpdateReference(pClone, pDoc, pObjNumberMap)) { | 293 if (!UpdateReference(pClone.get(), pDoc, pObjNumberMap)) |
| 300 delete pClone; | |
| 301 return 0; | 294 return 0; |
| 302 } | 295 |
| 296 pClone.release(); // TODO(tsepez): figure out ownership. | |
|
Lei Zhang
2016/11/08 18:55:43
On line 291 , AddIndirectObjet() is suppose to tak
Tom Sepez
2016/11/09 18:20:46
Yup.
| |
| 303 return dwNewObjNum; | 297 return dwNewObjNum; |
| 304 } | 298 } |
| 305 | 299 |
| 306 FPDF_BOOL ParserPageRangeString(CFX_ByteString rangstring, | 300 FPDF_BOOL ParserPageRangeString(CFX_ByteString rangstring, |
| 307 std::vector<uint16_t>* pageArray, | 301 std::vector<uint16_t>* pageArray, |
| 308 int nCount) { | 302 int nCount) { |
| 309 if (rangstring.GetLength() != 0) { | 303 if (rangstring.GetLength() != 0) { |
| 310 rangstring.Remove(' '); | 304 rangstring.Remove(' '); |
| 311 int nLength = rangstring.GetLength(); | 305 int nLength = rangstring.GetLength(); |
| 312 CFX_ByteString cbCompareString("0123456789-,"); | 306 CFX_ByteString cbCompareString("0123456789-,"); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 393 | 387 |
| 394 CPDF_Dictionary* pSrcDict = pSrcDoc->GetRoot(); | 388 CPDF_Dictionary* pSrcDict = pSrcDoc->GetRoot(); |
| 395 pSrcDict = pSrcDict->GetDictFor("ViewerPreferences"); | 389 pSrcDict = pSrcDict->GetDictFor("ViewerPreferences"); |
| 396 if (!pSrcDict) | 390 if (!pSrcDict) |
| 397 return false; | 391 return false; |
| 398 | 392 |
| 399 CPDF_Dictionary* pDstDict = pDstDoc->GetRoot(); | 393 CPDF_Dictionary* pDstDict = pDstDoc->GetRoot(); |
| 400 if (!pDstDict) | 394 if (!pDstDict) |
| 401 return false; | 395 return false; |
| 402 | 396 |
| 403 pDstDict->SetFor("ViewerPreferences", pSrcDict->CloneDirectObject()); | 397 pDstDict->SetFor("ViewerPreferences", |
| 398 pSrcDict->CloneDirectObject().release()); | |
| 404 return true; | 399 return true; |
| 405 } | 400 } |
| OLD | NEW |