| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 PDFium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | |
| 6 | |
| 7 #include "core/fpdfapi/fpdf_parser/cpdf_indirect_object_holder.h" | |
| 8 | |
| 9 #include "core/fpdfapi/fpdf_parser/cpdf_object.h" | |
| 10 #include "core/fpdfapi/fpdf_parser/cpdf_parser.h" | |
| 11 | |
| 12 CPDF_IndirectObjectHolder::CPDF_IndirectObjectHolder() : m_LastObjNum(0) {} | |
| 13 | |
| 14 CPDF_IndirectObjectHolder::~CPDF_IndirectObjectHolder() {} | |
| 15 | |
| 16 CPDF_Object* CPDF_IndirectObjectHolder::GetIndirectObject( | |
| 17 uint32_t objnum) const { | |
| 18 auto it = m_IndirectObjs.find(objnum); | |
| 19 return it != m_IndirectObjs.end() ? it->second.get() : nullptr; | |
| 20 } | |
| 21 | |
| 22 CPDF_Object* CPDF_IndirectObjectHolder::GetOrParseIndirectObject( | |
| 23 uint32_t objnum) { | |
| 24 if (objnum == 0) | |
| 25 return nullptr; | |
| 26 | |
| 27 CPDF_Object* pObj = GetIndirectObject(objnum); | |
| 28 if (pObj) | |
| 29 return pObj->GetObjNum() != CPDF_Object::kInvalidObjNum ? pObj : nullptr; | |
| 30 | |
| 31 pObj = ParseIndirectObject(objnum); | |
| 32 if (!pObj) | |
| 33 return nullptr; | |
| 34 | |
| 35 pObj->m_ObjNum = objnum; | |
| 36 m_LastObjNum = std::max(m_LastObjNum, objnum); | |
| 37 m_IndirectObjs[objnum].reset(pObj); | |
| 38 return pObj; | |
| 39 } | |
| 40 | |
| 41 CPDF_Object* CPDF_IndirectObjectHolder::ParseIndirectObject(uint32_t objnum) { | |
| 42 return nullptr; | |
| 43 } | |
| 44 | |
| 45 uint32_t CPDF_IndirectObjectHolder::AddIndirectObject(CPDF_Object* pObj) { | |
| 46 if (pObj->m_ObjNum) | |
| 47 return pObj->m_ObjNum; | |
| 48 | |
| 49 m_LastObjNum++; | |
| 50 m_IndirectObjs[m_LastObjNum].release(); // TODO(tsepez): stop this leak. | |
| 51 m_IndirectObjs[m_LastObjNum].reset(pObj); | |
| 52 pObj->m_ObjNum = m_LastObjNum; | |
| 53 return m_LastObjNum; | |
| 54 } | |
| 55 | |
| 56 bool CPDF_IndirectObjectHolder::ReplaceIndirectObjectIfHigherGeneration( | |
| 57 uint32_t objnum, | |
| 58 CPDF_Object* pObj) { | |
| 59 if (!objnum || !pObj) | |
| 60 return false; | |
| 61 | |
| 62 CPDF_Object* pOldObj = GetIndirectObject(objnum); | |
| 63 if (pOldObj && pObj->GetGenNum() <= pOldObj->GetGenNum()) { | |
| 64 delete pObj; | |
| 65 return false; | |
| 66 } | |
| 67 pObj->m_ObjNum = objnum; | |
| 68 m_IndirectObjs[objnum].reset(pObj); | |
| 69 m_LastObjNum = std::max(m_LastObjNum, objnum); | |
| 70 return true; | |
| 71 } | |
| 72 | |
| 73 void CPDF_IndirectObjectHolder::ReleaseIndirectObject(uint32_t objnum) { | |
| 74 CPDF_Object* pObj = GetIndirectObject(objnum); | |
| 75 if (!pObj || pObj->GetObjNum() == CPDF_Object::kInvalidObjNum) | |
| 76 return; | |
| 77 | |
| 78 m_IndirectObjs.erase(objnum); | |
| 79 } | |
| OLD | NEW |