OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef CORE_INCLUDE_FPDFAPI_FPDF_OBJECTS_H_ | 7 #ifndef CORE_INCLUDE_FPDFAPI_FPDF_OBJECTS_H_ |
8 #define CORE_INCLUDE_FPDFAPI_FPDF_OBJECTS_H_ | 8 #define CORE_INCLUDE_FPDFAPI_FPDF_OBJECTS_H_ |
9 | 9 |
10 #include <map> | 10 #include <map> |
(...skipping 12 matching lines...) Expand all Loading... |
23 class CPDF_Null; | 23 class CPDF_Null; |
24 class CPDF_Number; | 24 class CPDF_Number; |
25 class CPDF_Parser; | 25 class CPDF_Parser; |
26 class CPDF_Reference; | 26 class CPDF_Reference; |
27 class CPDF_Stream; | 27 class CPDF_Stream; |
28 class CPDF_StreamAcc; | 28 class CPDF_StreamAcc; |
29 class CPDF_StreamFilter; | 29 class CPDF_StreamFilter; |
30 class CPDF_String; | 30 class CPDF_String; |
31 class IFX_FileRead; | 31 class IFX_FileRead; |
32 | 32 |
33 #define PDFOBJ_INVALID 0 | |
34 #define PDFOBJ_BOOLEAN 1 | |
35 #define PDFOBJ_NUMBER 2 | |
36 #define PDFOBJ_STRING 3 | |
37 #define PDFOBJ_NAME 4 | |
38 #define PDFOBJ_ARRAY 5 | |
39 #define PDFOBJ_DICTIONARY 6 | |
40 #define PDFOBJ_STREAM 7 | |
41 #define PDFOBJ_NULL 8 | |
42 #define PDFOBJ_REFERENCE 9 | |
43 | |
44 class CPDF_Object { | 33 class CPDF_Object { |
45 public: | 34 public: |
46 int GetType() const { return m_Type; } | 35 enum Type { |
| 36 BOOLEAN = 1, |
| 37 NUMBER, |
| 38 STRING, |
| 39 NAME, |
| 40 ARRAY, |
| 41 DICTIONARY, |
| 42 STREAM, |
| 43 NULLOBJ, |
| 44 REFERENCE |
| 45 }; |
| 46 |
| 47 Type GetType() const { return m_Type; } |
47 FX_DWORD GetObjNum() const { return m_ObjNum; } | 48 FX_DWORD GetObjNum() const { return m_ObjNum; } |
48 FX_DWORD GetGenNum() const { return m_GenNum; } | 49 FX_DWORD GetGenNum() const { return m_GenNum; } |
49 | 50 |
50 FX_BOOL IsIdentical(CPDF_Object* pObj) const; | 51 FX_BOOL IsIdentical(CPDF_Object* pObj) const; |
51 CPDF_Object* Clone(FX_BOOL bDirect = FALSE) const; | 52 CPDF_Object* Clone(FX_BOOL bDirect = FALSE) const; |
52 CPDF_Object* CloneRef(CPDF_IndirectObjectHolder* pObjs) const; | 53 CPDF_Object* CloneRef(CPDF_IndirectObjectHolder* pObjs) const; |
53 | 54 |
54 CPDF_Object* GetDirect() const; | 55 CPDF_Object* GetDirect() const; |
55 FX_BOOL IsModified() const { return FALSE; } | 56 FX_BOOL IsModified() const { return FALSE; } |
56 | 57 |
57 void Release(); | 58 void Release(); |
58 | 59 |
59 CFX_ByteString GetString() const; | 60 CFX_ByteString GetString() const; |
60 CFX_ByteStringC GetConstString() const; | 61 CFX_ByteStringC GetConstString() const; |
61 CFX_WideString GetUnicodeText(CFX_CharMap* pCharMap = NULL) const; | 62 CFX_WideString GetUnicodeText(CFX_CharMap* pCharMap = NULL) const; |
62 FX_FLOAT GetNumber() const; | 63 FX_FLOAT GetNumber() const; |
63 FX_FLOAT GetNumber16() const; | 64 FX_FLOAT GetNumber16() const; |
64 int GetInteger() const; | 65 int GetInteger() const; |
65 CPDF_Dictionary* GetDict() const; | 66 CPDF_Dictionary* GetDict() const; |
66 CPDF_Array* GetArray() const; | 67 CPDF_Array* GetArray() const; |
67 | 68 |
68 void SetString(const CFX_ByteString& str); | 69 void SetString(const CFX_ByteString& str); |
69 void SetUnicodeText(const FX_WCHAR* pUnicodes, int len = -1); | 70 void SetUnicodeText(const FX_WCHAR* pUnicodes, int len = -1); |
70 | 71 |
71 bool IsArray() const { return m_Type == PDFOBJ_ARRAY; } | 72 bool IsArray() const { return m_Type == ARRAY; } |
72 bool IsBoolean() const { return m_Type == PDFOBJ_BOOLEAN; } | 73 bool IsBoolean() const { return m_Type == BOOLEAN; } |
73 bool IsDictionary() const { return m_Type == PDFOBJ_DICTIONARY; } | 74 bool IsDictionary() const { return m_Type == DICTIONARY; } |
74 bool IsName() const { return m_Type == PDFOBJ_NAME; } | 75 bool IsName() const { return m_Type == NAME; } |
75 bool IsNumber() const { return m_Type == PDFOBJ_NUMBER; } | 76 bool IsNumber() const { return m_Type == NUMBER; } |
76 bool IsReference() const { return m_Type == PDFOBJ_REFERENCE; } | 77 bool IsReference() const { return m_Type == REFERENCE; } |
77 bool IsStream() const { return m_Type == PDFOBJ_STREAM; } | 78 bool IsStream() const { return m_Type == STREAM; } |
78 bool IsString() const { return m_Type == PDFOBJ_STRING; } | 79 bool IsString() const { return m_Type == STRING; } |
79 | 80 |
80 CPDF_Array* AsArray(); | 81 CPDF_Array* AsArray(); |
81 const CPDF_Array* AsArray() const; | 82 const CPDF_Array* AsArray() const; |
82 CPDF_Boolean* AsBoolean(); | 83 CPDF_Boolean* AsBoolean(); |
83 const CPDF_Boolean* AsBoolean() const; | 84 const CPDF_Boolean* AsBoolean() const; |
84 CPDF_Dictionary* AsDictionary(); | 85 CPDF_Dictionary* AsDictionary(); |
85 const CPDF_Dictionary* AsDictionary() const; | 86 const CPDF_Dictionary* AsDictionary() const; |
86 CPDF_Name* AsName(); | 87 CPDF_Name* AsName(); |
87 const CPDF_Name* AsName() const; | 88 const CPDF_Name* AsName() const; |
88 CPDF_Number* AsNumber(); | 89 CPDF_Number* AsNumber(); |
89 const CPDF_Number* AsNumber() const; | 90 const CPDF_Number* AsNumber() const; |
90 CPDF_Reference* AsReference(); | 91 CPDF_Reference* AsReference(); |
91 const CPDF_Reference* AsReference() const; | 92 const CPDF_Reference* AsReference() const; |
92 CPDF_Stream* AsStream(); | 93 CPDF_Stream* AsStream(); |
93 const CPDF_Stream* AsStream() const; | 94 const CPDF_Stream* AsStream() const; |
94 CPDF_String* AsString(); | 95 CPDF_String* AsString(); |
95 const CPDF_String* AsString() const; | 96 const CPDF_String* AsString() const; |
96 | 97 |
97 protected: | 98 protected: |
98 explicit CPDF_Object(FX_DWORD type) | 99 explicit CPDF_Object(Type type) : m_Type(type), m_ObjNum(0), m_GenNum(0) {} |
99 : m_Type(type), m_ObjNum(0), m_GenNum(0) {} | |
100 ~CPDF_Object() {} | 100 ~CPDF_Object() {} |
101 void Destroy(); | 101 void Destroy(); |
102 | 102 |
103 const CPDF_Object* GetBasicObject() const; | 103 const CPDF_Object* GetBasicObject() const; |
104 | 104 |
105 FX_DWORD m_Type; | 105 const Type m_Type; |
106 FX_DWORD m_ObjNum; | 106 FX_DWORD m_ObjNum; |
107 FX_DWORD m_GenNum; | 107 FX_DWORD m_GenNum; |
108 | 108 |
109 friend class CPDF_IndirectObjectHolder; | 109 friend class CPDF_IndirectObjectHolder; |
110 friend class CPDF_Parser; | 110 friend class CPDF_Parser; |
111 friend class CPDF_SyntaxParser; | 111 friend class CPDF_SyntaxParser; |
112 | 112 |
113 private: | 113 private: |
114 CPDF_Object(const CPDF_Object& src) {} | |
115 CPDF_Object* CloneInternal(FX_BOOL bDirect, | 114 CPDF_Object* CloneInternal(FX_BOOL bDirect, |
116 std::set<FX_DWORD>* visited) const; | 115 std::set<FX_DWORD>* visited) const; |
117 }; | 116 }; |
118 class CPDF_Boolean : public CPDF_Object { | 117 class CPDF_Boolean : public CPDF_Object { |
119 public: | 118 public: |
120 CPDF_Boolean() : CPDF_Object(PDFOBJ_BOOLEAN), m_bValue(false) {} | 119 CPDF_Boolean() : CPDF_Object(BOOLEAN), m_bValue(false) {} |
121 explicit CPDF_Boolean(FX_BOOL value) | 120 explicit CPDF_Boolean(FX_BOOL value) |
122 : CPDF_Object(PDFOBJ_BOOLEAN), m_bValue(value) {} | 121 : CPDF_Object(BOOLEAN), m_bValue(value) {} |
123 | 122 |
124 FX_BOOL Identical(CPDF_Boolean* pOther) const { | 123 FX_BOOL Identical(CPDF_Boolean* pOther) const { |
125 return m_bValue == pOther->m_bValue; | 124 return m_bValue == pOther->m_bValue; |
126 } | 125 } |
127 | 126 |
128 CFX_ByteString GetString() const { return m_bValue ? "true" : "false"; } | 127 CFX_ByteString GetString() const { return m_bValue ? "true" : "false"; } |
129 FX_BOOL GetValue() const { return m_bValue; } | 128 FX_BOOL GetValue() const { return m_bValue; } |
130 | 129 |
131 protected: | 130 protected: |
132 FX_BOOL m_bValue; | 131 FX_BOOL m_bValue; |
133 friend class CPDF_Object; | 132 friend class CPDF_Object; |
134 }; | 133 }; |
135 inline CPDF_Boolean* ToBoolean(CPDF_Object* obj) { | 134 inline CPDF_Boolean* ToBoolean(CPDF_Object* obj) { |
136 return obj ? obj->AsBoolean() : nullptr; | 135 return obj ? obj->AsBoolean() : nullptr; |
137 } | 136 } |
138 inline const CPDF_Boolean* ToBoolean(const CPDF_Object* obj) { | 137 inline const CPDF_Boolean* ToBoolean(const CPDF_Object* obj) { |
139 return obj ? obj->AsBoolean() : nullptr; | 138 return obj ? obj->AsBoolean() : nullptr; |
140 } | 139 } |
141 | 140 |
142 class CPDF_Number : public CPDF_Object { | 141 class CPDF_Number : public CPDF_Object { |
143 public: | 142 public: |
144 CPDF_Number() : CPDF_Object(PDFOBJ_NUMBER), m_bInteger(TRUE), m_Integer(0) {} | 143 CPDF_Number() : CPDF_Object(NUMBER), m_bInteger(TRUE), m_Integer(0) {} |
145 | 144 |
146 explicit CPDF_Number(int value); | 145 explicit CPDF_Number(int value); |
147 | 146 |
148 explicit CPDF_Number(FX_FLOAT value); | 147 explicit CPDF_Number(FX_FLOAT value); |
149 | 148 |
150 explicit CPDF_Number(const CFX_ByteStringC& str); | 149 explicit CPDF_Number(const CFX_ByteStringC& str); |
151 | 150 |
152 FX_BOOL Identical(CPDF_Number* pOther) const; | 151 FX_BOOL Identical(CPDF_Number* pOther) const; |
153 | 152 |
154 CFX_ByteString GetString() const; | 153 CFX_ByteString GetString() const; |
(...skipping 28 matching lines...) Expand all Loading... |
183 }; | 182 }; |
184 inline CPDF_Number* ToNumber(CPDF_Object* obj) { | 183 inline CPDF_Number* ToNumber(CPDF_Object* obj) { |
185 return obj ? obj->AsNumber() : nullptr; | 184 return obj ? obj->AsNumber() : nullptr; |
186 } | 185 } |
187 inline const CPDF_Number* ToNumber(const CPDF_Object* obj) { | 186 inline const CPDF_Number* ToNumber(const CPDF_Object* obj) { |
188 return obj ? obj->AsNumber() : nullptr; | 187 return obj ? obj->AsNumber() : nullptr; |
189 } | 188 } |
190 | 189 |
191 class CPDF_String : public CPDF_Object { | 190 class CPDF_String : public CPDF_Object { |
192 public: | 191 public: |
193 CPDF_String() : CPDF_Object(PDFOBJ_STRING), m_bHex(FALSE) {} | 192 CPDF_String() : CPDF_Object(STRING), m_bHex(FALSE) {} |
194 | 193 |
195 CPDF_String(const CFX_ByteString& str, FX_BOOL bHex) | 194 CPDF_String(const CFX_ByteString& str, FX_BOOL bHex) |
196 : CPDF_Object(PDFOBJ_STRING), m_String(str), m_bHex(bHex) {} | 195 : CPDF_Object(STRING), m_String(str), m_bHex(bHex) {} |
197 | 196 |
198 explicit CPDF_String(const CFX_WideString& str); | 197 explicit CPDF_String(const CFX_WideString& str); |
199 | 198 |
200 CFX_ByteString GetString() const { return m_String; } | 199 CFX_ByteString GetString() const { return m_String; } |
201 | 200 |
202 FX_BOOL Identical(CPDF_String* pOther) const { | 201 FX_BOOL Identical(CPDF_String* pOther) const { |
203 return m_String == pOther->m_String; | 202 return m_String == pOther->m_String; |
204 } | 203 } |
205 | 204 |
206 FX_BOOL IsHex() const { return m_bHex; } | 205 FX_BOOL IsHex() const { return m_bHex; } |
207 | 206 |
208 protected: | 207 protected: |
209 CFX_ByteString m_String; | 208 CFX_ByteString m_String; |
210 | 209 |
211 FX_BOOL m_bHex; | 210 FX_BOOL m_bHex; |
212 friend class CPDF_Object; | 211 friend class CPDF_Object; |
213 }; | 212 }; |
214 inline CPDF_String* ToString(CPDF_Object* obj) { | 213 inline CPDF_String* ToString(CPDF_Object* obj) { |
215 return obj ? obj->AsString() : nullptr; | 214 return obj ? obj->AsString() : nullptr; |
216 } | 215 } |
217 inline const CPDF_String* ToString(const CPDF_Object* obj) { | 216 inline const CPDF_String* ToString(const CPDF_Object* obj) { |
218 return obj ? obj->AsString() : nullptr; | 217 return obj ? obj->AsString() : nullptr; |
219 } | 218 } |
220 | 219 |
221 class CPDF_Name : public CPDF_Object { | 220 class CPDF_Name : public CPDF_Object { |
222 public: | 221 public: |
223 explicit CPDF_Name(const CFX_ByteString& str) | 222 explicit CPDF_Name(const CFX_ByteString& str) |
224 : CPDF_Object(PDFOBJ_NAME), m_Name(str) {} | 223 : CPDF_Object(NAME), m_Name(str) {} |
225 explicit CPDF_Name(const CFX_ByteStringC& str) | 224 explicit CPDF_Name(const CFX_ByteStringC& str) |
226 : CPDF_Object(PDFOBJ_NAME), m_Name(str) {} | 225 : CPDF_Object(NAME), m_Name(str) {} |
227 explicit CPDF_Name(const FX_CHAR* str) | 226 explicit CPDF_Name(const FX_CHAR* str) : CPDF_Object(NAME), m_Name(str) {} |
228 : CPDF_Object(PDFOBJ_NAME), m_Name(str) {} | |
229 | 227 |
230 CFX_ByteString GetString() const { return m_Name; } | 228 CFX_ByteString GetString() const { return m_Name; } |
231 | 229 |
232 FX_BOOL Identical(CPDF_Name* pOther) const { | 230 FX_BOOL Identical(CPDF_Name* pOther) const { |
233 return m_Name == pOther->m_Name; | 231 return m_Name == pOther->m_Name; |
234 } | 232 } |
235 | 233 |
236 protected: | 234 protected: |
237 CFX_ByteString m_Name; | 235 CFX_ByteString m_Name; |
238 friend class CPDF_Object; | 236 friend class CPDF_Object; |
239 }; | 237 }; |
240 inline CPDF_Name* ToName(CPDF_Object* obj) { | 238 inline CPDF_Name* ToName(CPDF_Object* obj) { |
241 return obj ? obj->AsName() : nullptr; | 239 return obj ? obj->AsName() : nullptr; |
242 } | 240 } |
243 inline const CPDF_Name* ToName(const CPDF_Object* obj) { | 241 inline const CPDF_Name* ToName(const CPDF_Object* obj) { |
244 return obj ? obj->AsName() : nullptr; | 242 return obj ? obj->AsName() : nullptr; |
245 } | 243 } |
246 | 244 |
247 class CPDF_Array : public CPDF_Object { | 245 class CPDF_Array : public CPDF_Object { |
248 public: | 246 public: |
249 CPDF_Array() : CPDF_Object(PDFOBJ_ARRAY) {} | 247 CPDF_Array() : CPDF_Object(ARRAY) {} |
250 | 248 |
251 FX_DWORD GetCount() const { return m_Objects.GetSize(); } | 249 FX_DWORD GetCount() const { return m_Objects.GetSize(); } |
252 | 250 |
253 CPDF_Object* GetElement(FX_DWORD index) const; | 251 CPDF_Object* GetElement(FX_DWORD index) const; |
254 | 252 |
255 CPDF_Object* GetElementValue(FX_DWORD index) const; | 253 CPDF_Object* GetElementValue(FX_DWORD index) const; |
256 | 254 |
257 CFX_Matrix GetMatrix(); | 255 CFX_Matrix GetMatrix(); |
258 | 256 |
259 CFX_FloatRect GetRect(); | 257 CFX_FloatRect GetRect(); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 } | 315 } |
318 inline const CPDF_Array* ToArray(const CPDF_Object* obj) { | 316 inline const CPDF_Array* ToArray(const CPDF_Object* obj) { |
319 return obj ? obj->AsArray() : nullptr; | 317 return obj ? obj->AsArray() : nullptr; |
320 } | 318 } |
321 | 319 |
322 class CPDF_Dictionary : public CPDF_Object { | 320 class CPDF_Dictionary : public CPDF_Object { |
323 public: | 321 public: |
324 using iterator = std::map<CFX_ByteString, CPDF_Object*>::iterator; | 322 using iterator = std::map<CFX_ByteString, CPDF_Object*>::iterator; |
325 using const_iterator = std::map<CFX_ByteString, CPDF_Object*>::const_iterator; | 323 using const_iterator = std::map<CFX_ByteString, CPDF_Object*>::const_iterator; |
326 | 324 |
327 CPDF_Dictionary() : CPDF_Object(PDFOBJ_DICTIONARY) {} | 325 CPDF_Dictionary() : CPDF_Object(DICTIONARY) {} |
328 | 326 |
329 CPDF_Object* GetElement(const CFX_ByteStringC& key) const; | 327 CPDF_Object* GetElement(const CFX_ByteStringC& key) const; |
330 | 328 |
331 CPDF_Object* GetElementValue(const CFX_ByteStringC& key) const; | 329 CPDF_Object* GetElementValue(const CFX_ByteStringC& key) const; |
332 | 330 |
333 CFX_ByteString GetString(const CFX_ByteStringC& key) const; | 331 CFX_ByteString GetString(const CFX_ByteStringC& key) const; |
334 | 332 |
335 CFX_ByteStringC GetConstString(const CFX_ByteStringC& key) const; | 333 CFX_ByteStringC GetConstString(const CFX_ByteStringC& key) const; |
336 | 334 |
337 CFX_ByteString GetString(const CFX_ByteStringC& key, | 335 CFX_ByteString GetString(const CFX_ByteStringC& key, |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 | 518 |
521 CPDF_Dictionary* m_pImageParam; | 519 CPDF_Dictionary* m_pImageParam; |
522 | 520 |
523 const CPDF_Stream* m_pStream; | 521 const CPDF_Stream* m_pStream; |
524 | 522 |
525 uint8_t* m_pSrcData; | 523 uint8_t* m_pSrcData; |
526 }; | 524 }; |
527 | 525 |
528 class CPDF_Null : public CPDF_Object { | 526 class CPDF_Null : public CPDF_Object { |
529 public: | 527 public: |
530 CPDF_Null() : CPDF_Object(PDFOBJ_NULL) {} | 528 CPDF_Null() : CPDF_Object(NULLOBJ) {} |
531 }; | 529 }; |
532 | 530 |
533 class CPDF_Reference : public CPDF_Object { | 531 class CPDF_Reference : public CPDF_Object { |
534 public: | 532 public: |
535 CPDF_Reference(CPDF_IndirectObjectHolder* pDoc, int objnum) | 533 CPDF_Reference(CPDF_IndirectObjectHolder* pDoc, int objnum) |
536 : CPDF_Object(PDFOBJ_REFERENCE), m_pObjList(pDoc), m_RefObjNum(objnum) {} | 534 : CPDF_Object(REFERENCE), m_pObjList(pDoc), m_RefObjNum(objnum) {} |
537 | 535 |
538 CPDF_IndirectObjectHolder* GetObjList() const { return m_pObjList; } | 536 CPDF_IndirectObjectHolder* GetObjList() const { return m_pObjList; } |
539 | 537 |
540 FX_DWORD GetRefObjNum() const { return m_RefObjNum; } | 538 FX_DWORD GetRefObjNum() const { return m_RefObjNum; } |
541 | 539 |
542 void SetRef(CPDF_IndirectObjectHolder* pDoc, FX_DWORD objnum); | 540 void SetRef(CPDF_IndirectObjectHolder* pDoc, FX_DWORD objnum); |
543 | 541 |
544 FX_BOOL Identical(CPDF_Reference* pOther) const { | 542 FX_BOOL Identical(CPDF_Reference* pOther) const { |
545 return m_RefObjNum == pOther->m_RefObjNum; | 543 return m_RefObjNum == pOther->m_RefObjNum; |
546 } | 544 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
579 iterator end() { return m_IndirectObjs.end(); } | 577 iterator end() { return m_IndirectObjs.end(); } |
580 const_iterator end() const { return m_IndirectObjs.end(); } | 578 const_iterator end() const { return m_IndirectObjs.end(); } |
581 | 579 |
582 protected: | 580 protected: |
583 CPDF_Parser* m_pParser; | 581 CPDF_Parser* m_pParser; |
584 FX_DWORD m_LastObjNum; | 582 FX_DWORD m_LastObjNum; |
585 std::map<FX_DWORD, CPDF_Object*> m_IndirectObjs; | 583 std::map<FX_DWORD, CPDF_Object*> m_IndirectObjs; |
586 }; | 584 }; |
587 | 585 |
588 #endif // CORE_INCLUDE_FPDFAPI_FPDF_OBJECTS_H_ | 586 #endif // CORE_INCLUDE_FPDFAPI_FPDF_OBJECTS_H_ |
OLD | NEW |