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_dictionary.h" | 7 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 #include <utility> | 10 #include <utility> |
11 | 11 |
12 #include "core/fpdfapi/fpdf_parser/cpdf_boolean.h" | 12 #include "core/fpdfapi/fpdf_parser/cpdf_boolean.h" |
13 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" | 13 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" |
14 #include "core/fpdfapi/fpdf_parser/include/cpdf_name.h" | 14 #include "core/fpdfapi/fpdf_parser/include/cpdf_name.h" |
15 #include "core/fpdfapi/fpdf_parser/include/cpdf_number.h" | 15 #include "core/fpdfapi/fpdf_parser/include/cpdf_number.h" |
16 #include "core/fpdfapi/fpdf_parser/include/cpdf_reference.h" | 16 #include "core/fpdfapi/fpdf_parser/include/cpdf_reference.h" |
17 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream.h" | 17 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream.h" |
18 #include "core/fpdfapi/fpdf_parser/include/cpdf_string.h" | 18 #include "core/fpdfapi/fpdf_parser/include/cpdf_string.h" |
19 #include "third_party/base/stl_util.h" | 19 #include "third_party/base/stl_util.h" |
20 | 20 |
21 CPDF_Dictionary::CPDF_Dictionary() {} | 21 CPDF_Dictionary::CPDF_Dictionary(CFX_ByteStringPool* pPool) : m_pPool(pPool) {} |
22 | 22 |
23 CPDF_Dictionary::~CPDF_Dictionary() { | 23 CPDF_Dictionary::~CPDF_Dictionary() { |
24 // Mark the object as deleted so that it will not be deleted again | 24 // Mark the object as deleted so that it will not be deleted again |
25 // in case of cyclic references. | 25 // in case of cyclic references. |
26 m_ObjNum = kInvalidObjNum; | 26 m_ObjNum = kInvalidObjNum; |
27 for (const auto& it : m_Map) { | 27 for (const auto& it : m_Map) { |
28 if (it.second) | 28 if (it.second) |
29 it.second->Release(); | 29 it.second->Release(); |
30 } | 30 } |
31 } | 31 } |
(...skipping 21 matching lines...) Expand all Loading... |
53 } | 53 } |
54 | 54 |
55 CPDF_Object* CPDF_Dictionary::Clone() const { | 55 CPDF_Object* CPDF_Dictionary::Clone() const { |
56 return CloneObjectNonCyclic(false); | 56 return CloneObjectNonCyclic(false); |
57 } | 57 } |
58 | 58 |
59 CPDF_Object* CPDF_Dictionary::CloneNonCyclic( | 59 CPDF_Object* CPDF_Dictionary::CloneNonCyclic( |
60 bool bDirect, | 60 bool bDirect, |
61 std::set<const CPDF_Object*>* pVisited) const { | 61 std::set<const CPDF_Object*>* pVisited) const { |
62 pVisited->insert(this); | 62 pVisited->insert(this); |
63 CPDF_Dictionary* pCopy = new CPDF_Dictionary(); | 63 CPDF_Dictionary* pCopy = new CPDF_Dictionary(m_pPool); |
64 for (const auto& it : *this) { | 64 for (const auto& it : *this) { |
65 CPDF_Object* value = it.second; | 65 CPDF_Object* value = it.second; |
66 if (!pdfium::ContainsKey(*pVisited, value)) { | 66 if (!pdfium::ContainsKey(*pVisited, value)) { |
67 pCopy->m_Map.insert( | 67 pCopy->m_Map.insert( |
68 std::make_pair(it.first, value->CloneNonCyclic(bDirect, pVisited))); | 68 std::make_pair(it.first, value->CloneNonCyclic(bDirect, pVisited))); |
69 } | 69 } |
70 } | 70 } |
71 return pCopy; | 71 return pCopy; |
72 } | 72 } |
73 | 73 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 CPDF_Object* pType = GetDirectObjectFor("Type"); | 165 CPDF_Object* pType = GetDirectObjectFor("Type"); |
166 if (!pType) | 166 if (!pType) |
167 pType = GetDirectObjectFor("FT"); | 167 pType = GetDirectObjectFor("FT"); |
168 return pType && pType->GetString() == "Sig"; | 168 return pType && pType->GetString() == "Sig"; |
169 } | 169 } |
170 | 170 |
171 void CPDF_Dictionary::SetFor(const CFX_ByteString& key, CPDF_Object* pObj) { | 171 void CPDF_Dictionary::SetFor(const CFX_ByteString& key, CPDF_Object* pObj) { |
172 auto it = m_Map.find(key); | 172 auto it = m_Map.find(key); |
173 if (it == m_Map.end()) { | 173 if (it == m_Map.end()) { |
174 if (pObj) | 174 if (pObj) |
175 m_Map.insert(std::make_pair(key, pObj)); | 175 m_Map.insert(std::make_pair(MaybeIntern(key), pObj)); |
176 return; | 176 return; |
177 } | 177 } |
178 | 178 |
179 if (it->second == pObj) | 179 if (it->second == pObj) |
180 return; | 180 return; |
181 it->second->Release(); | 181 it->second->Release(); |
182 | 182 |
183 if (pObj) | 183 if (pObj) |
184 it->second = pObj; | 184 it->second = pObj; |
185 else | 185 else |
(...skipping 16 matching lines...) Expand all Loading... |
202 return; | 202 return; |
203 | 203 |
204 auto new_it = m_Map.find(newkey); | 204 auto new_it = m_Map.find(newkey); |
205 if (new_it == old_it) | 205 if (new_it == old_it) |
206 return; | 206 return; |
207 | 207 |
208 if (new_it != m_Map.end()) { | 208 if (new_it != m_Map.end()) { |
209 new_it->second->Release(); | 209 new_it->second->Release(); |
210 new_it->second = old_it->second; | 210 new_it->second = old_it->second; |
211 } else { | 211 } else { |
212 m_Map.insert(std::make_pair(newkey, old_it->second)); | 212 m_Map.insert(std::make_pair(MaybeIntern(newkey), old_it->second)); |
213 } | 213 } |
214 m_Map.erase(old_it); | 214 m_Map.erase(old_it); |
215 } | 215 } |
216 | 216 |
217 void CPDF_Dictionary::SetIntegerFor(const CFX_ByteString& key, int i) { | 217 void CPDF_Dictionary::SetIntegerFor(const CFX_ByteString& key, int i) { |
218 SetFor(key, new CPDF_Number(i)); | 218 SetFor(key, new CPDF_Number(i)); |
219 } | 219 } |
220 | 220 |
221 void CPDF_Dictionary::SetNameFor(const CFX_ByteString& key, | 221 void CPDF_Dictionary::SetNameFor(const CFX_ByteString& key, |
222 const CFX_ByteString& name) { | 222 const CFX_ByteString& name) { |
223 SetFor(key, new CPDF_Name(name)); | 223 SetFor(key, new CPDF_Name(MaybeIntern(name))); |
224 } | 224 } |
225 | 225 |
226 void CPDF_Dictionary::SetStringFor(const CFX_ByteString& key, | 226 void CPDF_Dictionary::SetStringFor(const CFX_ByteString& key, |
227 const CFX_ByteString& str) { | 227 const CFX_ByteString& str) { |
228 SetFor(key, new CPDF_String(str, FALSE)); | 228 SetFor(key, new CPDF_String(MaybeIntern(str), FALSE)); |
229 } | 229 } |
230 | 230 |
231 void CPDF_Dictionary::SetReferenceFor(const CFX_ByteString& key, | 231 void CPDF_Dictionary::SetReferenceFor(const CFX_ByteString& key, |
232 CPDF_IndirectObjectHolder* pDoc, | 232 CPDF_IndirectObjectHolder* pDoc, |
233 uint32_t objnum) { | 233 uint32_t objnum) { |
234 SetFor(key, new CPDF_Reference(pDoc, objnum)); | 234 SetFor(key, new CPDF_Reference(pDoc, objnum)); |
235 } | 235 } |
236 | 236 |
237 void CPDF_Dictionary::SetNumberFor(const CFX_ByteString& key, FX_FLOAT f) { | 237 void CPDF_Dictionary::SetNumberFor(const CFX_ByteString& key, FX_FLOAT f) { |
238 SetFor(key, new CPDF_Number(f)); | 238 SetFor(key, new CPDF_Number(f)); |
(...skipping 17 matching lines...) Expand all Loading... |
256 const CFX_Matrix& matrix) { | 256 const CFX_Matrix& matrix) { |
257 CPDF_Array* pArray = new CPDF_Array; | 257 CPDF_Array* pArray = new CPDF_Array; |
258 pArray->AddNumber(matrix.a); | 258 pArray->AddNumber(matrix.a); |
259 pArray->AddNumber(matrix.b); | 259 pArray->AddNumber(matrix.b); |
260 pArray->AddNumber(matrix.c); | 260 pArray->AddNumber(matrix.c); |
261 pArray->AddNumber(matrix.d); | 261 pArray->AddNumber(matrix.d); |
262 pArray->AddNumber(matrix.e); | 262 pArray->AddNumber(matrix.e); |
263 pArray->AddNumber(matrix.f); | 263 pArray->AddNumber(matrix.f); |
264 SetFor(key, pArray); | 264 SetFor(key, pArray); |
265 } | 265 } |
| 266 |
| 267 CFX_ByteString CPDF_Dictionary::MaybeIntern(const CFX_ByteString& str) { |
| 268 return m_pPool ? m_pPool->Intern(str) : str; |
| 269 } |
OLD | NEW |