Chromium Code Reviews| 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/include/fpdfapi/cpdf_indirect_object_holder.h" | |
| 8 #include "core/include/fpdfapi/cpdf_object.h" | |
| 9 #include "core/include/fpdfapi/cpdf_parser.h" | |
| 10 | |
| 11 CPDF_IndirectObjectHolder::CPDF_IndirectObjectHolder(CPDF_Parser* pParser) | |
| 12 : m_pParser(pParser), m_LastObjNum(0) { | |
| 13 if (pParser) | |
| 14 m_LastObjNum = m_pParser->GetLastObjNum(); | |
| 15 } | |
| 16 | |
| 17 CPDF_IndirectObjectHolder::~CPDF_IndirectObjectHolder() { | |
| 18 for (const auto& pair : m_IndirectObjs) { | |
| 19 pair.second->Destroy(); | |
| 20 } | |
|
dsinclair
2016/03/10 21:23:45
nit: {}s
Tom Sepez
2016/03/10 22:05:19
Done.
| |
| 21 } | |
| 22 | |
| 23 CPDF_Object* CPDF_IndirectObjectHolder::GetIndirectObject(FX_DWORD objnum) { | |
| 24 if (objnum == 0) | |
| 25 return nullptr; | |
| 26 | |
| 27 auto it = m_IndirectObjs.find(objnum); | |
| 28 if (it != m_IndirectObjs.end()) | |
| 29 return it->second->GetObjNum() != -1 ? it->second : nullptr; | |
| 30 | |
| 31 if (!m_pParser) | |
| 32 return nullptr; | |
| 33 | |
| 34 CPDF_Object* pObj = m_pParser->ParseIndirectObject(this, objnum); | |
| 35 if (!pObj) | |
| 36 return nullptr; | |
| 37 | |
| 38 pObj->m_ObjNum = objnum; | |
| 39 m_LastObjNum = std::max(m_LastObjNum, objnum); | |
| 40 if (m_IndirectObjs[objnum]) | |
| 41 m_IndirectObjs[objnum]->Destroy(); | |
| 42 | |
| 43 m_IndirectObjs[objnum] = pObj; | |
| 44 return pObj; | |
| 45 } | |
| 46 | |
| 47 FX_DWORD CPDF_IndirectObjectHolder::AddIndirectObject(CPDF_Object* pObj) { | |
| 48 if (pObj->m_ObjNum) { | |
| 49 return pObj->m_ObjNum; | |
| 50 } | |
|
dsinclair
2016/03/10 21:23:45
nit: {}s
Tom Sepez
2016/03/10 22:05:19
Done.
| |
| 51 m_LastObjNum++; | |
| 52 m_IndirectObjs[m_LastObjNum] = pObj; | |
| 53 pObj->m_ObjNum = m_LastObjNum; | |
| 54 return m_LastObjNum; | |
| 55 } | |
| 56 | |
| 57 void CPDF_IndirectObjectHolder::ReleaseIndirectObject(FX_DWORD objnum) { | |
| 58 auto it = m_IndirectObjs.find(objnum); | |
| 59 if (it == m_IndirectObjs.end() || it->second->GetObjNum() == -1) | |
| 60 return; | |
| 61 it->second->Destroy(); | |
| 62 m_IndirectObjs.erase(it); | |
| 63 } | |
| 64 | |
| 65 FX_BOOL CPDF_IndirectObjectHolder::InsertIndirectObject(FX_DWORD objnum, | |
| 66 CPDF_Object* pObj) { | |
| 67 if (!objnum || !pObj) | |
| 68 return FALSE; | |
| 69 auto it = m_IndirectObjs.find(objnum); | |
| 70 if (it != m_IndirectObjs.end()) { | |
| 71 if (pObj->GetGenNum() <= it->second->GetGenNum()) { | |
| 72 pObj->Destroy(); | |
| 73 return FALSE; | |
| 74 } | |
| 75 it->second->Destroy(); | |
| 76 } | |
| 77 pObj->m_ObjNum = objnum; | |
| 78 m_IndirectObjs[objnum] = pObj; | |
| 79 m_LastObjNum = std::max(m_LastObjNum, objnum); | |
| 80 return TRUE; | |
| 81 } | |
| OLD | NEW |