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(FX_DWORD objnum) { | 23 CPDF_Object* CPDF_IndirectObjectHolder::GetIndirectObject(uint32_t objnum) { |
24 if (objnum == 0) | 24 if (objnum == 0) |
25 return nullptr; | 25 return nullptr; |
26 | 26 |
27 auto it = m_IndirectObjs.find(objnum); | 27 auto it = m_IndirectObjs.find(objnum); |
28 if (it != m_IndirectObjs.end()) | 28 if (it != m_IndirectObjs.end()) |
29 return it->second->GetObjNum() != -1 ? it->second : nullptr; | 29 return it->second->GetObjNum() != -1 ? it->second : nullptr; |
30 | 30 |
31 if (!m_pParser) | 31 if (!m_pParser) |
32 return nullptr; | 32 return nullptr; |
33 | 33 |
34 CPDF_Object* pObj = m_pParser->ParseIndirectObject(this, objnum); | 34 CPDF_Object* pObj = m_pParser->ParseIndirectObject(this, 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 m_IndirectObjs[objnum]->Destroy(); |
42 | 42 |
43 m_IndirectObjs[objnum] = pObj; | 43 m_IndirectObjs[objnum] = pObj; |
44 return pObj; | 44 return pObj; |
45 } | 45 } |
46 | 46 |
47 FX_DWORD CPDF_IndirectObjectHolder::AddIndirectObject(CPDF_Object* pObj) { | 47 uint32_t CPDF_IndirectObjectHolder::AddIndirectObject(CPDF_Object* pObj) { |
48 if (pObj->m_ObjNum) | 48 if (pObj->m_ObjNum) |
49 return pObj->m_ObjNum; | 49 return pObj->m_ObjNum; |
50 | 50 |
51 m_LastObjNum++; | 51 m_LastObjNum++; |
52 m_IndirectObjs[m_LastObjNum] = pObj; | 52 m_IndirectObjs[m_LastObjNum] = pObj; |
53 pObj->m_ObjNum = m_LastObjNum; | 53 pObj->m_ObjNum = m_LastObjNum; |
54 return m_LastObjNum; | 54 return m_LastObjNum; |
55 } | 55 } |
56 | 56 |
57 void CPDF_IndirectObjectHolder::ReleaseIndirectObject(FX_DWORD objnum) { | 57 void CPDF_IndirectObjectHolder::ReleaseIndirectObject(uint32_t objnum) { |
58 auto it = m_IndirectObjs.find(objnum); | 58 auto it = m_IndirectObjs.find(objnum); |
59 if (it == m_IndirectObjs.end() || it->second->GetObjNum() == -1) | 59 if (it == m_IndirectObjs.end() || it->second->GetObjNum() == -1) |
60 return; | 60 return; |
61 it->second->Destroy(); | 61 it->second->Destroy(); |
62 m_IndirectObjs.erase(it); | 62 m_IndirectObjs.erase(it); |
63 } | 63 } |
64 | 64 |
65 FX_BOOL CPDF_IndirectObjectHolder::InsertIndirectObject(FX_DWORD objnum, | 65 FX_BOOL CPDF_IndirectObjectHolder::InsertIndirectObject(uint32_t objnum, |
66 CPDF_Object* pObj) { | 66 CPDF_Object* pObj) { |
67 if (!objnum || !pObj) | 67 if (!objnum || !pObj) |
68 return FALSE; | 68 return FALSE; |
69 auto it = m_IndirectObjs.find(objnum); | 69 auto it = m_IndirectObjs.find(objnum); |
70 if (it != m_IndirectObjs.end()) { | 70 if (it != m_IndirectObjs.end()) { |
71 if (pObj->GetGenNum() <= it->second->GetGenNum()) { | 71 if (pObj->GetGenNum() <= it->second->GetGenNum()) { |
72 pObj->Destroy(); | 72 pObj->Destroy(); |
73 return FALSE; | 73 return FALSE; |
74 } | 74 } |
75 it->second->Destroy(); | 75 it->second->Destroy(); |
76 } | 76 } |
77 pObj->m_ObjNum = objnum; | 77 pObj->m_ObjNum = objnum; |
78 m_IndirectObjs[objnum] = pObj; | 78 m_IndirectObjs[objnum] = pObj; |
79 m_LastObjNum = std::max(m_LastObjNum, objnum); | 79 m_LastObjNum = std::max(m_LastObjNum, objnum); |
80 return TRUE; | 80 return TRUE; |
81 } | 81 } |
OLD | NEW |