Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(118)

Side by Side Diff: core/fpdfapi/fpdf_parser/cpdf_dictionary.cpp

Issue 2334323005: Rename dictionary set and get methods (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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>
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
74 CPDF_Object* CPDF_Dictionary::GetObjectBy(const CFX_ByteString& key) const { 74 CPDF_Object* CPDF_Dictionary::GetObjectFor(const CFX_ByteString& key) const {
75 auto it = m_Map.find(key); 75 auto it = m_Map.find(key);
76 return it != m_Map.end() ? it->second : nullptr; 76 return it != m_Map.end() ? it->second : nullptr;
77 } 77 }
78 78
79 CPDF_Object* CPDF_Dictionary::GetDirectObjectBy( 79 CPDF_Object* CPDF_Dictionary::GetDirectObjectFor(
80 const CFX_ByteString& key) const { 80 const CFX_ByteString& key) const {
81 CPDF_Object* p = GetObjectBy(key); 81 CPDF_Object* p = GetObjectFor(key);
82 return p ? p->GetDirect() : nullptr; 82 return p ? p->GetDirect() : nullptr;
83 } 83 }
84 84
85 CFX_ByteString CPDF_Dictionary::GetStringBy(const CFX_ByteString& key) const { 85 CFX_ByteString CPDF_Dictionary::GetStringFor(const CFX_ByteString& key) const {
86 CPDF_Object* p = GetObjectBy(key); 86 CPDF_Object* p = GetObjectFor(key);
87 return p ? p->GetString() : CFX_ByteString(); 87 return p ? p->GetString() : CFX_ByteString();
88 } 88 }
89 89
90 CFX_WideString CPDF_Dictionary::GetUnicodeTextBy( 90 CFX_WideString CPDF_Dictionary::GetUnicodeTextFor(
91 const CFX_ByteString& key) const { 91 const CFX_ByteString& key) const {
92 CPDF_Object* p = GetObjectBy(key); 92 CPDF_Object* p = GetObjectFor(key);
93 if (CPDF_Reference* pRef = ToReference(p)) 93 if (CPDF_Reference* pRef = ToReference(p))
94 p = pRef->GetDirect(); 94 p = pRef->GetDirect();
95 return p ? p->GetUnicodeText() : CFX_WideString(); 95 return p ? p->GetUnicodeText() : CFX_WideString();
96 } 96 }
97 97
98 CFX_ByteString CPDF_Dictionary::GetStringBy(const CFX_ByteString& key, 98 CFX_ByteString CPDF_Dictionary::GetStringFor(const CFX_ByteString& key,
99 const CFX_ByteString& def) const { 99 const CFX_ByteString& def) const {
100 CPDF_Object* p = GetObjectBy(key); 100 CPDF_Object* p = GetObjectFor(key);
101 return p ? p->GetString() : CFX_ByteString(def); 101 return p ? p->GetString() : CFX_ByteString(def);
102 } 102 }
103 103
104 int CPDF_Dictionary::GetIntegerBy(const CFX_ByteString& key) const { 104 int CPDF_Dictionary::GetIntegerFor(const CFX_ByteString& key) const {
105 CPDF_Object* p = GetObjectBy(key); 105 CPDF_Object* p = GetObjectFor(key);
106 return p ? p->GetInteger() : 0; 106 return p ? p->GetInteger() : 0;
107 } 107 }
108 108
109 int CPDF_Dictionary::GetIntegerBy(const CFX_ByteString& key, int def) const { 109 int CPDF_Dictionary::GetIntegerFor(const CFX_ByteString& key, int def) const {
110 CPDF_Object* p = GetObjectBy(key); 110 CPDF_Object* p = GetObjectFor(key);
111 return p ? p->GetInteger() : def; 111 return p ? p->GetInteger() : def;
112 } 112 }
113 113
114 FX_FLOAT CPDF_Dictionary::GetNumberBy(const CFX_ByteString& key) const { 114 FX_FLOAT CPDF_Dictionary::GetNumberFor(const CFX_ByteString& key) const {
115 CPDF_Object* p = GetObjectBy(key); 115 CPDF_Object* p = GetObjectFor(key);
116 return p ? p->GetNumber() : 0; 116 return p ? p->GetNumber() : 0;
117 } 117 }
118 118
119 bool CPDF_Dictionary::GetBooleanBy(const CFX_ByteString& key, 119 bool CPDF_Dictionary::GetBooleanFor(const CFX_ByteString& key,
120 bool bDefault) const { 120 bool bDefault) const {
121 CPDF_Object* p = GetObjectBy(key); 121 CPDF_Object* p = GetObjectFor(key);
122 return ToBoolean(p) ? p->GetInteger() != 0 : bDefault; 122 return ToBoolean(p) ? p->GetInteger() != 0 : bDefault;
123 } 123 }
124 124
125 CPDF_Dictionary* CPDF_Dictionary::GetDictBy(const CFX_ByteString& key) const { 125 CPDF_Dictionary* CPDF_Dictionary::GetDictFor(const CFX_ByteString& key) const {
126 CPDF_Object* p = GetDirectObjectBy(key); 126 CPDF_Object* p = GetDirectObjectFor(key);
127 if (!p) 127 if (!p)
128 return nullptr; 128 return nullptr;
129 if (CPDF_Dictionary* pDict = p->AsDictionary()) 129 if (CPDF_Dictionary* pDict = p->AsDictionary())
130 return pDict; 130 return pDict;
131 if (CPDF_Stream* pStream = p->AsStream()) 131 if (CPDF_Stream* pStream = p->AsStream())
132 return pStream->GetDict(); 132 return pStream->GetDict();
133 return nullptr; 133 return nullptr;
134 } 134 }
135 135
136 CPDF_Array* CPDF_Dictionary::GetArrayBy(const CFX_ByteString& key) const { 136 CPDF_Array* CPDF_Dictionary::GetArrayFor(const CFX_ByteString& key) const {
137 return ToArray(GetDirectObjectBy(key)); 137 return ToArray(GetDirectObjectFor(key));
138 } 138 }
139 139
140 CPDF_Stream* CPDF_Dictionary::GetStreamBy(const CFX_ByteString& key) const { 140 CPDF_Stream* CPDF_Dictionary::GetStreamFor(const CFX_ByteString& key) const {
141 return ToStream(GetDirectObjectBy(key)); 141 return ToStream(GetDirectObjectFor(key));
142 } 142 }
143 143
144 CFX_FloatRect CPDF_Dictionary::GetRectBy(const CFX_ByteString& key) const { 144 CFX_FloatRect CPDF_Dictionary::GetRectFor(const CFX_ByteString& key) const {
145 CFX_FloatRect rect; 145 CFX_FloatRect rect;
146 CPDF_Array* pArray = GetArrayBy(key); 146 CPDF_Array* pArray = GetArrayFor(key);
147 if (pArray) 147 if (pArray)
148 rect = pArray->GetRect(); 148 rect = pArray->GetRect();
149 return rect; 149 return rect;
150 } 150 }
151 151
152 CFX_Matrix CPDF_Dictionary::GetMatrixBy(const CFX_ByteString& key) const { 152 CFX_Matrix CPDF_Dictionary::GetMatrixFor(const CFX_ByteString& key) const {
153 CFX_Matrix matrix; 153 CFX_Matrix matrix;
154 CPDF_Array* pArray = GetArrayBy(key); 154 CPDF_Array* pArray = GetArrayFor(key);
155 if (pArray) 155 if (pArray)
156 matrix = pArray->GetMatrix(); 156 matrix = pArray->GetMatrix();
157 return matrix; 157 return matrix;
158 } 158 }
159 159
160 FX_BOOL CPDF_Dictionary::KeyExist(const CFX_ByteString& key) const { 160 FX_BOOL CPDF_Dictionary::KeyExist(const CFX_ByteString& key) const {
161 return pdfium::ContainsKey(m_Map, key); 161 return pdfium::ContainsKey(m_Map, key);
162 } 162 }
163 163
164 bool CPDF_Dictionary::IsSignatureDict() const { 164 bool CPDF_Dictionary::IsSignatureDict() const {
165 CPDF_Object* pType = GetDirectObjectBy("Type"); 165 CPDF_Object* pType = GetDirectObjectFor("Type");
166 if (!pType) 166 if (!pType)
167 pType = GetDirectObjectBy("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::SetAt(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(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
186 m_Map.erase(it); 186 m_Map.erase(it);
187 } 187 }
188 188
189 void CPDF_Dictionary::RemoveAt(const CFX_ByteString& key) { 189 void CPDF_Dictionary::RemoveFor(const CFX_ByteString& key) {
190 auto it = m_Map.find(key); 190 auto it = m_Map.find(key);
191 if (it == m_Map.end()) 191 if (it == m_Map.end())
192 return; 192 return;
193 193
194 it->second->Release(); 194 it->second->Release();
195 m_Map.erase(it); 195 m_Map.erase(it);
196 } 196 }
197 197
198 void CPDF_Dictionary::ReplaceKey(const CFX_ByteString& oldkey, 198 void CPDF_Dictionary::ReplaceKey(const CFX_ByteString& oldkey,
199 const CFX_ByteString& newkey) { 199 const CFX_ByteString& newkey) {
200 auto old_it = m_Map.find(oldkey); 200 auto old_it = m_Map.find(oldkey);
201 if (old_it == m_Map.end()) 201 if (old_it == m_Map.end())
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(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::SetAtInteger(const CFX_ByteString& key, int i) { 217 void CPDF_Dictionary::SetIntegerFor(const CFX_ByteString& key, int i) {
218 SetAt(key, new CPDF_Number(i)); 218 SetFor(key, new CPDF_Number(i));
219 } 219 }
220 220
221 void CPDF_Dictionary::SetAtName(const CFX_ByteString& key, 221 void CPDF_Dictionary::SetNameFor(const CFX_ByteString& key,
222 const CFX_ByteString& name) { 222 const CFX_ByteString& name) {
223 SetAt(key, new CPDF_Name(name)); 223 SetFor(key, new CPDF_Name(name));
224 } 224 }
225 225
226 void CPDF_Dictionary::SetAtString(const CFX_ByteString& key, 226 void CPDF_Dictionary::SetStringFor(const CFX_ByteString& key,
227 const CFX_ByteString& str) { 227 const CFX_ByteString& str) {
228 SetAt(key, new CPDF_String(str, FALSE)); 228 SetFor(key, new CPDF_String(str, FALSE));
229 } 229 }
230 230
231 void CPDF_Dictionary::SetAtReference(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 SetAt(key, new CPDF_Reference(pDoc, objnum)); 234 SetFor(key, new CPDF_Reference(pDoc, objnum));
235 } 235 }
236 236
237 void CPDF_Dictionary::SetAtNumber(const CFX_ByteString& key, FX_FLOAT f) { 237 void CPDF_Dictionary::SetNumberFor(const CFX_ByteString& key, FX_FLOAT f) {
238 SetAt(key, new CPDF_Number(f)); 238 SetFor(key, new CPDF_Number(f));
239 } 239 }
240 240
241 void CPDF_Dictionary::SetAtBoolean(const CFX_ByteString& key, bool bValue) { 241 void CPDF_Dictionary::SetBooleanFor(const CFX_ByteString& key, bool bValue) {
242 SetAt(key, new CPDF_Boolean(bValue)); 242 SetFor(key, new CPDF_Boolean(bValue));
243 } 243 }
244 244
245 void CPDF_Dictionary::SetAtRect(const CFX_ByteString& key, 245 void CPDF_Dictionary::SetRectFor(const CFX_ByteString& key,
246 const CFX_FloatRect& rect) { 246 const CFX_FloatRect& rect) {
247 CPDF_Array* pArray = new CPDF_Array; 247 CPDF_Array* pArray = new CPDF_Array;
248 pArray->AddNumber(rect.left); 248 pArray->AddNumber(rect.left);
249 pArray->AddNumber(rect.bottom); 249 pArray->AddNumber(rect.bottom);
250 pArray->AddNumber(rect.right); 250 pArray->AddNumber(rect.right);
251 pArray->AddNumber(rect.top); 251 pArray->AddNumber(rect.top);
252 SetAt(key, pArray); 252 SetFor(key, pArray);
253 } 253 }
254 254
255 void CPDF_Dictionary::SetAtMatrix(const CFX_ByteString& key, 255 void CPDF_Dictionary::SetMatrixFor(const CFX_ByteString& key,
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 SetAt(key, pArray); 264 SetFor(key, pArray);
265 } 265 }
OLDNEW
« no previous file with comments | « core/fpdfapi/fpdf_parser/cpdf_data_avail.cpp ('k') | core/fpdfapi/fpdf_parser/cpdf_document.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698