| 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(CPDF_Parser* pParser) |
| 13 : m_pParser(pParser), m_LastObjNum(0) { | 13 : m_pParser(pParser), m_LastObjNum(0) { |
| 14 if (pParser) | 14 if (pParser) |
| 15 m_LastObjNum = m_pParser->GetLastObjNum(); | 15 m_LastObjNum = m_pParser->GetLastObjNum(); |
| 16 } | 16 } |
| 17 | 17 |
| 18 CPDF_IndirectObjectHolder::~CPDF_IndirectObjectHolder() { | 18 CPDF_IndirectObjectHolder::~CPDF_IndirectObjectHolder() { |
| 19 for (const auto& pair : m_IndirectObjs) | 19 for (const auto& pair : m_IndirectObjs) |
| 20 pair.second->Destroy(); | 20 pair.second->Destroy(); |
| 21 } | 21 } |
| 22 | 22 |
| 23 CPDF_Object* CPDF_IndirectObjectHolder::GetIndirectObject(uint32_t objnum) { | 23 CPDF_Object* CPDF_IndirectObjectHolder::GetOrParseIndirectObject( |
| 24 uint32_t objnum) { |
| 24 if (objnum == 0) | 25 if (objnum == 0) |
| 25 return nullptr; | 26 return nullptr; |
| 26 | 27 |
| 27 auto it = m_IndirectObjs.find(objnum); | 28 auto it = m_IndirectObjs.find(objnum); |
| 28 if (it != m_IndirectObjs.end()) | 29 if (it != m_IndirectObjs.end()) |
| 29 return it->second->GetObjNum() != CPDF_Object::kInvalidObjNum ? it->second | 30 return it->second->GetObjNum() != CPDF_Object::kInvalidObjNum ? it->second |
| 30 : nullptr; | 31 : nullptr; |
| 31 | 32 |
| 32 if (!m_pParser) | 33 if (!m_pParser) |
| 33 return nullptr; | 34 return nullptr; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 48 uint32_t CPDF_IndirectObjectHolder::AddIndirectObject(CPDF_Object* pObj) { | 49 uint32_t CPDF_IndirectObjectHolder::AddIndirectObject(CPDF_Object* pObj) { |
| 49 if (pObj->m_ObjNum) | 50 if (pObj->m_ObjNum) |
| 50 return pObj->m_ObjNum; | 51 return pObj->m_ObjNum; |
| 51 | 52 |
| 52 m_LastObjNum++; | 53 m_LastObjNum++; |
| 53 m_IndirectObjs[m_LastObjNum] = pObj; | 54 m_IndirectObjs[m_LastObjNum] = pObj; |
| 54 pObj->m_ObjNum = m_LastObjNum; | 55 pObj->m_ObjNum = m_LastObjNum; |
| 55 return m_LastObjNum; | 56 return m_LastObjNum; |
| 56 } | 57 } |
| 57 | 58 |
| 58 void CPDF_IndirectObjectHolder::ReleaseIndirectObject(uint32_t objnum) { | 59 bool CPDF_IndirectObjectHolder::ReplaceIndirectObjectIfHigherGeneration( |
| 59 auto it = m_IndirectObjs.find(objnum); | 60 uint32_t objnum, |
| 60 if (it == m_IndirectObjs.end() || | 61 CPDF_Object* pObj) { |
| 61 it->second->GetObjNum() == CPDF_Object::kInvalidObjNum) { | |
| 62 return; | |
| 63 } | |
| 64 it->second->Destroy(); | |
| 65 m_IndirectObjs.erase(it); | |
| 66 } | |
| 67 | |
| 68 bool CPDF_IndirectObjectHolder::InsertIndirectObject(uint32_t objnum, | |
| 69 CPDF_Object* pObj) { | |
| 70 if (!objnum || !pObj) | 62 if (!objnum || !pObj) |
| 71 return false; | 63 return false; |
| 72 | 64 |
| 73 auto it = m_IndirectObjs.find(objnum); | 65 auto it = m_IndirectObjs.find(objnum); |
| 74 if (it != m_IndirectObjs.end()) { | 66 if (it != m_IndirectObjs.end()) { |
| 75 if (pObj->GetGenNum() <= it->second->GetGenNum()) { | 67 if (pObj->GetGenNum() <= it->second->GetGenNum()) { |
| 76 pObj->Destroy(); | 68 pObj->Destroy(); |
| 77 return false; | 69 return false; |
| 78 } | 70 } |
| 79 it->second->Destroy(); | 71 it->second->Destroy(); |
| 80 } | 72 } |
| 81 pObj->m_ObjNum = objnum; | 73 pObj->m_ObjNum = objnum; |
| 82 m_IndirectObjs[objnum] = pObj; | 74 m_IndirectObjs[objnum] = pObj; |
| 83 m_LastObjNum = std::max(m_LastObjNum, objnum); | 75 m_LastObjNum = std::max(m_LastObjNum, objnum); |
| 84 return true; | 76 return true; |
| 85 } | 77 } |
| 78 |
| 79 void CPDF_IndirectObjectHolder::ReleaseIndirectObject(uint32_t objnum) { |
| 80 auto it = m_IndirectObjs.find(objnum); |
| 81 if (it == m_IndirectObjs.end() || |
| 82 it->second->GetObjNum() == CPDF_Object::kInvalidObjNum) { |
| 83 return; |
| 84 } |
| 85 it->second->Destroy(); |
| 86 m_IndirectObjs.erase(it); |
| 87 } |
| OLD | NEW |