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/parser/cpdf_indirect_object_holder.h" | 7 #include "core/fpdfapi/parser/cpdf_indirect_object_holder.h" |
8 | 8 |
9 #include "core/fpdfapi/parser/cpdf_array.h" | |
10 #include "core/fpdfapi/parser/cpdf_dictionary.h" | |
9 #include "core/fpdfapi/parser/cpdf_object.h" | 11 #include "core/fpdfapi/parser/cpdf_object.h" |
10 #include "core/fpdfapi/parser/cpdf_parser.h" | 12 #include "core/fpdfapi/parser/cpdf_parser.h" |
13 #include "core/fpdfapi/parser/cpdf_stream.h" | |
11 | 14 |
12 CPDF_IndirectObjectHolder::CPDF_IndirectObjectHolder() : m_LastObjNum(0) {} | 15 CPDF_IndirectObjectHolder::CPDF_IndirectObjectHolder() : m_LastObjNum(0) {} |
13 | 16 |
14 CPDF_IndirectObjectHolder::~CPDF_IndirectObjectHolder() {} | 17 CPDF_IndirectObjectHolder::~CPDF_IndirectObjectHolder() {} |
15 | 18 |
16 CPDF_Object* CPDF_IndirectObjectHolder::GetIndirectObject( | 19 CPDF_Object* CPDF_IndirectObjectHolder::GetIndirectObject( |
17 uint32_t objnum) const { | 20 uint32_t objnum) const { |
18 auto it = m_IndirectObjs.find(objnum); | 21 auto it = m_IndirectObjs.find(objnum); |
19 return it != m_IndirectObjs.end() ? it->second.get() : nullptr; | 22 return it != m_IndirectObjs.end() ? it->second.get() : nullptr; |
20 } | 23 } |
(...skipping 14 matching lines...) Expand all Loading... | |
35 pObj->m_ObjNum = objnum; | 38 pObj->m_ObjNum = objnum; |
36 m_LastObjNum = std::max(m_LastObjNum, objnum); | 39 m_LastObjNum = std::max(m_LastObjNum, objnum); |
37 m_IndirectObjs[objnum].reset(pObj); | 40 m_IndirectObjs[objnum].reset(pObj); |
38 return pObj; | 41 return pObj; |
39 } | 42 } |
40 | 43 |
41 CPDF_Object* CPDF_IndirectObjectHolder::ParseIndirectObject(uint32_t objnum) { | 44 CPDF_Object* CPDF_IndirectObjectHolder::ParseIndirectObject(uint32_t objnum) { |
42 return nullptr; | 45 return nullptr; |
43 } | 46 } |
44 | 47 |
45 uint32_t CPDF_IndirectObjectHolder::AddIndirectObject(CPDF_Object* pObj) { | 48 CPDF_Object* CPDF_IndirectObjectHolder::AddIndirectObject(UniqueObject pObj) { |
46 if (pObj->m_ObjNum) | 49 if (pObj->m_ObjNum) |
47 return pObj->m_ObjNum; | 50 return pObj.release(); // TODO(tsepez): shouldn't happen, stop this leak. |
48 | 51 |
49 m_LastObjNum++; | 52 pObj->m_ObjNum = ++m_LastObjNum; |
50 m_IndirectObjs[m_LastObjNum].release(); // TODO(tsepez): stop this leak. | 53 m_IndirectObjs[m_LastObjNum].release(); // TODO(tsepez): stop this leak. |
51 m_IndirectObjs[m_LastObjNum].reset(pObj); | 54 m_IndirectObjs[m_LastObjNum].reset(pObj.release()); // Changes deleters. |
52 pObj->m_ObjNum = m_LastObjNum; | 55 return m_IndirectObjs[m_LastObjNum].get(); |
53 return m_LastObjNum; | 56 } |
57 | |
58 CPDF_Array* CPDF_IndirectObjectHolder::AddIndirectArray() { | |
59 return ToArray(AddIndirectObject(UniqueObject(new CPDF_Array()))); | |
60 } | |
61 | |
62 CPDF_Dictionary* CPDF_IndirectObjectHolder::AddIndirectDictionary() { | |
63 return ToDictionary(AddIndirectObject(UniqueObject(new CPDF_Dictionary()))); | |
64 } | |
65 | |
66 CPDF_Dictionary* CPDF_IndirectObjectHolder::AddIndirectDictionary( | |
67 const CFX_WeakPtr<CFX_ByteStringPool>& pPool) { | |
68 return ToDictionary( | |
69 AddIndirectObject(UniqueObject(new CPDF_Dictionary(pPool)))); | |
70 } | |
71 | |
72 CPDF_Stream* CPDF_IndirectObjectHolder::AddIndirectStream() { | |
73 return ToStream(AddIndirectObject(UniqueObject(new CPDF_Stream()))); | |
74 } | |
75 | |
76 CPDF_Stream* CPDF_IndirectObjectHolder::AddIndirectStream( | |
77 uint8_t* pData, | |
Lei Zhang
2016/10/14 23:18:04
Parameters are not used?
Tom Sepez
2016/10/14 23:42:29
Argh. I have some template foo coming to avoid th
| |
78 uint32_t size, | |
79 CPDF_Dictionary* pDict) { | |
80 return ToStream(AddIndirectObject(UniqueObject(new CPDF_Stream()))); | |
54 } | 81 } |
55 | 82 |
56 bool CPDF_IndirectObjectHolder::ReplaceIndirectObjectIfHigherGeneration( | 83 bool CPDF_IndirectObjectHolder::ReplaceIndirectObjectIfHigherGeneration( |
57 uint32_t objnum, | 84 uint32_t objnum, |
58 CPDF_Object* pObj) { | 85 UniqueObject pObj) { |
59 if (!objnum || !pObj) | 86 if (!objnum || !pObj) |
60 return false; | 87 return false; |
61 | 88 |
62 CPDF_Object* pOldObj = GetIndirectObject(objnum); | 89 CPDF_Object* pOldObj = GetIndirectObject(objnum); |
63 if (pOldObj && pObj->GetGenNum() <= pOldObj->GetGenNum()) { | 90 if (pOldObj && pObj->GetGenNum() <= pOldObj->GetGenNum()) |
64 delete pObj; | |
65 return false; | 91 return false; |
66 } | 92 |
67 pObj->m_ObjNum = objnum; | 93 pObj->m_ObjNum = objnum; |
68 m_IndirectObjs[objnum].reset(pObj); | 94 m_IndirectObjs[objnum].reset(pObj.release()); // Changes deleters. |
69 m_LastObjNum = std::max(m_LastObjNum, objnum); | 95 m_LastObjNum = std::max(m_LastObjNum, objnum); |
70 return true; | 96 return true; |
71 } | 97 } |
72 | 98 |
73 void CPDF_IndirectObjectHolder::ReleaseIndirectObject(uint32_t objnum) { | 99 void CPDF_IndirectObjectHolder::DeleteIndirectObject(uint32_t objnum) { |
74 CPDF_Object* pObj = GetIndirectObject(objnum); | 100 CPDF_Object* pObj = GetIndirectObject(objnum); |
75 if (!pObj || pObj->GetObjNum() == CPDF_Object::kInvalidObjNum) | 101 if (!pObj || pObj->GetObjNum() == CPDF_Object::kInvalidObjNum) |
76 return; | 102 return; |
77 | 103 |
78 m_IndirectObjs.erase(objnum); | 104 m_IndirectObjs.erase(objnum); |
79 } | 105 } |
OLD | NEW |