| 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 int CPDF_Dictionary::GetIntegerBy(const CFX_ByteString& key, int def) const { | 89 int CPDF_Dictionary::GetIntegerBy(const CFX_ByteString& key, int def) const { |
| 90 CPDF_Object* p = GetObjectBy(key); | 90 CPDF_Object* p = GetObjectBy(key); |
| 91 return p ? p->GetInteger() : def; | 91 return p ? p->GetInteger() : def; |
| 92 } | 92 } |
| 93 | 93 |
| 94 FX_FLOAT CPDF_Dictionary::GetNumberBy(const CFX_ByteString& key) const { | 94 FX_FLOAT CPDF_Dictionary::GetNumberBy(const CFX_ByteString& key) const { |
| 95 CPDF_Object* p = GetObjectBy(key); | 95 CPDF_Object* p = GetObjectBy(key); |
| 96 return p ? p->GetNumber() : 0; | 96 return p ? p->GetNumber() : 0; |
| 97 } | 97 } |
| 98 | 98 |
| 99 FX_BOOL CPDF_Dictionary::GetBooleanBy(const CFX_ByteString& key, | 99 bool CPDF_Dictionary::GetBooleanBy(const CFX_ByteString& key, |
| 100 FX_BOOL bDefault) const { | 100 bool bDefault) const { |
| 101 CPDF_Object* p = GetObjectBy(key); | 101 CPDF_Object* p = GetObjectBy(key); |
| 102 return ToBoolean(p) ? p->GetInteger() : bDefault; | 102 return ToBoolean(p) ? p->GetInteger() != 0 : bDefault; |
| 103 } | 103 } |
| 104 | 104 |
| 105 CPDF_Dictionary* CPDF_Dictionary::GetDictBy(const CFX_ByteString& key) const { | 105 CPDF_Dictionary* CPDF_Dictionary::GetDictBy(const CFX_ByteString& key) const { |
| 106 CPDF_Object* p = GetDirectObjectBy(key); | 106 CPDF_Object* p = GetDirectObjectBy(key); |
| 107 if (!p) | 107 if (!p) |
| 108 return nullptr; | 108 return nullptr; |
| 109 if (CPDF_Dictionary* pDict = p->AsDictionary()) | 109 if (CPDF_Dictionary* pDict = p->AsDictionary()) |
| 110 return pDict; | 110 return pDict; |
| 111 if (CPDF_Stream* pStream = p->AsStream()) | 111 if (CPDF_Stream* pStream = p->AsStream()) |
| 112 return pStream->GetDict(); | 112 return pStream->GetDict(); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 void CPDF_Dictionary::AddReference(const CFX_ByteString& key, | 217 void CPDF_Dictionary::AddReference(const CFX_ByteString& key, |
| 218 CPDF_IndirectObjectHolder* pDoc, | 218 CPDF_IndirectObjectHolder* pDoc, |
| 219 uint32_t objnum) { | 219 uint32_t objnum) { |
| 220 SetAt(key, new CPDF_Reference(pDoc, objnum)); | 220 SetAt(key, new CPDF_Reference(pDoc, objnum)); |
| 221 } | 221 } |
| 222 | 222 |
| 223 void CPDF_Dictionary::SetAtNumber(const CFX_ByteString& key, FX_FLOAT f) { | 223 void CPDF_Dictionary::SetAtNumber(const CFX_ByteString& key, FX_FLOAT f) { |
| 224 SetAt(key, new CPDF_Number(f)); | 224 SetAt(key, new CPDF_Number(f)); |
| 225 } | 225 } |
| 226 | 226 |
| 227 void CPDF_Dictionary::SetAtBoolean(const CFX_ByteString& key, FX_BOOL bValue) { | 227 void CPDF_Dictionary::SetAtBoolean(const CFX_ByteString& key, bool bValue) { |
| 228 SetAt(key, new CPDF_Boolean(bValue)); | 228 SetAt(key, new CPDF_Boolean(bValue)); |
| 229 } | 229 } |
| 230 | 230 |
| 231 void CPDF_Dictionary::SetAtRect(const CFX_ByteString& key, | 231 void CPDF_Dictionary::SetAtRect(const CFX_ByteString& key, |
| 232 const CFX_FloatRect& rect) { | 232 const CFX_FloatRect& rect) { |
| 233 CPDF_Array* pArray = new CPDF_Array; | 233 CPDF_Array* pArray = new CPDF_Array; |
| 234 pArray->AddNumber(rect.left); | 234 pArray->AddNumber(rect.left); |
| 235 pArray->AddNumber(rect.bottom); | 235 pArray->AddNumber(rect.bottom); |
| 236 pArray->AddNumber(rect.right); | 236 pArray->AddNumber(rect.right); |
| 237 pArray->AddNumber(rect.top); | 237 pArray->AddNumber(rect.top); |
| 238 SetAt(key, pArray); | 238 SetAt(key, pArray); |
| 239 } | 239 } |
| 240 | 240 |
| 241 void CPDF_Dictionary::SetAtMatrix(const CFX_ByteString& key, | 241 void CPDF_Dictionary::SetAtMatrix(const CFX_ByteString& key, |
| 242 const CFX_Matrix& matrix) { | 242 const CFX_Matrix& matrix) { |
| 243 CPDF_Array* pArray = new CPDF_Array; | 243 CPDF_Array* pArray = new CPDF_Array; |
| 244 pArray->AddNumber(matrix.a); | 244 pArray->AddNumber(matrix.a); |
| 245 pArray->AddNumber(matrix.b); | 245 pArray->AddNumber(matrix.b); |
| 246 pArray->AddNumber(matrix.c); | 246 pArray->AddNumber(matrix.c); |
| 247 pArray->AddNumber(matrix.d); | 247 pArray->AddNumber(matrix.d); |
| 248 pArray->AddNumber(matrix.e); | 248 pArray->AddNumber(matrix.e); |
| 249 pArray->AddNumber(matrix.f); | 249 pArray->AddNumber(matrix.f); |
| 250 SetAt(key, pArray); | 250 SetAt(key, pArray); |
| 251 } | 251 } |
| OLD | NEW |