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_dictionary.h" | 7 #include "core/fpdfapi/parser/cpdf_dictionary.h" |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 #include <utility> | 10 #include <utility> |
(...skipping 13 matching lines...) Expand all Loading... |
24 | 24 |
25 CPDF_Dictionary::CPDF_Dictionary(const CFX_WeakPtr<CFX_ByteStringPool>& pPool) | 25 CPDF_Dictionary::CPDF_Dictionary(const CFX_WeakPtr<CFX_ByteStringPool>& pPool) |
26 : m_pPool(pPool) {} | 26 : m_pPool(pPool) {} |
27 | 27 |
28 CPDF_Dictionary::~CPDF_Dictionary() { | 28 CPDF_Dictionary::~CPDF_Dictionary() { |
29 // Mark the object as deleted so that it will not be deleted again | 29 // Mark the object as deleted so that it will not be deleted again |
30 // in case of cyclic references. | 30 // in case of cyclic references. |
31 m_ObjNum = kInvalidObjNum; | 31 m_ObjNum = kInvalidObjNum; |
32 for (const auto& it : m_Map) { | 32 for (const auto& it : m_Map) { |
33 if (it.second && it.second->GetObjNum() != kInvalidObjNum) | 33 if (it.second && it.second->GetObjNum() != kInvalidObjNum) |
34 delete it.second; | 34 it.second->Release(); |
35 } | 35 } |
36 } | 36 } |
37 | 37 |
38 CPDF_Object::Type CPDF_Dictionary::GetType() const { | 38 CPDF_Object::Type CPDF_Dictionary::GetType() const { |
39 return DICTIONARY; | 39 return DICTIONARY; |
40 } | 40 } |
41 | 41 |
42 CPDF_Dictionary* CPDF_Dictionary::GetDict() const { | 42 CPDF_Dictionary* CPDF_Dictionary::GetDict() const { |
43 // The method should be made non-const if we want to not be const. | 43 // The method should be made non-const if we want to not be const. |
44 // See bug #234. | 44 // See bug #234. |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 CHECK(!pObj || pObj->IsInline()); | 177 CHECK(!pObj || pObj->IsInline()); |
178 auto it = m_Map.find(key); | 178 auto it = m_Map.find(key); |
179 if (it == m_Map.end()) { | 179 if (it == m_Map.end()) { |
180 if (pObj) | 180 if (pObj) |
181 m_Map.insert(std::make_pair(MaybeIntern(key), pObj)); | 181 m_Map.insert(std::make_pair(MaybeIntern(key), pObj)); |
182 return; | 182 return; |
183 } | 183 } |
184 | 184 |
185 if (it->second == pObj) | 185 if (it->second == pObj) |
186 return; | 186 return; |
187 delete it->second; | 187 it->second->Release(); |
188 | 188 |
189 if (pObj) | 189 if (pObj) |
190 it->second = pObj; | 190 it->second = pObj; |
191 else | 191 else |
192 m_Map.erase(it); | 192 m_Map.erase(it); |
193 } | 193 } |
194 | 194 |
195 void CPDF_Dictionary::ConvertToIndirectObjectFor( | 195 void CPDF_Dictionary::ConvertToIndirectObjectFor( |
196 const CFX_ByteString& key, | 196 const CFX_ByteString& key, |
197 CPDF_IndirectObjectHolder* pHolder) { | 197 CPDF_IndirectObjectHolder* pHolder) { |
198 auto it = m_Map.find(key); | 198 auto it = m_Map.find(key); |
199 if (it == m_Map.end() || it->second->IsReference()) | 199 if (it == m_Map.end() || it->second->IsReference()) |
200 return; | 200 return; |
201 | 201 |
202 uint32_t objnum = pHolder->AddIndirectObject(it->second); | 202 uint32_t objnum = pHolder->AddIndirectObject(it->second); |
203 it->second = new CPDF_Reference(pHolder, objnum); | 203 it->second = new CPDF_Reference(pHolder, objnum); |
204 } | 204 } |
205 | 205 |
206 void CPDF_Dictionary::RemoveFor(const CFX_ByteString& key) { | 206 void CPDF_Dictionary::RemoveFor(const CFX_ByteString& key) { |
207 auto it = m_Map.find(key); | 207 auto it = m_Map.find(key); |
208 if (it == m_Map.end()) | 208 if (it == m_Map.end()) |
209 return; | 209 return; |
210 | 210 |
211 delete it->second; | 211 it->second->Release(); |
212 m_Map.erase(it); | 212 m_Map.erase(it); |
213 } | 213 } |
214 | 214 |
215 void CPDF_Dictionary::ReplaceKey(const CFX_ByteString& oldkey, | 215 void CPDF_Dictionary::ReplaceKey(const CFX_ByteString& oldkey, |
216 const CFX_ByteString& newkey) { | 216 const CFX_ByteString& newkey) { |
217 auto old_it = m_Map.find(oldkey); | 217 auto old_it = m_Map.find(oldkey); |
218 if (old_it == m_Map.end()) | 218 if (old_it == m_Map.end()) |
219 return; | 219 return; |
220 | 220 |
221 auto new_it = m_Map.find(newkey); | 221 auto new_it = m_Map.find(newkey); |
222 if (new_it == old_it) | 222 if (new_it == old_it) |
223 return; | 223 return; |
224 | 224 |
225 if (new_it != m_Map.end()) { | 225 if (new_it != m_Map.end()) { |
226 delete new_it->second; | 226 new_it->second->Release(); |
227 new_it->second = old_it->second; | 227 new_it->second = old_it->second; |
228 } else { | 228 } else { |
229 m_Map.insert(std::make_pair(MaybeIntern(newkey), old_it->second)); | 229 m_Map.insert(std::make_pair(MaybeIntern(newkey), old_it->second)); |
230 } | 230 } |
231 m_Map.erase(old_it); | 231 m_Map.erase(old_it); |
232 } | 232 } |
233 | 233 |
234 void CPDF_Dictionary::SetIntegerFor(const CFX_ByteString& key, int i) { | 234 void CPDF_Dictionary::SetIntegerFor(const CFX_ByteString& key, int i) { |
235 SetFor(key, new CPDF_Number(i)); | 235 SetFor(key, new CPDF_Number(i)); |
236 } | 236 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 pArray->AddNumber(matrix.c); | 277 pArray->AddNumber(matrix.c); |
278 pArray->AddNumber(matrix.d); | 278 pArray->AddNumber(matrix.d); |
279 pArray->AddNumber(matrix.e); | 279 pArray->AddNumber(matrix.e); |
280 pArray->AddNumber(matrix.f); | 280 pArray->AddNumber(matrix.f); |
281 SetFor(key, pArray); | 281 SetFor(key, pArray); |
282 } | 282 } |
283 | 283 |
284 CFX_ByteString CPDF_Dictionary::MaybeIntern(const CFX_ByteString& str) { | 284 CFX_ByteString CPDF_Dictionary::MaybeIntern(const CFX_ByteString& str) { |
285 return m_pPool ? m_pPool->Intern(str) : str; | 285 return m_pPool ? m_pPool->Intern(str) : str; |
286 } | 286 } |
OLD | NEW |