OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 |
| 7 #ifndef CORE_INCLUDE_FPDFAPI_CPDF_DICTIONARY_H_ |
| 8 #define CORE_INCLUDE_FPDFAPI_CPDF_DICTIONARY_H_ |
| 9 |
| 10 #include <map> |
| 11 |
| 12 #include "core/include/fpdfapi/cpdf_object.h" |
| 13 #include "core/include/fxcrt/fx_coordinates.h" |
| 14 #include "core/include/fxcrt/fx_string.h" |
| 15 |
| 16 class CPDF_IndirectObjectHolder; |
| 17 |
| 18 class CPDF_Dictionary : public CPDF_Object { |
| 19 public: |
| 20 using iterator = std::map<CFX_ByteString, CPDF_Object*>::iterator; |
| 21 using const_iterator = std::map<CFX_ByteString, CPDF_Object*>::const_iterator; |
| 22 |
| 23 CPDF_Dictionary(); |
| 24 |
| 25 // CPDF_Object. |
| 26 Type GetType() const override; |
| 27 CPDF_Object* Clone(FX_BOOL bDirect = FALSE) const override; |
| 28 CPDF_Dictionary* GetDict() const override; |
| 29 bool IsDictionary() const override; |
| 30 CPDF_Dictionary* AsDictionary() override; |
| 31 const CPDF_Dictionary* AsDictionary() const override; |
| 32 |
| 33 size_t GetCount() const { return m_Map.size(); } |
| 34 CPDF_Object* GetElement(const CFX_ByteStringC& key) const; |
| 35 CPDF_Object* GetElementValue(const CFX_ByteStringC& key) const; |
| 36 CFX_ByteString GetStringBy(const CFX_ByteStringC& key) const; |
| 37 CFX_ByteStringC GetConstStringBy(const CFX_ByteStringC& key) const; |
| 38 CFX_ByteString GetStringBy(const CFX_ByteStringC& key, |
| 39 const CFX_ByteStringC& default_str) const; |
| 40 CFX_ByteStringC GetConstStringBy(const CFX_ByteStringC& key, |
| 41 const CFX_ByteStringC& default_str) const; |
| 42 CFX_WideString GetUnicodeTextBy(const CFX_ByteStringC& key) const; |
| 43 int GetIntegerBy(const CFX_ByteStringC& key) const; |
| 44 int GetIntegerBy(const CFX_ByteStringC& key, int default_int) const; |
| 45 FX_BOOL GetBooleanBy(const CFX_ByteStringC& key, |
| 46 FX_BOOL bDefault = FALSE) const; |
| 47 FX_FLOAT GetNumberBy(const CFX_ByteStringC& key) const; |
| 48 CPDF_Dictionary* GetDictBy(const CFX_ByteStringC& key) const; |
| 49 CPDF_Stream* GetStreamBy(const CFX_ByteStringC& key) const; |
| 50 CPDF_Array* GetArrayBy(const CFX_ByteStringC& key) const; |
| 51 CFX_FloatRect GetRectBy(const CFX_ByteStringC& key) const; |
| 52 CFX_Matrix GetMatrixBy(const CFX_ByteStringC& key) const; |
| 53 FX_FLOAT GetFloatBy(const CFX_ByteStringC& key) const { |
| 54 return GetNumberBy(key); |
| 55 } |
| 56 |
| 57 FX_BOOL KeyExist(const CFX_ByteStringC& key) const; |
| 58 bool IsSignatureDict() const; |
| 59 |
| 60 // Set* functions invalidate iterators for the element with the key |key|. |
| 61 void SetAt(const CFX_ByteStringC& key, CPDF_Object* pObj); |
| 62 void SetAtName(const CFX_ByteStringC& key, const CFX_ByteString& name); |
| 63 void SetAtString(const CFX_ByteStringC& key, const CFX_ByteString& str); |
| 64 void SetAtInteger(const CFX_ByteStringC& key, int i); |
| 65 void SetAtNumber(const CFX_ByteStringC& key, FX_FLOAT f); |
| 66 void SetAtReference(const CFX_ByteStringC& key, |
| 67 CPDF_IndirectObjectHolder* pDoc, |
| 68 FX_DWORD objnum); |
| 69 void SetAtReference(const CFX_ByteStringC& key, |
| 70 CPDF_IndirectObjectHolder* pDoc, |
| 71 CPDF_Object* obj) { |
| 72 SetAtReference(key, pDoc, obj->GetObjNum()); |
| 73 } |
| 74 void SetAtRect(const CFX_ByteStringC& key, const CFX_FloatRect& rect); |
| 75 void SetAtMatrix(const CFX_ByteStringC& key, const CFX_Matrix& matrix); |
| 76 void SetAtBoolean(const CFX_ByteStringC& key, FX_BOOL bValue); |
| 77 |
| 78 void AddReference(const CFX_ByteStringC& key, |
| 79 CPDF_IndirectObjectHolder* pDoc, |
| 80 FX_DWORD objnum); |
| 81 |
| 82 // Invalidates iterators for the element with the key |key|. |
| 83 void RemoveAt(const CFX_ByteStringC& key); |
| 84 |
| 85 // Invalidates iterators for the element with the key |oldkey|. |
| 86 void ReplaceKey(const CFX_ByteStringC& oldkey, const CFX_ByteStringC& newkey); |
| 87 |
| 88 iterator begin() { return m_Map.begin(); } |
| 89 iterator end() { return m_Map.end(); } |
| 90 const_iterator begin() const { return m_Map.begin(); } |
| 91 const_iterator end() const { return m_Map.end(); } |
| 92 |
| 93 protected: |
| 94 ~CPDF_Dictionary() override; |
| 95 |
| 96 std::map<CFX_ByteString, CPDF_Object*> m_Map; |
| 97 }; |
| 98 |
| 99 #endif // CORE_INCLUDE_FPDFAPI_CPDF_DICTIONARY_H_ |
OLD | NEW |