| OLD | NEW |
| 1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 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 "core/fpdfapi/fpdf_parser/include/cpdf_indirect_object_holder.h" | 7 #include "core/fpdfapi/fpdf_parser/include/cpdf_indirect_object_holder.h" |
| 8 | 8 |
| 9 #include "core/fpdfapi/fpdf_parser/include/cpdf_object.h" | 9 #include "core/fpdfapi/fpdf_parser/include/cpdf_object.h" |
| 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_parser.h" | 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_parser.h" |
| 11 | 11 |
| 12 CPDF_IndirectObjectHolder::CPDF_IndirectObjectHolder(CPDF_Parser* pParser) | 12 CPDF_IndirectObjectHolder::CPDF_IndirectObjectHolder() : m_LastObjNum(0) {} |
| 13 : m_pParser(pParser), m_LastObjNum(0) { | |
| 14 if (pParser) | |
| 15 m_LastObjNum = m_pParser->GetLastObjNum(); | |
| 16 } | |
| 17 | 13 |
| 18 CPDF_IndirectObjectHolder::~CPDF_IndirectObjectHolder() { | 14 CPDF_IndirectObjectHolder::~CPDF_IndirectObjectHolder() { |
| 19 for (const auto& pair : m_IndirectObjs) | 15 for (const auto& pair : m_IndirectObjs) |
| 20 pair.second->Destroy(); | 16 pair.second->Destroy(); |
| 21 } | 17 } |
| 22 | 18 |
| 23 CPDF_Object* CPDF_IndirectObjectHolder::GetIndirectObject(uint32_t objnum) { | 19 CPDF_Object* CPDF_IndirectObjectHolder::GetIndirectObject(uint32_t objnum) { |
| 24 if (objnum == 0) | 20 if (objnum == 0) |
| 25 return nullptr; | 21 return nullptr; |
| 26 | 22 |
| 27 auto it = m_IndirectObjs.find(objnum); | 23 auto it = m_IndirectObjs.find(objnum); |
| 28 if (it != m_IndirectObjs.end()) | 24 if (it == m_IndirectObjs.end() || |
| 29 return it->second->GetObjNum() != CPDF_Object::kInvalidObjNum ? it->second | 25 it->second->GetObjNum() == CPDF_Object::kInvalidObjNum) |
| 30 : nullptr; | |
| 31 | |
| 32 if (!m_pParser) | |
| 33 return nullptr; | 26 return nullptr; |
| 34 | 27 return it->second; |
| 35 CPDF_Object* pObj = m_pParser->ParseIndirectObject(this, objnum); | |
| 36 if (!pObj) | |
| 37 return nullptr; | |
| 38 | |
| 39 pObj->m_ObjNum = objnum; | |
| 40 m_LastObjNum = std::max(m_LastObjNum, objnum); | |
| 41 if (m_IndirectObjs[objnum]) | |
| 42 m_IndirectObjs[objnum]->Destroy(); | |
| 43 | |
| 44 m_IndirectObjs[objnum] = pObj; | |
| 45 return pObj; | |
| 46 } | 28 } |
| 47 | 29 |
| 48 uint32_t CPDF_IndirectObjectHolder::AddIndirectObject(CPDF_Object* pObj) { | 30 uint32_t CPDF_IndirectObjectHolder::AddIndirectObject(CPDF_Object* pObj) { |
| 49 if (pObj->m_ObjNum) | 31 if (pObj->m_ObjNum) |
| 50 return pObj->m_ObjNum; | 32 return pObj->m_ObjNum; |
| 51 | 33 |
| 52 m_LastObjNum++; | 34 m_LastObjNum++; |
| 53 m_IndirectObjs[m_LastObjNum] = pObj; | 35 m_IndirectObjs[m_LastObjNum] = pObj; |
| 54 pObj->m_ObjNum = m_LastObjNum; | 36 pObj->m_ObjNum = m_LastObjNum; |
| 55 return m_LastObjNum; | 37 return m_LastObjNum; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 76 pObj->Destroy(); | 58 pObj->Destroy(); |
| 77 return false; | 59 return false; |
| 78 } | 60 } |
| 79 it->second->Destroy(); | 61 it->second->Destroy(); |
| 80 } | 62 } |
| 81 pObj->m_ObjNum = objnum; | 63 pObj->m_ObjNum = objnum; |
| 82 m_IndirectObjs[objnum] = pObj; | 64 m_IndirectObjs[objnum] = pObj; |
| 83 m_LastObjNum = std::max(m_LastObjNum, objnum); | 65 m_LastObjNum = std::max(m_LastObjNum, objnum); |
| 84 return true; | 66 return true; |
| 85 } | 67 } |
| OLD | NEW |