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