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 "core/fpdfapi/fpdf_parser/cpdf_boolean.h" | 9 #include "core/fpdfapi/fpdf_parser/cpdf_boolean.h" |
10 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" | 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 return this; | 44 return this; |
45 } | 45 } |
46 | 46 |
47 CPDF_Object* CPDF_Dictionary::Clone(FX_BOOL bDirect) const { | 47 CPDF_Object* CPDF_Dictionary::Clone(FX_BOOL bDirect) const { |
48 CPDF_Dictionary* pCopy = new CPDF_Dictionary(); | 48 CPDF_Dictionary* pCopy = new CPDF_Dictionary(); |
49 for (const auto& it : *this) | 49 for (const auto& it : *this) |
50 pCopy->m_Map.insert(std::make_pair(it.first, it.second->Clone(bDirect))); | 50 pCopy->m_Map.insert(std::make_pair(it.first, it.second->Clone(bDirect))); |
51 return pCopy; | 51 return pCopy; |
52 } | 52 } |
53 | 53 |
54 CPDF_Object* CPDF_Dictionary::GetElement(const CFX_ByteStringC& key) const { | 54 CPDF_Object* CPDF_Dictionary::GetObjectBy(const CFX_ByteStringC& key) const { |
55 auto it = m_Map.find(key); | 55 auto it = m_Map.find(key); |
56 if (it == m_Map.end()) | 56 if (it == m_Map.end()) |
57 return nullptr; | 57 return nullptr; |
58 return it->second; | 58 return it->second; |
59 } | 59 } |
60 CPDF_Object* CPDF_Dictionary::GetElementValue( | 60 CPDF_Object* CPDF_Dictionary::GetDirectObjectBy( |
61 const CFX_ByteStringC& key) const { | 61 const CFX_ByteStringC& key) const { |
62 CPDF_Object* p = GetElement(key); | 62 CPDF_Object* p = GetObjectBy(key); |
63 return p ? p->GetDirect() : nullptr; | 63 return p ? p->GetDirect() : nullptr; |
64 } | 64 } |
65 | 65 |
66 CFX_ByteString CPDF_Dictionary::GetStringBy(const CFX_ByteStringC& key) const { | 66 CFX_ByteString CPDF_Dictionary::GetStringBy(const CFX_ByteStringC& key) const { |
67 CPDF_Object* p = GetElement(key); | 67 CPDF_Object* p = GetObjectBy(key); |
68 return p ? p->GetString() : CFX_ByteString(); | 68 return p ? p->GetString() : CFX_ByteString(); |
69 } | 69 } |
70 | 70 |
71 CFX_ByteStringC CPDF_Dictionary::GetConstStringBy( | 71 CFX_ByteStringC CPDF_Dictionary::GetConstStringBy( |
72 const CFX_ByteStringC& key) const { | 72 const CFX_ByteStringC& key) const { |
73 CPDF_Object* p = GetElement(key); | 73 CPDF_Object* p = GetObjectBy(key); |
74 return p ? p->GetConstString() : CFX_ByteStringC(); | 74 return p ? p->GetConstString() : CFX_ByteStringC(); |
75 } | 75 } |
76 | 76 |
77 CFX_WideString CPDF_Dictionary::GetUnicodeTextBy( | 77 CFX_WideString CPDF_Dictionary::GetUnicodeTextBy( |
78 const CFX_ByteStringC& key) const { | 78 const CFX_ByteStringC& key) const { |
79 CPDF_Object* p = GetElement(key); | 79 CPDF_Object* p = GetObjectBy(key); |
80 if (CPDF_Reference* pRef = ToReference(p)) | 80 if (CPDF_Reference* pRef = ToReference(p)) |
81 p = pRef->GetDirect(); | 81 p = pRef->GetDirect(); |
82 return p ? p->GetUnicodeText() : CFX_WideString(); | 82 return p ? p->GetUnicodeText() : CFX_WideString(); |
83 } | 83 } |
84 | 84 |
85 CFX_ByteString CPDF_Dictionary::GetStringBy(const CFX_ByteStringC& key, | 85 CFX_ByteString CPDF_Dictionary::GetStringBy(const CFX_ByteStringC& key, |
86 const CFX_ByteStringC& def) const { | 86 const CFX_ByteStringC& def) const { |
87 CPDF_Object* p = GetElement(key); | 87 CPDF_Object* p = GetObjectBy(key); |
88 return p ? p->GetString() : CFX_ByteString(def); | 88 return p ? p->GetString() : CFX_ByteString(def); |
89 } | 89 } |
90 | 90 |
91 CFX_ByteStringC CPDF_Dictionary::GetConstStringBy( | 91 CFX_ByteStringC CPDF_Dictionary::GetConstStringBy( |
92 const CFX_ByteStringC& key, | 92 const CFX_ByteStringC& key, |
93 const CFX_ByteStringC& def) const { | 93 const CFX_ByteStringC& def) const { |
94 CPDF_Object* p = GetElement(key); | 94 CPDF_Object* p = GetObjectBy(key); |
95 return p ? p->GetConstString() : CFX_ByteStringC(def); | 95 return p ? p->GetConstString() : CFX_ByteStringC(def); |
96 } | 96 } |
97 | 97 |
98 int CPDF_Dictionary::GetIntegerBy(const CFX_ByteStringC& key) const { | 98 int CPDF_Dictionary::GetIntegerBy(const CFX_ByteStringC& key) const { |
99 CPDF_Object* p = GetElement(key); | 99 CPDF_Object* p = GetObjectBy(key); |
100 return p ? p->GetInteger() : 0; | 100 return p ? p->GetInteger() : 0; |
101 } | 101 } |
102 | 102 |
103 int CPDF_Dictionary::GetIntegerBy(const CFX_ByteStringC& key, int def) const { | 103 int CPDF_Dictionary::GetIntegerBy(const CFX_ByteStringC& key, int def) const { |
104 CPDF_Object* p = GetElement(key); | 104 CPDF_Object* p = GetObjectBy(key); |
105 return p ? p->GetInteger() : def; | 105 return p ? p->GetInteger() : def; |
106 } | 106 } |
107 | 107 |
108 FX_FLOAT CPDF_Dictionary::GetNumberBy(const CFX_ByteStringC& key) const { | 108 FX_FLOAT CPDF_Dictionary::GetNumberBy(const CFX_ByteStringC& key) const { |
109 CPDF_Object* p = GetElement(key); | 109 CPDF_Object* p = GetObjectBy(key); |
110 return p ? p->GetNumber() : 0; | 110 return p ? p->GetNumber() : 0; |
111 } | 111 } |
112 | 112 |
113 FX_BOOL CPDF_Dictionary::GetBooleanBy(const CFX_ByteStringC& key, | 113 FX_BOOL CPDF_Dictionary::GetBooleanBy(const CFX_ByteStringC& key, |
114 FX_BOOL bDefault) const { | 114 FX_BOOL bDefault) const { |
115 CPDF_Object* p = GetElement(key); | 115 CPDF_Object* p = GetObjectBy(key); |
116 return ToBoolean(p) ? p->GetInteger() : bDefault; | 116 return ToBoolean(p) ? p->GetInteger() : bDefault; |
117 } | 117 } |
118 | 118 |
119 CPDF_Dictionary* CPDF_Dictionary::GetDictBy(const CFX_ByteStringC& key) const { | 119 CPDF_Dictionary* CPDF_Dictionary::GetDictBy(const CFX_ByteStringC& key) const { |
120 CPDF_Object* p = GetElementValue(key); | 120 CPDF_Object* p = GetDirectObjectBy(key); |
121 if (!p) | 121 if (!p) |
122 return nullptr; | 122 return nullptr; |
123 if (CPDF_Dictionary* pDict = p->AsDictionary()) | 123 if (CPDF_Dictionary* pDict = p->AsDictionary()) |
124 return pDict; | 124 return pDict; |
125 if (CPDF_Stream* pStream = p->AsStream()) | 125 if (CPDF_Stream* pStream = p->AsStream()) |
126 return pStream->GetDict(); | 126 return pStream->GetDict(); |
127 return nullptr; | 127 return nullptr; |
128 } | 128 } |
129 | 129 |
130 CPDF_Array* CPDF_Dictionary::GetArrayBy(const CFX_ByteStringC& key) const { | 130 CPDF_Array* CPDF_Dictionary::GetArrayBy(const CFX_ByteStringC& key) const { |
131 return ToArray(GetElementValue(key)); | 131 return ToArray(GetDirectObjectBy(key)); |
132 } | 132 } |
133 | 133 |
134 CPDF_Stream* CPDF_Dictionary::GetStreamBy(const CFX_ByteStringC& key) const { | 134 CPDF_Stream* CPDF_Dictionary::GetStreamBy(const CFX_ByteStringC& key) const { |
135 return ToStream(GetElementValue(key)); | 135 return ToStream(GetDirectObjectBy(key)); |
136 } | 136 } |
137 | 137 |
138 CFX_FloatRect CPDF_Dictionary::GetRectBy(const CFX_ByteStringC& key) const { | 138 CFX_FloatRect CPDF_Dictionary::GetRectBy(const CFX_ByteStringC& key) const { |
139 CFX_FloatRect rect; | 139 CFX_FloatRect rect; |
140 CPDF_Array* pArray = GetArrayBy(key); | 140 CPDF_Array* pArray = GetArrayBy(key); |
141 if (pArray) | 141 if (pArray) |
142 rect = pArray->GetRect(); | 142 rect = pArray->GetRect(); |
143 return rect; | 143 return rect; |
144 } | 144 } |
145 | 145 |
146 CFX_Matrix CPDF_Dictionary::GetMatrixBy(const CFX_ByteStringC& key) const { | 146 CFX_Matrix CPDF_Dictionary::GetMatrixBy(const CFX_ByteStringC& key) const { |
147 CFX_Matrix matrix; | 147 CFX_Matrix matrix; |
148 CPDF_Array* pArray = GetArrayBy(key); | 148 CPDF_Array* pArray = GetArrayBy(key); |
149 if (pArray) | 149 if (pArray) |
150 matrix = pArray->GetMatrix(); | 150 matrix = pArray->GetMatrix(); |
151 return matrix; | 151 return matrix; |
152 } | 152 } |
153 | 153 |
154 FX_BOOL CPDF_Dictionary::KeyExist(const CFX_ByteStringC& key) const { | 154 FX_BOOL CPDF_Dictionary::KeyExist(const CFX_ByteStringC& key) const { |
155 return pdfium::ContainsKey(m_Map, key); | 155 return pdfium::ContainsKey(m_Map, key); |
156 } | 156 } |
157 | 157 |
158 bool CPDF_Dictionary::IsSignatureDict() const { | 158 bool CPDF_Dictionary::IsSignatureDict() const { |
159 CPDF_Object* pType = GetElementValue("Type"); | 159 CPDF_Object* pType = GetDirectObjectBy("Type"); |
160 if (!pType) | 160 if (!pType) |
161 pType = GetElementValue("FT"); | 161 pType = GetDirectObjectBy("FT"); |
162 return pType && pType->GetString() == "Sig"; | 162 return pType && pType->GetString() == "Sig"; |
163 } | 163 } |
164 | 164 |
165 void CPDF_Dictionary::SetAt(const CFX_ByteStringC& key, CPDF_Object* pObj) { | 165 void CPDF_Dictionary::SetAt(const CFX_ByteStringC& key, CPDF_Object* pObj) { |
166 ASSERT(IsDictionary()); | 166 ASSERT(IsDictionary()); |
167 // Avoid 2 constructions of CFX_ByteString. | 167 // Avoid 2 constructions of CFX_ByteString. |
168 CFX_ByteString key_bytestring = key; | 168 CFX_ByteString key_bytestring = key; |
169 auto it = m_Map.find(key_bytestring); | 169 auto it = m_Map.find(key_bytestring); |
170 if (it == m_Map.end()) { | 170 if (it == m_Map.end()) { |
171 if (pObj) | 171 if (pObj) |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 const CFX_Matrix& matrix) { | 262 const CFX_Matrix& matrix) { |
263 CPDF_Array* pArray = new CPDF_Array; | 263 CPDF_Array* pArray = new CPDF_Array; |
264 pArray->AddNumber(matrix.a); | 264 pArray->AddNumber(matrix.a); |
265 pArray->AddNumber(matrix.b); | 265 pArray->AddNumber(matrix.b); |
266 pArray->AddNumber(matrix.c); | 266 pArray->AddNumber(matrix.c); |
267 pArray->AddNumber(matrix.d); | 267 pArray->AddNumber(matrix.d); |
268 pArray->AddNumber(matrix.e); | 268 pArray->AddNumber(matrix.e); |
269 pArray->AddNumber(matrix.f); | 269 pArray->AddNumber(matrix.f); |
270 SetAt(key, pArray); | 270 SetAt(key, pArray); |
271 } | 271 } |
OLD | NEW |