| 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_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_DICTIONARY_H_ | |
| 8 #define CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_DICTIONARY_H_ | |
| 9 | |
| 10 #include <map> | |
| 11 #include <set> | |
| 12 | |
| 13 #include "core/fpdfapi/fpdf_parser/include/cpdf_object.h" | |
| 14 #include "core/fxcrt/include/cfx_string_pool_template.h" | |
| 15 #include "core/fxcrt/include/cfx_weak_ptr.h" | |
| 16 #include "core/fxcrt/include/fx_coordinates.h" | |
| 17 #include "core/fxcrt/include/fx_string.h" | |
| 18 | |
| 19 class CPDF_IndirectObjectHolder; | |
| 20 | |
| 21 class CPDF_Dictionary : public CPDF_Object { | |
| 22 public: | |
| 23 using iterator = std::map<CFX_ByteString, CPDF_Object*>::iterator; | |
| 24 using const_iterator = std::map<CFX_ByteString, CPDF_Object*>::const_iterator; | |
| 25 | |
| 26 explicit CPDF_Dictionary(const CFX_WeakPtr<CFX_ByteStringPool>& pPool); | |
| 27 | |
| 28 // CPDF_Object. | |
| 29 Type GetType() const override; | |
| 30 CPDF_Object* Clone() const override; | |
| 31 CPDF_Dictionary* GetDict() const override; | |
| 32 bool IsDictionary() const override; | |
| 33 CPDF_Dictionary* AsDictionary() override; | |
| 34 const CPDF_Dictionary* AsDictionary() const override; | |
| 35 | |
| 36 size_t GetCount() const { return m_Map.size(); } | |
| 37 CPDF_Object* GetObjectFor(const CFX_ByteString& key) const; | |
| 38 CPDF_Object* GetDirectObjectFor(const CFX_ByteString& key) const; | |
| 39 CFX_ByteString GetStringFor(const CFX_ByteString& key) const; | |
| 40 CFX_ByteString GetStringFor(const CFX_ByteString& key, | |
| 41 const CFX_ByteString& default_str) const; | |
| 42 CFX_WideString GetUnicodeTextFor(const CFX_ByteString& key) const; | |
| 43 int GetIntegerFor(const CFX_ByteString& key) const; | |
| 44 int GetIntegerFor(const CFX_ByteString& key, int default_int) const; | |
| 45 bool GetBooleanFor(const CFX_ByteString& key, bool bDefault = false) const; | |
| 46 FX_FLOAT GetNumberFor(const CFX_ByteString& key) const; | |
| 47 CPDF_Dictionary* GetDictFor(const CFX_ByteString& key) const; | |
| 48 CPDF_Stream* GetStreamFor(const CFX_ByteString& key) const; | |
| 49 CPDF_Array* GetArrayFor(const CFX_ByteString& key) const; | |
| 50 CFX_FloatRect GetRectFor(const CFX_ByteString& key) const; | |
| 51 CFX_Matrix GetMatrixFor(const CFX_ByteString& key) const; | |
| 52 FX_FLOAT GetFloatFor(const CFX_ByteString& key) const { | |
| 53 return GetNumberFor(key); | |
| 54 } | |
| 55 | |
| 56 FX_BOOL KeyExist(const CFX_ByteString& key) const; | |
| 57 bool IsSignatureDict() const; | |
| 58 | |
| 59 // Set* functions invalidate iterators for the element with the key |key|. | |
| 60 void SetFor(const CFX_ByteString& key, CPDF_Object* pObj); | |
| 61 void SetNameFor(const CFX_ByteString& key, const CFX_ByteString& name); | |
| 62 void SetStringFor(const CFX_ByteString& key, const CFX_ByteString& str); | |
| 63 void SetIntegerFor(const CFX_ByteString& key, int i); | |
| 64 void SetNumberFor(const CFX_ByteString& key, FX_FLOAT f); | |
| 65 void SetReferenceFor(const CFX_ByteString& key, | |
| 66 CPDF_IndirectObjectHolder* pDoc, | |
| 67 uint32_t objnum); | |
| 68 void SetRectFor(const CFX_ByteString& key, const CFX_FloatRect& rect); | |
| 69 void SetMatrixFor(const CFX_ByteString& key, const CFX_Matrix& matrix); | |
| 70 void SetBooleanFor(const CFX_ByteString& key, bool bValue); | |
| 71 | |
| 72 // Invalidates iterators for the element with the key |key|. | |
| 73 void RemoveFor(const CFX_ByteString& key); | |
| 74 | |
| 75 // Invalidates iterators for the element with the key |oldkey|. | |
| 76 void ReplaceKey(const CFX_ByteString& oldkey, const CFX_ByteString& newkey); | |
| 77 | |
| 78 iterator begin() { return m_Map.begin(); } | |
| 79 iterator end() { return m_Map.end(); } | |
| 80 const_iterator begin() const { return m_Map.begin(); } | |
| 81 const_iterator end() const { return m_Map.end(); } | |
| 82 | |
| 83 CFX_WeakPtr<CFX_ByteStringPool> GetByteStringPool() const { return m_pPool; } | |
| 84 | |
| 85 protected: | |
| 86 ~CPDF_Dictionary() override; | |
| 87 | |
| 88 CFX_ByteString MaybeIntern(const CFX_ByteString& str); | |
| 89 CPDF_Object* CloneNonCyclic( | |
| 90 bool bDirect, | |
| 91 std::set<const CPDF_Object*>* visited) const override; | |
| 92 | |
| 93 CFX_WeakPtr<CFX_ByteStringPool> m_pPool; | |
| 94 std::map<CFX_ByteString, CPDF_Object*> m_Map; | |
| 95 }; | |
| 96 | |
| 97 #endif // CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_DICTIONARY_H_ | |
| OLD | NEW |