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 #include "../../../include/fpdfapi/fpdf_parser.h" | 7 #include "../../../include/fpdfapi/fpdf_parser.h" |
8 #include "../../../include/fxcrt/fx_string.h" | 8 #include "../../../include/fxcrt/fx_string.h" |
9 | 9 |
10 //static | 10 // static |
11 int CPDF_Object::s_nCurRefDepth = 0; | 11 int CPDF_Object::s_nCurRefDepth = 0; |
12 | 12 |
13 void CPDF_Object::Release() | 13 void CPDF_Object::Release() { |
14 { | 14 if (m_ObjNum) { |
15 if (m_ObjNum) { | 15 return; |
16 return; | 16 } |
17 } | 17 Destroy(); |
18 Destroy(); | 18 } |
19 } | 19 void CPDF_Object::Destroy() { |
20 void CPDF_Object::Destroy() | 20 switch (m_Type) { |
21 { | 21 case PDFOBJ_STRING: |
22 switch (m_Type) { | 22 delete (CPDF_String*)this; |
23 case PDFOBJ_STRING: | 23 break; |
24 delete (CPDF_String*)this; | 24 case PDFOBJ_NAME: |
25 break; | 25 delete (CPDF_Name*)this; |
26 case PDFOBJ_NAME: | 26 break; |
27 delete (CPDF_Name*)this; | 27 case PDFOBJ_ARRAY: |
28 break; | 28 delete (CPDF_Array*)this; |
29 case PDFOBJ_ARRAY: | 29 break; |
30 delete (CPDF_Array*)this; | 30 case PDFOBJ_DICTIONARY: |
31 break; | 31 delete (CPDF_Dictionary*)this; |
32 case PDFOBJ_DICTIONARY: | 32 break; |
33 delete (CPDF_Dictionary*)this; | 33 case PDFOBJ_STREAM: |
34 break; | 34 delete (CPDF_Stream*)this; |
35 case PDFOBJ_STREAM: | 35 break; |
36 delete (CPDF_Stream*)this; | 36 default: |
37 break; | 37 delete this; |
38 default: | 38 } |
39 delete this; | 39 } |
40 } | 40 CFX_ByteString CPDF_Object::GetString() const { |
41 } | 41 switch (m_Type) { |
42 CFX_ByteString CPDF_Object::GetString() const | 42 case PDFOBJ_BOOLEAN: |
43 { | 43 return ((CPDF_Boolean*)this)->m_bValue ? "true" : "false"; |
44 switch (m_Type) { | 44 case PDFOBJ_NUMBER: |
45 case PDFOBJ_BOOLEAN: | 45 return ((CPDF_Number*)this)->GetString(); |
46 return ((CPDF_Boolean*)this)->m_bValue ? "true" : "false"; | 46 case PDFOBJ_STRING: |
47 case PDFOBJ_NUMBER: | 47 return ((CPDF_String*)this)->m_String; |
48 return ((CPDF_Number*)this)->GetString(); | 48 case PDFOBJ_NAME: |
49 case PDFOBJ_STRING: | 49 return ((CPDF_Name*)this)->m_Name; |
50 return ((CPDF_String*)this)->m_String; | 50 case PDFOBJ_REFERENCE: { |
51 case PDFOBJ_NAME: | 51 CPDF_Reference* pRef = (CPDF_Reference*)(void*)this; |
52 return ((CPDF_Name*)this)->m_Name; | 52 if (pRef->m_pObjList == NULL) { |
53 case PDFOBJ_REFERENCE: { | 53 break; |
54 CPDF_Reference* pRef = (CPDF_Reference*)(void*)this; | 54 } |
55 if (pRef->m_pObjList == NULL) { | 55 CPDF_Object* pObj = |
56 break; | 56 pRef->m_pObjList->GetIndirectObject(pRef->m_RefObjNum); |
57 } | 57 if (pObj == NULL) { |
58 CPDF_Object* pObj = pRef->m_pObjList->GetIndirectObject(pRef->m_
RefObjNum); | 58 return CFX_ByteString(); |
59 if (pObj == NULL) { | 59 } |
60 return CFX_ByteString(); | 60 return pObj->GetString(); |
61 } | 61 } |
62 return pObj->GetString(); | 62 } |
63 } | 63 return CFX_ByteString(); |
64 } | 64 } |
65 return CFX_ByteString(); | 65 CFX_ByteStringC CPDF_Object::GetConstString() const { |
66 } | 66 switch (m_Type) { |
67 CFX_ByteStringC CPDF_Object::GetConstString() const | 67 case PDFOBJ_STRING: |
68 { | 68 return CFX_ByteStringC((const uint8_t*)((CPDF_String*)this)->m_String, |
69 switch (m_Type) { | 69 ((CPDF_String*)this)->m_String.GetLength()); |
70 case PDFOBJ_STRING: | 70 case PDFOBJ_NAME: |
71 return CFX_ByteStringC((const uint8_t*)((CPDF_String*)this)->m_Strin
g, ((CPDF_String*)this)->m_String.GetLength()); | 71 return CFX_ByteStringC((const uint8_t*)((CPDF_Name*)this)->m_Name, |
72 case PDFOBJ_NAME: | 72 ((CPDF_Name*)this)->m_Name.GetLength()); |
73 return CFX_ByteStringC((const uint8_t*)((CPDF_Name*)this)->m_Name, (
(CPDF_Name*)this)->m_Name.GetLength()); | 73 case PDFOBJ_REFERENCE: { |
74 case PDFOBJ_REFERENCE: { | 74 CPDF_Reference* pRef = (CPDF_Reference*)(void*)this; |
75 CPDF_Reference* pRef = (CPDF_Reference*)(void*)this; | 75 if (pRef->m_pObjList == NULL) { |
76 if (pRef->m_pObjList == NULL) { | 76 break; |
77 break; | 77 } |
78 } | 78 CPDF_Object* pObj = |
79 CPDF_Object* pObj = pRef->m_pObjList->GetIndirectObject(pRef->m_
RefObjNum); | 79 pRef->m_pObjList->GetIndirectObject(pRef->m_RefObjNum); |
80 if (pObj == NULL) { | 80 if (pObj == NULL) { |
81 return CFX_ByteStringC(); | 81 return CFX_ByteStringC(); |
82 } | 82 } |
83 return pObj->GetConstString(); | 83 return pObj->GetConstString(); |
84 } | 84 } |
85 } | 85 } |
86 return CFX_ByteStringC(); | 86 return CFX_ByteStringC(); |
87 } | 87 } |
88 FX_FLOAT CPDF_Object::GetNumber() const | 88 FX_FLOAT CPDF_Object::GetNumber() const { |
89 { | 89 switch (m_Type) { |
90 switch (m_Type) { | 90 case PDFOBJ_NUMBER: |
91 case PDFOBJ_NUMBER: | 91 return ((CPDF_Number*)this)->GetNumber(); |
92 return ((CPDF_Number*)this)->GetNumber(); | 92 case PDFOBJ_REFERENCE: { |
93 case PDFOBJ_REFERENCE: { | 93 CPDF_Reference* pRef = (CPDF_Reference*)(void*)this; |
94 CPDF_Reference* pRef = (CPDF_Reference*)(void*)this; | 94 if (pRef->m_pObjList == NULL) { |
95 if (pRef->m_pObjList == NULL) { | 95 break; |
96 break; | 96 } |
97 } | 97 CPDF_Object* pObj = |
98 CPDF_Object* pObj = pRef->m_pObjList->GetIndirectObject(pRef->m_
RefObjNum); | 98 pRef->m_pObjList->GetIndirectObject(pRef->m_RefObjNum); |
99 if (pObj == NULL) { | 99 if (pObj == NULL) { |
100 return 0; | 100 return 0; |
101 } | 101 } |
102 return pObj->GetNumber(); | 102 return pObj->GetNumber(); |
103 } | 103 } |
104 } | 104 } |
| 105 return 0; |
| 106 } |
| 107 FX_FLOAT CPDF_Object::GetNumber16() const { |
| 108 return GetNumber(); |
| 109 } |
| 110 int CPDF_Object::GetInteger() const { |
| 111 CFX_AutoRestorer<int> restorer(&s_nCurRefDepth); |
| 112 if (++s_nCurRefDepth > OBJECT_REF_MAX_DEPTH) { |
105 return 0; | 113 return 0; |
106 } | 114 } |
107 FX_FLOAT CPDF_Object::GetNumber16() const | 115 switch (m_Type) { |
108 { | 116 case PDFOBJ_BOOLEAN: |
109 return GetNumber(); | 117 return ((CPDF_Boolean*)this)->m_bValue; |
110 } | 118 case PDFOBJ_NUMBER: |
111 int CPDF_Object::GetInteger() const | 119 return ((CPDF_Number*)this)->GetInteger(); |
112 { | 120 case PDFOBJ_REFERENCE: { |
113 CFX_AutoRestorer<int> restorer(&s_nCurRefDepth); | 121 CPDF_Reference* pRef = (CPDF_Reference*)(void*)this; |
114 if (++s_nCurRefDepth > OBJECT_REF_MAX_DEPTH) { | 122 PARSE_CONTEXT context; |
| 123 FXSYS_memset(&context, 0, sizeof(PARSE_CONTEXT)); |
| 124 if (pRef->m_pObjList == NULL) { |
115 return 0; | 125 return 0; |
116 } | 126 } |
117 switch (m_Type) { | 127 CPDF_Object* pObj = |
118 case PDFOBJ_BOOLEAN: | 128 pRef->m_pObjList->GetIndirectObject(pRef->m_RefObjNum, &context); |
119 return ((CPDF_Boolean*)this)->m_bValue; | 129 if (pObj == NULL) { |
120 case PDFOBJ_NUMBER: | 130 return 0; |
121 return ((CPDF_Number*)this)->GetInteger(); | 131 } |
122 case PDFOBJ_REFERENCE: { | 132 return pObj->GetInteger(); |
123 CPDF_Reference* pRef = (CPDF_Reference*)(void*)this; | 133 } |
124 PARSE_CONTEXT context; | 134 } |
125 FXSYS_memset(&context, 0, sizeof(PARSE_CONTEXT)); | 135 return 0; |
126 if (pRef->m_pObjList == NULL) { | 136 } |
127 return 0; | 137 CPDF_Dictionary* CPDF_Object::GetDict() const { |
128 } | 138 switch (m_Type) { |
129 CPDF_Object* pObj = pRef->m_pObjList->GetIndirectObject(pRef->m_
RefObjNum, &context); | 139 case PDFOBJ_DICTIONARY: |
130 if (pObj == NULL) { | 140 return (CPDF_Dictionary*)this; |
131 return 0; | 141 case PDFOBJ_STREAM: |
132 } | 142 return ((CPDF_Stream*)this)->GetDict(); |
133 return pObj->GetInteger(); | 143 case PDFOBJ_REFERENCE: { |
134 } | 144 CPDF_Reference* pRef = (CPDF_Reference*)this; |
135 } | 145 if (pRef->m_pObjList == NULL) { |
136 return 0; | 146 break; |
137 } | 147 } |
138 CPDF_Dictionary* CPDF_Object::GetDict() const | 148 CPDF_Object* pObj = |
139 { | 149 pRef->m_pObjList->GetIndirectObject(pRef->m_RefObjNum); |
140 switch (m_Type) { | 150 if (pObj == NULL) { |
141 case PDFOBJ_DICTIONARY: | 151 return NULL; |
142 return (CPDF_Dictionary*)this; | 152 } |
143 case PDFOBJ_STREAM: | 153 return pObj->GetDict(); |
144 return ((CPDF_Stream*)this)->GetDict(); | 154 } |
145 case PDFOBJ_REFERENCE: { | 155 } |
146 CPDF_Reference* pRef = (CPDF_Reference*)this; | 156 return NULL; |
147 if (pRef->m_pObjList == NULL) { | 157 } |
148 break; | 158 CPDF_Array* CPDF_Object::GetArray() const { |
149 } | 159 if (m_Type == PDFOBJ_ARRAY) |
150 CPDF_Object* pObj = pRef->m_pObjList->GetIndirectObject(pRef->m_
RefObjNum); | 160 return (CPDF_Array*)this; |
151 if (pObj == NULL) { | 161 |
152 return NULL; | 162 return NULL; |
153 } | 163 } |
154 return pObj->GetDict(); | 164 void CPDF_Object::SetString(const CFX_ByteString& str) { |
155 } | 165 ASSERT(this != NULL); |
156 } | 166 switch (m_Type) { |
| 167 case PDFOBJ_BOOLEAN: |
| 168 ((CPDF_Boolean*)this)->m_bValue = str == FX_BSTRC("true") ? 1 : 0; |
| 169 return; |
| 170 case PDFOBJ_NUMBER: |
| 171 ((CPDF_Number*)this)->SetString(str); |
| 172 return; |
| 173 case PDFOBJ_STRING: |
| 174 ((CPDF_String*)this)->m_String = str; |
| 175 return; |
| 176 case PDFOBJ_NAME: |
| 177 ((CPDF_Name*)this)->m_Name = str; |
| 178 return; |
| 179 } |
| 180 ASSERT(FALSE); |
| 181 } |
| 182 int CPDF_Object::GetDirectType() const { |
| 183 if (m_Type != PDFOBJ_REFERENCE) { |
| 184 return m_Type; |
| 185 } |
| 186 CPDF_Reference* pRef = (CPDF_Reference*)this; |
| 187 return pRef->m_pObjList->GetIndirectType(pRef->m_RefObjNum); |
| 188 } |
| 189 FX_BOOL CPDF_Object::IsIdentical(CPDF_Object* pOther) const { |
| 190 if (this == pOther) { |
| 191 return TRUE; |
| 192 } |
| 193 if (pOther == NULL) { |
| 194 return FALSE; |
| 195 } |
| 196 if (pOther->m_Type != m_Type) { |
| 197 if (m_Type == PDFOBJ_REFERENCE && GetDirect()) { |
| 198 return GetDirect()->IsIdentical(pOther); |
| 199 } |
| 200 if (pOther->m_Type == PDFOBJ_REFERENCE) { |
| 201 return IsIdentical(pOther->GetDirect()); |
| 202 } |
| 203 return FALSE; |
| 204 } |
| 205 switch (m_Type) { |
| 206 case PDFOBJ_BOOLEAN: |
| 207 return (((CPDF_Boolean*)this)->Identical((CPDF_Boolean*)pOther)); |
| 208 case PDFOBJ_NUMBER: |
| 209 return (((CPDF_Number*)this)->Identical((CPDF_Number*)pOther)); |
| 210 case PDFOBJ_STRING: |
| 211 return (((CPDF_String*)this)->Identical((CPDF_String*)pOther)); |
| 212 case PDFOBJ_NAME: |
| 213 return (((CPDF_Name*)this)->Identical((CPDF_Name*)pOther)); |
| 214 case PDFOBJ_ARRAY: |
| 215 return (((CPDF_Array*)this)->Identical((CPDF_Array*)pOther)); |
| 216 case PDFOBJ_DICTIONARY: |
| 217 return (((CPDF_Dictionary*)this)->Identical((CPDF_Dictionary*)pOther)); |
| 218 case PDFOBJ_NULL: |
| 219 return TRUE; |
| 220 case PDFOBJ_STREAM: |
| 221 return (((CPDF_Stream*)this)->Identical((CPDF_Stream*)pOther)); |
| 222 case PDFOBJ_REFERENCE: |
| 223 return (((CPDF_Reference*)this)->Identical((CPDF_Reference*)pOther)); |
| 224 } |
| 225 return FALSE; |
| 226 } |
| 227 CPDF_Object* CPDF_Object::GetDirect() const { |
| 228 if (m_Type != PDFOBJ_REFERENCE) { |
| 229 return (CPDF_Object*)this; |
| 230 } |
| 231 CPDF_Reference* pRef = (CPDF_Reference*)(void*)this; |
| 232 if (pRef->m_pObjList == NULL) { |
157 return NULL; | 233 return NULL; |
158 } | 234 } |
159 CPDF_Array* CPDF_Object::GetArray() const | 235 return pRef->m_pObjList->GetIndirectObject(pRef->m_RefObjNum); |
160 { | 236 } |
161 if (m_Type == PDFOBJ_ARRAY) | 237 CPDF_Object* CPDF_Object::Clone(FX_BOOL bDirect) const { |
162 return (CPDF_Array*)this; | 238 CFX_MapPtrToPtr visited; |
| 239 return CloneInternal(bDirect, &visited); |
| 240 } |
| 241 CPDF_Object* CPDF_Object::CloneInternal(FX_BOOL bDirect, |
| 242 CFX_MapPtrToPtr* visited) const { |
| 243 switch (m_Type) { |
| 244 case PDFOBJ_BOOLEAN: |
| 245 return new CPDF_Boolean(((CPDF_Boolean*)this)->m_bValue); |
| 246 case PDFOBJ_NUMBER: |
| 247 return new CPDF_Number(((CPDF_Number*)this)->m_bInteger, |
| 248 &((CPDF_Number*)this)->m_Integer); |
| 249 case PDFOBJ_STRING: |
| 250 return new CPDF_String(((CPDF_String*)this)->m_String, |
| 251 ((CPDF_String*)this)->IsHex()); |
| 252 case PDFOBJ_NAME: |
| 253 return new CPDF_Name(((CPDF_Name*)this)->m_Name); |
| 254 case PDFOBJ_ARRAY: { |
| 255 CPDF_Array* pCopy = new CPDF_Array(); |
| 256 CPDF_Array* pThis = (CPDF_Array*)this; |
| 257 int n = pThis->GetCount(); |
| 258 for (int i = 0; i < n; i++) { |
| 259 CPDF_Object* value = (CPDF_Object*)pThis->m_Objects.GetAt(i); |
| 260 pCopy->m_Objects.Add(value->CloneInternal(bDirect, visited)); |
| 261 } |
| 262 return pCopy; |
| 263 } |
| 264 case PDFOBJ_DICTIONARY: { |
| 265 CPDF_Dictionary* pCopy = new CPDF_Dictionary(); |
| 266 CPDF_Dictionary* pThis = (CPDF_Dictionary*)this; |
| 267 FX_POSITION pos = pThis->m_Map.GetStartPosition(); |
| 268 while (pos) { |
| 269 CFX_ByteString key; |
| 270 CPDF_Object* value; |
| 271 pThis->m_Map.GetNextAssoc(pos, key, (void*&)value); |
| 272 pCopy->m_Map.SetAt(key, value->CloneInternal(bDirect, visited)); |
| 273 } |
| 274 return pCopy; |
| 275 } |
| 276 case PDFOBJ_NULL: { |
| 277 return new CPDF_Null; |
| 278 } |
| 279 case PDFOBJ_STREAM: { |
| 280 CPDF_Stream* pThis = (CPDF_Stream*)this; |
| 281 CPDF_StreamAcc acc; |
| 282 acc.LoadAllData(pThis, TRUE); |
| 283 FX_DWORD streamSize = acc.GetSize(); |
| 284 CPDF_Dictionary* pDict = pThis->GetDict(); |
| 285 if (pDict) |
| 286 pDict = (CPDF_Dictionary*)((CPDF_Object*)pDict) |
| 287 ->CloneInternal(bDirect, visited); |
| 288 return new CPDF_Stream(acc.DetachData(), streamSize, pDict); |
| 289 } |
| 290 case PDFOBJ_REFERENCE: { |
| 291 CPDF_Reference* pRef = (CPDF_Reference*)this; |
| 292 FX_DWORD obj_num = pRef->m_RefObjNum; |
| 293 if (bDirect && !visited->GetValueAt((void*)(uintptr_t)obj_num)) { |
| 294 visited->SetAt((void*)(uintptr_t)obj_num, (void*)1); |
| 295 if (!pRef->GetDirect()) |
| 296 return nullptr; |
163 | 297 |
164 return NULL; | 298 return pRef->GetDirect()->CloneInternal(TRUE, visited); |
165 } | 299 } |
166 void CPDF_Object::SetString(const CFX_ByteString& str) | 300 return new CPDF_Reference(pRef->m_pObjList, obj_num); |
167 { | 301 } |
168 ASSERT(this != NULL); | 302 } |
169 switch (m_Type) { | 303 return NULL; |
170 case PDFOBJ_BOOLEAN: | 304 } |
171 ((CPDF_Boolean*)this)->m_bValue = str == FX_BSTRC("true") ? 1 : 0; | 305 CPDF_Object* CPDF_Object::CloneRef(CPDF_IndirectObjects* pDoc) const { |
172 return; | 306 if (m_ObjNum) { |
173 case PDFOBJ_NUMBER: | 307 return new CPDF_Reference(pDoc, m_ObjNum); |
174 ((CPDF_Number*)this)->SetString(str); | 308 } |
175 return; | 309 return Clone(); |
176 case PDFOBJ_STRING: | 310 } |
177 ((CPDF_String*)this)->m_String = str; | 311 CFX_WideString CPDF_Object::GetUnicodeText(CFX_CharMap* pCharMap) const { |
178 return; | 312 if (m_Type == PDFOBJ_STRING) { |
179 case PDFOBJ_NAME: | 313 return PDF_DecodeText(((CPDF_String*)this)->m_String, pCharMap); |
180 ((CPDF_Name*)this)->m_Name = str; | 314 } |
181 return; | 315 if (m_Type == PDFOBJ_STREAM) { |
182 } | 316 CPDF_StreamAcc stream; |
183 ASSERT(FALSE); | 317 stream.LoadAllData((CPDF_Stream*)this, FALSE); |
184 } | 318 CFX_WideString result = |
185 int CPDF_Object::GetDirectType() const | 319 PDF_DecodeText(stream.GetData(), stream.GetSize(), pCharMap); |
186 { | 320 return result; |
187 if (m_Type != PDFOBJ_REFERENCE) { | 321 } |
188 return m_Type; | 322 if (m_Type == PDFOBJ_NAME) { |
189 } | 323 return PDF_DecodeText(((CPDF_Name*)this)->m_Name, pCharMap); |
190 CPDF_Reference* pRef = (CPDF_Reference*)this; | 324 } |
191 return pRef->m_pObjList->GetIndirectType(pRef->m_RefObjNum); | 325 return CFX_WideString(); |
192 } | 326 } |
193 FX_BOOL CPDF_Object::IsIdentical(CPDF_Object* pOther) const | 327 void CPDF_Object::SetUnicodeText(const FX_WCHAR* pUnicodes, int len) { |
194 { | 328 if (m_Type == PDFOBJ_STRING) { |
195 if (this == pOther) { | 329 ((CPDF_String*)this)->m_String = PDF_EncodeText(pUnicodes, len); |
196 return TRUE; | 330 } else if (m_Type == PDFOBJ_STREAM) { |
197 } | 331 CFX_ByteString result = PDF_EncodeText(pUnicodes, len); |
198 if (pOther == NULL) { | 332 ((CPDF_Stream*)this) |
199 return FALSE; | 333 ->SetData((uint8_t*)result.c_str(), result.GetLength(), FALSE, FALSE); |
200 } | 334 } |
201 if (pOther->m_Type != m_Type) { | |
202 if (m_Type == PDFOBJ_REFERENCE && GetDirect()) { | |
203 return GetDirect()->IsIdentical(pOther); | |
204 } | |
205 if (pOther->m_Type == PDFOBJ_REFERENCE) { | |
206 return IsIdentical(pOther->GetDirect()); | |
207 } | |
208 return FALSE; | |
209 } | |
210 switch (m_Type) { | |
211 case PDFOBJ_BOOLEAN: | |
212 return (((CPDF_Boolean*)this)->Identical((CPDF_Boolean*)pOther)); | |
213 case PDFOBJ_NUMBER: | |
214 return (((CPDF_Number*)this)->Identical((CPDF_Number*)pOther)); | |
215 case PDFOBJ_STRING: | |
216 return (((CPDF_String*)this)->Identical((CPDF_String*)pOther)); | |
217 case PDFOBJ_NAME: | |
218 return (((CPDF_Name*)this)->Identical((CPDF_Name*)pOther)); | |
219 case PDFOBJ_ARRAY: | |
220 return (((CPDF_Array*)this)->Identical((CPDF_Array*)pOther)); | |
221 case PDFOBJ_DICTIONARY: | |
222 return (((CPDF_Dictionary*)this)->Identical((CPDF_Dictionary*)pOther
)); | |
223 case PDFOBJ_NULL: | |
224 return TRUE; | |
225 case PDFOBJ_STREAM: | |
226 return (((CPDF_Stream*)this)->Identical((CPDF_Stream*)pOther)); | |
227 case PDFOBJ_REFERENCE: | |
228 return (((CPDF_Reference*)this)->Identical((CPDF_Reference*)pOther))
; | |
229 } | |
230 return FALSE; | |
231 } | |
232 CPDF_Object* CPDF_Object::GetDirect() const | |
233 { | |
234 if (m_Type != PDFOBJ_REFERENCE) { | |
235 return (CPDF_Object*)this; | |
236 } | |
237 CPDF_Reference* pRef = (CPDF_Reference*)(void*)this; | |
238 if (pRef->m_pObjList == NULL) { | |
239 return NULL; | |
240 } | |
241 return pRef->m_pObjList->GetIndirectObject(pRef->m_RefObjNum); | |
242 } | |
243 CPDF_Object* CPDF_Object::Clone(FX_BOOL bDirect) const | |
244 { | |
245 CFX_MapPtrToPtr visited; | |
246 return CloneInternal(bDirect, &visited); | |
247 } | |
248 CPDF_Object* CPDF_Object::CloneInternal(FX_BOOL bDirect, CFX_MapPtrToPtr* visite
d) const | |
249 { | |
250 switch (m_Type) { | |
251 case PDFOBJ_BOOLEAN: | |
252 return new CPDF_Boolean(((CPDF_Boolean*)this)->m_bValue); | |
253 case PDFOBJ_NUMBER: | |
254 return new CPDF_Number(((CPDF_Number*)this)->m_bInteger, &((CPDF_Num
ber*)this)->m_Integer); | |
255 case PDFOBJ_STRING: | |
256 return new CPDF_String(((CPDF_String*)this)->m_String, ((CPDF_String
*)this)->IsHex()); | |
257 case PDFOBJ_NAME: | |
258 return new CPDF_Name(((CPDF_Name*)this)->m_Name); | |
259 case PDFOBJ_ARRAY: { | |
260 CPDF_Array* pCopy = new CPDF_Array(); | |
261 CPDF_Array* pThis = (CPDF_Array*)this; | |
262 int n = pThis->GetCount(); | |
263 for (int i = 0; i < n; i ++) { | |
264 CPDF_Object* value = (CPDF_Object*)pThis->m_Objects.GetAt(i)
; | |
265 pCopy->m_Objects.Add(value->CloneInternal(bDirect, visited))
; | |
266 } | |
267 return pCopy; | |
268 } | |
269 case PDFOBJ_DICTIONARY: { | |
270 CPDF_Dictionary* pCopy = new CPDF_Dictionary(); | |
271 CPDF_Dictionary* pThis = (CPDF_Dictionary*)this; | |
272 FX_POSITION pos = pThis->m_Map.GetStartPosition(); | |
273 while (pos) { | |
274 CFX_ByteString key; | |
275 CPDF_Object* value; | |
276 pThis->m_Map.GetNextAssoc(pos, key, (void*&)value); | |
277 pCopy->m_Map.SetAt(key, value->CloneInternal(bDirect, visite
d)); | |
278 } | |
279 return pCopy; | |
280 } | |
281 case PDFOBJ_NULL: { | |
282 return new CPDF_Null; | |
283 } | |
284 case PDFOBJ_STREAM: { | |
285 CPDF_Stream* pThis = (CPDF_Stream*)this; | |
286 CPDF_StreamAcc acc; | |
287 acc.LoadAllData(pThis, TRUE); | |
288 FX_DWORD streamSize = acc.GetSize(); | |
289 CPDF_Dictionary* pDict = pThis->GetDict(); | |
290 if (pDict) | |
291 pDict = (CPDF_Dictionary*)((CPDF_Object*)pDict)->CloneIntern
al(bDirect, visited); | |
292 return new CPDF_Stream(acc.DetachData(), streamSize, pDict); | |
293 } | |
294 case PDFOBJ_REFERENCE: { | |
295 CPDF_Reference* pRef = (CPDF_Reference*)this; | |
296 FX_DWORD obj_num = pRef->m_RefObjNum; | |
297 if (bDirect && !visited->GetValueAt((void*)(uintptr_t)obj_num))
{ | |
298 visited->SetAt((void*)(uintptr_t)obj_num, (void*)1); | |
299 if (!pRef->GetDirect()) | |
300 return nullptr; | |
301 | |
302 return pRef->GetDirect()->CloneInternal(TRUE, visited); | |
303 } | |
304 return new CPDF_Reference(pRef->m_pObjList, obj_num); | |
305 } | |
306 } | |
307 return NULL; | |
308 } | |
309 CPDF_Object* CPDF_Object::CloneRef(CPDF_IndirectObjects* pDoc) const | |
310 { | |
311 if (m_ObjNum) { | |
312 return new CPDF_Reference(pDoc, m_ObjNum); | |
313 } | |
314 return Clone(); | |
315 } | |
316 CFX_WideString CPDF_Object::GetUnicodeText(CFX_CharMap* pCharMap) const | |
317 { | |
318 if (m_Type == PDFOBJ_STRING) { | |
319 return PDF_DecodeText(((CPDF_String*)this)->m_String, pCharMap); | |
320 } | |
321 if (m_Type == PDFOBJ_STREAM) { | |
322 CPDF_StreamAcc stream; | |
323 stream.LoadAllData((CPDF_Stream*)this, FALSE); | |
324 CFX_WideString result = PDF_DecodeText(stream.GetData(), stream.GetSize(
), pCharMap); | |
325 return result; | |
326 } | |
327 if (m_Type == PDFOBJ_NAME) { | |
328 return PDF_DecodeText(((CPDF_Name*)this)->m_Name, pCharMap); | |
329 } | |
330 return CFX_WideString(); | |
331 } | |
332 void CPDF_Object::SetUnicodeText(const FX_WCHAR* pUnicodes, int len) | |
333 { | |
334 if (m_Type == PDFOBJ_STRING) { | |
335 ((CPDF_String*)this)->m_String = PDF_EncodeText(pUnicodes, len); | |
336 } else if (m_Type == PDFOBJ_STREAM) { | |
337 CFX_ByteString result = PDF_EncodeText(pUnicodes, len); | |
338 ((CPDF_Stream*)this)->SetData((uint8_t*)result.c_str(), result.GetLength
(), FALSE, FALSE); | |
339 } | |
340 } | 335 } |
341 | 336 |
342 CPDF_Number::CPDF_Number(int value) | 337 CPDF_Number::CPDF_Number(int value) |
343 : CPDF_Object(PDFOBJ_NUMBER), m_bInteger(TRUE), m_Integer(value) { | 338 : CPDF_Object(PDFOBJ_NUMBER), m_bInteger(TRUE), m_Integer(value) {} |
344 } | |
345 | 339 |
346 CPDF_Number::CPDF_Number(FX_FLOAT value) | 340 CPDF_Number::CPDF_Number(FX_FLOAT value) |
347 : CPDF_Object(PDFOBJ_NUMBER), m_bInteger(FALSE), m_Float(value) { | 341 : CPDF_Object(PDFOBJ_NUMBER), m_bInteger(FALSE), m_Float(value) {} |
348 } | |
349 | 342 |
350 CPDF_Number::CPDF_Number(FX_BOOL bInteger, void* pData) | 343 CPDF_Number::CPDF_Number(FX_BOOL bInteger, void* pData) |
351 : CPDF_Object(PDFOBJ_NUMBER), m_bInteger(bInteger), m_Integer(*(int*)pData)
{ | 344 : CPDF_Object(PDFOBJ_NUMBER), |
352 } | 345 m_bInteger(bInteger), |
| 346 m_Integer(*(int*)pData) {} |
353 | 347 |
354 CPDF_Number::CPDF_Number(const CFX_ByteStringC& str) : CPDF_Object(PDFOBJ_NUMBER
) { | 348 CPDF_Number::CPDF_Number(const CFX_ByteStringC& str) |
355 FX_atonum(str, m_bInteger, &m_Integer); | 349 : CPDF_Object(PDFOBJ_NUMBER) { |
| 350 FX_atonum(str, m_bInteger, &m_Integer); |
356 } | 351 } |
357 | 352 |
358 void CPDF_Number::SetString(const CFX_ByteStringC& str) | 353 void CPDF_Number::SetString(const CFX_ByteStringC& str) { |
359 { | 354 FX_atonum(str, m_bInteger, &m_Integer); |
360 FX_atonum(str, m_bInteger, &m_Integer); | 355 } |
361 } | 356 FX_BOOL CPDF_Number::Identical(CPDF_Number* pOther) const { |
362 FX_BOOL CPDF_Number::Identical(CPDF_Number* pOther) const | 357 return m_bInteger == pOther->m_bInteger && m_Integer == pOther->m_Integer; |
363 { | 358 } |
364 return m_bInteger == pOther->m_bInteger && m_Integer == pOther->m_Integer; | 359 CFX_ByteString CPDF_Number::GetString() const { |
365 } | 360 return m_bInteger ? CFX_ByteString::FormatInteger(m_Integer, FXFORMAT_SIGNED) |
366 CFX_ByteString CPDF_Number::GetString() const | 361 : CFX_ByteString::FormatFloat(m_Float); |
367 { | 362 } |
368 return m_bInteger ? CFX_ByteString::FormatInteger(m_Integer, FXFORMAT_SIGNED
) : CFX_ByteString::FormatFloat(m_Float); | 363 void CPDF_Number::SetNumber(FX_FLOAT value) { |
369 } | 364 m_bInteger = FALSE; |
370 void CPDF_Number::SetNumber(FX_FLOAT value) | 365 m_Float = value; |
371 { | 366 } |
372 m_bInteger = FALSE; | 367 CPDF_String::CPDF_String(const CFX_WideString& str) |
373 m_Float = value; | 368 : CPDF_Object(PDFOBJ_STRING), m_bHex(FALSE) { |
374 } | 369 m_String = PDF_EncodeText(str); |
375 CPDF_String::CPDF_String(const CFX_WideString& str) : CPDF_Object(PDFOBJ_STRING)
, m_bHex(FALSE) { | 370 } |
376 m_String = PDF_EncodeText(str); | 371 CPDF_Array::~CPDF_Array() { |
377 } | 372 int size = m_Objects.GetSize(); |
378 CPDF_Array::~CPDF_Array() | 373 CPDF_Object** pList = (CPDF_Object**)m_Objects.GetData(); |
379 { | 374 for (int i = 0; i < size; i++) { |
380 int size = m_Objects.GetSize(); | 375 if (pList[i]) |
381 CPDF_Object** pList = (CPDF_Object**)m_Objects.GetData(); | 376 pList[i]->Release(); |
382 for (int i = 0; i < size; i ++) { | 377 } |
383 if (pList[i]) | 378 } |
384 pList[i]->Release(); | 379 CFX_FloatRect CPDF_Array::GetRect() { |
385 } | 380 CFX_FloatRect rect; |
386 } | 381 if (m_Type != PDFOBJ_ARRAY || m_Objects.GetSize() != 4) { |
387 CFX_FloatRect CPDF_Array::GetRect() | |
388 { | |
389 CFX_FloatRect rect; | |
390 if (m_Type != PDFOBJ_ARRAY || m_Objects.GetSize() != 4) { | |
391 return rect; | |
392 } | |
393 rect.left = GetNumber(0); | |
394 rect.bottom = GetNumber(1); | |
395 rect.right = GetNumber(2); | |
396 rect.top = GetNumber(3); | |
397 return rect; | 382 return rect; |
398 } | 383 } |
399 CFX_AffineMatrix CPDF_Array::GetMatrix() | 384 rect.left = GetNumber(0); |
400 { | 385 rect.bottom = GetNumber(1); |
401 CFX_AffineMatrix matrix; | 386 rect.right = GetNumber(2); |
402 if (m_Type != PDFOBJ_ARRAY || m_Objects.GetSize() != 6) { | 387 rect.top = GetNumber(3); |
403 return matrix; | 388 return rect; |
404 } | 389 } |
405 matrix.Set(GetNumber(0), GetNumber(1), GetNumber(2), GetNumber(3), GetNumber
(4), GetNumber(5)); | 390 CFX_AffineMatrix CPDF_Array::GetMatrix() { |
| 391 CFX_AffineMatrix matrix; |
| 392 if (m_Type != PDFOBJ_ARRAY || m_Objects.GetSize() != 6) { |
406 return matrix; | 393 return matrix; |
407 } | 394 } |
408 CPDF_Object* CPDF_Array::GetElement(FX_DWORD i) const | 395 matrix.Set(GetNumber(0), GetNumber(1), GetNumber(2), GetNumber(3), |
409 { | 396 GetNumber(4), GetNumber(5)); |
410 if (i >= (FX_DWORD)m_Objects.GetSize()) { | 397 return matrix; |
411 return NULL; | 398 } |
412 } | 399 CPDF_Object* CPDF_Array::GetElement(FX_DWORD i) const { |
413 return (CPDF_Object*)m_Objects.GetAt(i); | 400 if (i >= (FX_DWORD)m_Objects.GetSize()) { |
414 } | 401 return NULL; |
415 CPDF_Object* CPDF_Array::GetElementValue(FX_DWORD i) const | 402 } |
416 { | 403 return (CPDF_Object*)m_Objects.GetAt(i); |
417 if (i >= (FX_DWORD)m_Objects.GetSize()) { | 404 } |
418 return NULL; | 405 CPDF_Object* CPDF_Array::GetElementValue(FX_DWORD i) const { |
419 } | 406 if (i >= (FX_DWORD)m_Objects.GetSize()) { |
420 return ((CPDF_Object*)m_Objects.GetAt(i))->GetDirect(); | 407 return NULL; |
421 } | 408 } |
422 CFX_ByteString CPDF_Array::GetString(FX_DWORD i) const | 409 return ((CPDF_Object*)m_Objects.GetAt(i))->GetDirect(); |
423 { | 410 } |
424 if (i < (FX_DWORD)m_Objects.GetSize()) { | 411 CFX_ByteString CPDF_Array::GetString(FX_DWORD i) const { |
425 CPDF_Object* p = (CPDF_Object*)m_Objects.GetAt(i); | 412 if (i < (FX_DWORD)m_Objects.GetSize()) { |
426 return p->GetString(); | |
427 } | |
428 return CFX_ByteString(); | |
429 } | |
430 CFX_ByteStringC CPDF_Array::GetConstString(FX_DWORD i) const | |
431 { | |
432 if (i < (FX_DWORD)m_Objects.GetSize()) { | |
433 CPDF_Object* p = (CPDF_Object*)m_Objects.GetAt(i); | |
434 return p->GetConstString(); | |
435 } | |
436 return CFX_ByteStringC(); | |
437 } | |
438 int CPDF_Array::GetInteger(FX_DWORD i) const | |
439 { | |
440 if (i >= (FX_DWORD)m_Objects.GetSize()) { | |
441 return 0; | |
442 } | |
443 CPDF_Object* p = (CPDF_Object*)m_Objects.GetAt(i); | 413 CPDF_Object* p = (CPDF_Object*)m_Objects.GetAt(i); |
| 414 return p->GetString(); |
| 415 } |
| 416 return CFX_ByteString(); |
| 417 } |
| 418 CFX_ByteStringC CPDF_Array::GetConstString(FX_DWORD i) const { |
| 419 if (i < (FX_DWORD)m_Objects.GetSize()) { |
| 420 CPDF_Object* p = (CPDF_Object*)m_Objects.GetAt(i); |
| 421 return p->GetConstString(); |
| 422 } |
| 423 return CFX_ByteStringC(); |
| 424 } |
| 425 int CPDF_Array::GetInteger(FX_DWORD i) const { |
| 426 if (i >= (FX_DWORD)m_Objects.GetSize()) { |
| 427 return 0; |
| 428 } |
| 429 CPDF_Object* p = (CPDF_Object*)m_Objects.GetAt(i); |
| 430 return p->GetInteger(); |
| 431 } |
| 432 FX_FLOAT CPDF_Array::GetNumber(FX_DWORD i) const { |
| 433 if (i >= (FX_DWORD)m_Objects.GetSize()) { |
| 434 return 0; |
| 435 } |
| 436 CPDF_Object* p = (CPDF_Object*)m_Objects.GetAt(i); |
| 437 return p->GetNumber(); |
| 438 } |
| 439 CPDF_Dictionary* CPDF_Array::GetDict(FX_DWORD i) const { |
| 440 CPDF_Object* p = GetElementValue(i); |
| 441 if (!p) { |
| 442 return NULL; |
| 443 } |
| 444 if (p->GetType() == PDFOBJ_DICTIONARY) { |
| 445 return (CPDF_Dictionary*)p; |
| 446 } |
| 447 if (p->GetType() == PDFOBJ_STREAM) { |
| 448 return ((CPDF_Stream*)p)->GetDict(); |
| 449 } |
| 450 return NULL; |
| 451 } |
| 452 CPDF_Stream* CPDF_Array::GetStream(FX_DWORD i) const { |
| 453 CPDF_Object* p = GetElementValue(i); |
| 454 if (p == NULL || p->GetType() != PDFOBJ_STREAM) { |
| 455 return NULL; |
| 456 } |
| 457 return (CPDF_Stream*)p; |
| 458 } |
| 459 CPDF_Array* CPDF_Array::GetArray(FX_DWORD i) const { |
| 460 CPDF_Object* p = GetElementValue(i); |
| 461 if (p == NULL || p->GetType() != PDFOBJ_ARRAY) { |
| 462 return NULL; |
| 463 } |
| 464 return (CPDF_Array*)p; |
| 465 } |
| 466 void CPDF_Array::RemoveAt(FX_DWORD i) { |
| 467 ASSERT(m_Type == PDFOBJ_ARRAY); |
| 468 if (i >= (FX_DWORD)m_Objects.GetSize()) { |
| 469 return; |
| 470 } |
| 471 CPDF_Object* p = (CPDF_Object*)m_Objects.GetAt(i); |
| 472 if (p) |
| 473 p->Release(); |
| 474 m_Objects.RemoveAt(i); |
| 475 } |
| 476 void CPDF_Array::SetAt(FX_DWORD i, |
| 477 CPDF_Object* pObj, |
| 478 CPDF_IndirectObjects* pObjs) { |
| 479 ASSERT(m_Type == PDFOBJ_ARRAY); |
| 480 ASSERT(i < (FX_DWORD)m_Objects.GetSize()); |
| 481 if (i >= (FX_DWORD)m_Objects.GetSize()) { |
| 482 return; |
| 483 } |
| 484 CPDF_Object* pOld = (CPDF_Object*)m_Objects.GetAt(i); |
| 485 if (pOld) |
| 486 pOld->Release(); |
| 487 if (pObj->GetObjNum()) { |
| 488 ASSERT(pObjs != NULL); |
| 489 pObj = new CPDF_Reference(pObjs, pObj->GetObjNum()); |
| 490 } |
| 491 m_Objects.SetAt(i, pObj); |
| 492 } |
| 493 void CPDF_Array::InsertAt(FX_DWORD index, |
| 494 CPDF_Object* pObj, |
| 495 CPDF_IndirectObjects* pObjs) { |
| 496 ASSERT(pObj != NULL); |
| 497 if (pObj->GetObjNum()) { |
| 498 ASSERT(pObjs != NULL); |
| 499 pObj = new CPDF_Reference(pObjs, pObj->GetObjNum()); |
| 500 } |
| 501 m_Objects.InsertAt(index, pObj); |
| 502 } |
| 503 void CPDF_Array::Add(CPDF_Object* pObj, CPDF_IndirectObjects* pObjs) { |
| 504 ASSERT(pObj != NULL); |
| 505 if (pObj->GetObjNum()) { |
| 506 ASSERT(pObjs != NULL); |
| 507 pObj = new CPDF_Reference(pObjs, pObj->GetObjNum()); |
| 508 } |
| 509 m_Objects.Add(pObj); |
| 510 } |
| 511 void CPDF_Array::AddName(const CFX_ByteString& str) { |
| 512 ASSERT(m_Type == PDFOBJ_ARRAY); |
| 513 Add(new CPDF_Name(str)); |
| 514 } |
| 515 void CPDF_Array::AddString(const CFX_ByteString& str) { |
| 516 ASSERT(m_Type == PDFOBJ_ARRAY); |
| 517 Add(new CPDF_String(str)); |
| 518 } |
| 519 void CPDF_Array::AddInteger(int i) { |
| 520 ASSERT(m_Type == PDFOBJ_ARRAY); |
| 521 Add(new CPDF_Number(i)); |
| 522 } |
| 523 void CPDF_Array::AddNumber(FX_FLOAT f) { |
| 524 ASSERT(m_Type == PDFOBJ_ARRAY); |
| 525 CPDF_Number* pNumber = new CPDF_Number; |
| 526 pNumber->SetNumber(f); |
| 527 Add(pNumber); |
| 528 } |
| 529 void CPDF_Array::AddReference(CPDF_IndirectObjects* pDoc, FX_DWORD objnum) { |
| 530 ASSERT(m_Type == PDFOBJ_ARRAY); |
| 531 Add(new CPDF_Reference(pDoc, objnum)); |
| 532 } |
| 533 FX_BOOL CPDF_Array::Identical(CPDF_Array* pOther) const { |
| 534 if (m_Objects.GetSize() != pOther->m_Objects.GetSize()) { |
| 535 return FALSE; |
| 536 } |
| 537 for (int i = 0; i < m_Objects.GetSize(); i++) |
| 538 if (!((CPDF_Object*)m_Objects[i]) |
| 539 ->IsIdentical((CPDF_Object*)pOther->m_Objects[i])) { |
| 540 return FALSE; |
| 541 } |
| 542 return TRUE; |
| 543 } |
| 544 CPDF_Dictionary::~CPDF_Dictionary() { |
| 545 FX_POSITION pos = m_Map.GetStartPosition(); |
| 546 while (pos) { |
| 547 void* value = m_Map.GetNextValue(pos); |
| 548 if (value) |
| 549 ((CPDF_Object*)value)->Release(); |
| 550 } |
| 551 } |
| 552 FX_POSITION CPDF_Dictionary::GetStartPos() const { |
| 553 return m_Map.GetStartPosition(); |
| 554 } |
| 555 CPDF_Object* CPDF_Dictionary::GetNextElement(FX_POSITION& pos, |
| 556 CFX_ByteString& key) const { |
| 557 if (pos == NULL) { |
| 558 return NULL; |
| 559 } |
| 560 CPDF_Object* p; |
| 561 m_Map.GetNextAssoc(pos, key, (void*&)p); |
| 562 return p; |
| 563 } |
| 564 CPDF_Object* CPDF_Dictionary::GetElement(const CFX_ByteStringC& key) const { |
| 565 CPDF_Object* p = NULL; |
| 566 m_Map.Lookup(key, (void*&)p); |
| 567 return p; |
| 568 } |
| 569 CPDF_Object* CPDF_Dictionary::GetElementValue( |
| 570 const CFX_ByteStringC& key) const { |
| 571 CPDF_Object* p = NULL; |
| 572 m_Map.Lookup(key, (void*&)p); |
| 573 return p ? p->GetDirect() : NULL; |
| 574 } |
| 575 CFX_ByteString CPDF_Dictionary::GetString(const CFX_ByteStringC& key) const { |
| 576 CPDF_Object* p = NULL; |
| 577 m_Map.Lookup(key, (void*&)p); |
| 578 if (p) { |
| 579 return p->GetString(); |
| 580 } |
| 581 return CFX_ByteString(); |
| 582 } |
| 583 CFX_ByteStringC CPDF_Dictionary::GetConstString( |
| 584 const CFX_ByteStringC& key) const { |
| 585 CPDF_Object* p = NULL; |
| 586 m_Map.Lookup(key, (void*&)p); |
| 587 if (p) { |
| 588 return p->GetConstString(); |
| 589 } |
| 590 return CFX_ByteStringC(); |
| 591 } |
| 592 CFX_WideString CPDF_Dictionary::GetUnicodeText(const CFX_ByteStringC& key, |
| 593 CFX_CharMap* pCharMap) const { |
| 594 CPDF_Object* p = NULL; |
| 595 m_Map.Lookup(key, (void*&)p); |
| 596 if (p) { |
| 597 if (p->GetType() == PDFOBJ_REFERENCE) { |
| 598 p = ((CPDF_Reference*)p)->GetDirect(); |
| 599 if (p) { |
| 600 return p->GetUnicodeText(pCharMap); |
| 601 } |
| 602 } else { |
| 603 return p->GetUnicodeText(pCharMap); |
| 604 } |
| 605 } |
| 606 return CFX_WideString(); |
| 607 } |
| 608 CFX_ByteString CPDF_Dictionary::GetString(const CFX_ByteStringC& key, |
| 609 const CFX_ByteStringC& def) const { |
| 610 CPDF_Object* p = NULL; |
| 611 m_Map.Lookup(key, (void*&)p); |
| 612 if (p) { |
| 613 return p->GetString(); |
| 614 } |
| 615 return CFX_ByteString(def); |
| 616 } |
| 617 CFX_ByteStringC CPDF_Dictionary::GetConstString( |
| 618 const CFX_ByteStringC& key, |
| 619 const CFX_ByteStringC& def) const { |
| 620 CPDF_Object* p = NULL; |
| 621 m_Map.Lookup(key, (void*&)p); |
| 622 if (p) { |
| 623 return p->GetConstString(); |
| 624 } |
| 625 return CFX_ByteStringC(def); |
| 626 } |
| 627 int CPDF_Dictionary::GetInteger(const CFX_ByteStringC& key) const { |
| 628 CPDF_Object* p = NULL; |
| 629 m_Map.Lookup(key, (void*&)p); |
| 630 if (p) { |
444 return p->GetInteger(); | 631 return p->GetInteger(); |
445 } | 632 } |
446 FX_FLOAT CPDF_Array::GetNumber(FX_DWORD i) const | 633 return 0; |
447 { | 634 } |
448 if (i >= (FX_DWORD)m_Objects.GetSize()) { | 635 int CPDF_Dictionary::GetInteger(const CFX_ByteStringC& key, int def) const { |
449 return 0; | 636 CPDF_Object* p = NULL; |
450 } | 637 m_Map.Lookup(key, (void*&)p); |
451 CPDF_Object* p = (CPDF_Object*)m_Objects.GetAt(i); | 638 if (p) { |
| 639 return p->GetInteger(); |
| 640 } |
| 641 return def; |
| 642 } |
| 643 FX_FLOAT CPDF_Dictionary::GetNumber(const CFX_ByteStringC& key) const { |
| 644 CPDF_Object* p = NULL; |
| 645 m_Map.Lookup(key, (void*&)p); |
| 646 if (p) { |
452 return p->GetNumber(); | 647 return p->GetNumber(); |
453 } | 648 } |
454 CPDF_Dictionary* CPDF_Array::GetDict(FX_DWORD i) const | 649 return 0; |
455 { | 650 } |
456 CPDF_Object* p = GetElementValue(i); | 651 FX_BOOL CPDF_Dictionary::GetBoolean(const CFX_ByteStringC& key, |
457 if (!p) { | 652 FX_BOOL bDefault) const { |
458 return NULL; | 653 CPDF_Object* p = NULL; |
459 } | 654 m_Map.Lookup(key, (void*&)p); |
460 if (p->GetType() == PDFOBJ_DICTIONARY) { | 655 if (p && p->GetType() == PDFOBJ_BOOLEAN) { |
461 return (CPDF_Dictionary*)p; | 656 return p->GetInteger(); |
462 } | 657 } |
463 if (p->GetType() == PDFOBJ_STREAM) { | 658 return bDefault; |
464 return ((CPDF_Stream*)p)->GetDict(); | 659 } |
465 } | 660 CPDF_Dictionary* CPDF_Dictionary::GetDict(const CFX_ByteStringC& key) const { |
| 661 CPDF_Object* p = GetElementValue(key); |
| 662 if (!p) { |
| 663 return nullptr; |
| 664 } |
| 665 if (p->GetType() == PDFOBJ_DICTIONARY) { |
| 666 return (CPDF_Dictionary*)p; |
| 667 } |
| 668 if (p->GetType() == PDFOBJ_STREAM) { |
| 669 return ((CPDF_Stream*)p)->GetDict(); |
| 670 } |
| 671 return nullptr; |
| 672 } |
| 673 CPDF_Array* CPDF_Dictionary::GetArray(const CFX_ByteStringC& key) const { |
| 674 CPDF_Object* p = GetElementValue(key); |
| 675 if (p == NULL || p->GetType() != PDFOBJ_ARRAY) { |
466 return NULL; | 676 return NULL; |
467 } | 677 } |
468 CPDF_Stream* CPDF_Array::GetStream(FX_DWORD i) const | 678 return (CPDF_Array*)p; |
469 { | 679 } |
470 CPDF_Object* p = GetElementValue(i); | 680 CPDF_Stream* CPDF_Dictionary::GetStream(const CFX_ByteStringC& key) const { |
471 if (p == NULL || p->GetType() != PDFOBJ_STREAM) { | 681 CPDF_Object* p = GetElementValue(key); |
472 return NULL; | 682 if (p == NULL || p->GetType() != PDFOBJ_STREAM) { |
473 } | 683 return NULL; |
474 return (CPDF_Stream*)p; | 684 } |
475 } | 685 return (CPDF_Stream*)p; |
476 CPDF_Array* CPDF_Array::GetArray(FX_DWORD i) const | 686 } |
477 { | 687 CFX_FloatRect CPDF_Dictionary::GetRect(const CFX_ByteStringC& key) const { |
478 CPDF_Object* p = GetElementValue(i); | 688 CFX_FloatRect rect; |
479 if (p == NULL || p->GetType() != PDFOBJ_ARRAY) { | 689 CPDF_Array* pArray = GetArray(key); |
480 return NULL; | 690 if (pArray) { |
481 } | 691 rect = pArray->GetRect(); |
482 return (CPDF_Array*)p; | 692 } |
483 } | 693 return rect; |
484 void CPDF_Array::RemoveAt(FX_DWORD i) | 694 } |
485 { | 695 CFX_AffineMatrix CPDF_Dictionary::GetMatrix(const CFX_ByteStringC& key) const { |
486 ASSERT(m_Type == PDFOBJ_ARRAY); | 696 CFX_AffineMatrix matrix; |
487 if (i >= (FX_DWORD)m_Objects.GetSize()) { | 697 CPDF_Array* pArray = GetArray(key); |
488 return; | 698 if (pArray) { |
489 } | 699 matrix = pArray->GetMatrix(); |
490 CPDF_Object* p = (CPDF_Object*)m_Objects.GetAt(i); | 700 } |
491 if (p) | 701 return matrix; |
492 p->Release(); | 702 } |
493 m_Objects.RemoveAt(i); | 703 FX_BOOL CPDF_Dictionary::KeyExist(const CFX_ByteStringC& key) const { |
494 } | 704 void* value; |
495 void CPDF_Array::SetAt(FX_DWORD i, CPDF_Object* pObj, CPDF_IndirectObjects* pObj
s) | 705 return m_Map.Lookup(key, value); |
496 { | 706 } |
497 ASSERT(m_Type == PDFOBJ_ARRAY); | 707 void CPDF_Dictionary::SetAt(const CFX_ByteStringC& key, |
498 ASSERT(i < (FX_DWORD)m_Objects.GetSize()); | 708 CPDF_Object* pObj, |
499 if (i >= (FX_DWORD)m_Objects.GetSize()) { | 709 CPDF_IndirectObjects* pObjs) { |
500 return; | 710 ASSERT(m_Type == PDFOBJ_DICTIONARY); |
501 } | 711 CPDF_Object* p = NULL; |
502 CPDF_Object* pOld = (CPDF_Object*)m_Objects.GetAt(i); | 712 m_Map.Lookup(key, (void*&)p); |
503 if (pOld) | 713 if (p == pObj) { |
504 pOld->Release(); | 714 return; |
| 715 } |
| 716 if (p) |
| 717 p->Release(); |
| 718 if (pObj) { |
505 if (pObj->GetObjNum()) { | 719 if (pObj->GetObjNum()) { |
506 ASSERT(pObjs != NULL); | 720 ASSERT(pObjs != NULL); |
507 pObj = new CPDF_Reference(pObjs, pObj->GetObjNum()); | 721 pObj = new CPDF_Reference(pObjs, pObj->GetObjNum()); |
508 } | 722 } |
509 m_Objects.SetAt(i, pObj); | 723 m_Map.SetAt(key, pObj); |
510 } | 724 } else { |
511 void CPDF_Array::InsertAt(FX_DWORD index, CPDF_Object* pObj, CPDF_IndirectObject
s* pObjs) | 725 m_Map.RemoveKey(key); |
512 { | 726 } |
513 ASSERT(pObj != NULL); | 727 } |
514 if (pObj->GetObjNum()) { | 728 void CPDF_Dictionary::AddValue(const CFX_ByteStringC& key, CPDF_Object* pObj) { |
515 ASSERT(pObjs != NULL); | 729 ASSERT(m_Type == PDFOBJ_DICTIONARY); |
516 pObj = new CPDF_Reference(pObjs, pObj->GetObjNum()); | 730 m_Map.AddValue(key, pObj); |
517 } | 731 } |
518 m_Objects.InsertAt(index, pObj); | 732 void CPDF_Dictionary::RemoveAt(const CFX_ByteStringC& key) { |
519 } | 733 ASSERT(m_Type == PDFOBJ_DICTIONARY); |
520 void CPDF_Array::Add(CPDF_Object* pObj, CPDF_IndirectObjects* pObjs) | 734 CPDF_Object* p = NULL; |
521 { | 735 m_Map.Lookup(key, (void*&)p); |
522 ASSERT(pObj != NULL); | 736 if (p == NULL) { |
523 if (pObj->GetObjNum()) { | 737 return; |
524 ASSERT(pObjs != NULL); | 738 } |
525 pObj = new CPDF_Reference(pObjs, pObj->GetObjNum()); | 739 p->Release(); |
526 } | 740 m_Map.RemoveKey(key); |
527 m_Objects.Add(pObj); | 741 } |
528 } | 742 void CPDF_Dictionary::ReplaceKey(const CFX_ByteStringC& oldkey, |
529 void CPDF_Array::AddName(const CFX_ByteString& str) | 743 const CFX_ByteStringC& newkey) { |
530 { | 744 ASSERT(m_Type == PDFOBJ_DICTIONARY); |
531 ASSERT(m_Type == PDFOBJ_ARRAY); | 745 CPDF_Object* p = NULL; |
532 Add(new CPDF_Name(str)); | 746 m_Map.Lookup(oldkey, (void*&)p); |
533 } | 747 if (p == NULL) { |
534 void CPDF_Array::AddString(const CFX_ByteString& str) | 748 return; |
535 { | 749 } |
536 ASSERT(m_Type == PDFOBJ_ARRAY); | 750 m_Map.RemoveKey(oldkey); |
537 Add(new CPDF_String(str)); | 751 m_Map.SetAt(newkey, p); |
538 } | 752 } |
539 void CPDF_Array::AddInteger(int i) | 753 FX_BOOL CPDF_Dictionary::Identical(CPDF_Dictionary* pOther) const { |
540 { | 754 if (pOther == NULL) { |
541 ASSERT(m_Type == PDFOBJ_ARRAY); | 755 return FALSE; |
542 Add(new CPDF_Number(i)); | 756 } |
543 } | 757 if (m_Map.GetCount() != pOther->m_Map.GetCount()) { |
544 void CPDF_Array::AddNumber(FX_FLOAT f) | 758 return FALSE; |
545 { | 759 } |
546 ASSERT(m_Type == PDFOBJ_ARRAY); | 760 FX_POSITION pos = m_Map.GetStartPosition(); |
547 CPDF_Number* pNumber = new CPDF_Number; | 761 while (pos) { |
548 pNumber->SetNumber(f); | 762 CFX_ByteString key; |
549 Add(pNumber); | |
550 } | |
551 void CPDF_Array::AddReference(CPDF_IndirectObjects* pDoc, FX_DWORD objnum) | |
552 { | |
553 ASSERT(m_Type == PDFOBJ_ARRAY); | |
554 Add(new CPDF_Reference(pDoc, objnum)); | |
555 } | |
556 FX_BOOL CPDF_Array::Identical(CPDF_Array* pOther) const | |
557 { | |
558 if (m_Objects.GetSize() != pOther->m_Objects.GetSize()) { | |
559 return FALSE; | |
560 } | |
561 for (int i = 0; i < m_Objects.GetSize(); i ++) | |
562 if (!((CPDF_Object*)m_Objects[i])->IsIdentical((CPDF_Object*)pOther->m_O
bjects[i])) { | |
563 return FALSE; | |
564 } | |
565 return TRUE; | |
566 } | |
567 CPDF_Dictionary::~CPDF_Dictionary() | |
568 { | |
569 FX_POSITION pos = m_Map.GetStartPosition(); | |
570 while (pos) { | |
571 void* value = m_Map.GetNextValue(pos); | |
572 if (value) | |
573 ((CPDF_Object*)value)->Release(); | |
574 } | |
575 } | |
576 FX_POSITION CPDF_Dictionary::GetStartPos() const | |
577 { | |
578 return m_Map.GetStartPosition(); | |
579 } | |
580 CPDF_Object* CPDF_Dictionary::GetNextElement(FX_POSITION& pos, CFX_ByteString& k
ey) const | |
581 { | |
582 if (pos == NULL) { | |
583 return NULL; | |
584 } | |
585 CPDF_Object* p; | |
586 m_Map.GetNextAssoc(pos, key, (void*&)p); | |
587 return p; | |
588 } | |
589 CPDF_Object* CPDF_Dictionary::GetElement(const CFX_ByteStringC& key) const | |
590 { | |
591 CPDF_Object* p = NULL; | |
592 m_Map.Lookup(key, (void*&)p); | |
593 return p; | |
594 } | |
595 CPDF_Object* CPDF_Dictionary::GetElementValue(const CFX_ByteStringC& key) const | |
596 { | |
597 CPDF_Object* p = NULL; | |
598 m_Map.Lookup(key, (void*&)p); | |
599 return p ? p->GetDirect() : NULL; | |
600 } | |
601 CFX_ByteString CPDF_Dictionary::GetString(const CFX_ByteStringC& key) const | |
602 { | |
603 CPDF_Object* p = NULL; | |
604 m_Map.Lookup(key, (void*&)p); | |
605 if (p) { | |
606 return p->GetString(); | |
607 } | |
608 return CFX_ByteString(); | |
609 } | |
610 CFX_ByteStringC CPDF_Dictionary::GetConstString(const CFX_ByteStringC& key) cons
t | |
611 { | |
612 CPDF_Object* p = NULL; | |
613 m_Map.Lookup(key, (void*&)p); | |
614 if (p) { | |
615 return p->GetConstString(); | |
616 } | |
617 return CFX_ByteStringC(); | |
618 } | |
619 CFX_WideString CPDF_Dictionary::GetUnicodeText(const CFX_ByteStringC& key, CFX_C
harMap* pCharMap) const | |
620 { | |
621 CPDF_Object* p = NULL; | |
622 m_Map.Lookup(key, (void*&)p); | |
623 if (p) { | |
624 if(p->GetType() == PDFOBJ_REFERENCE) { | |
625 p = ((CPDF_Reference*)p)->GetDirect(); | |
626 if (p) { | |
627 return p->GetUnicodeText(pCharMap); | |
628 } | |
629 } else { | |
630 return p->GetUnicodeText(pCharMap); | |
631 } | |
632 } | |
633 return CFX_WideString(); | |
634 } | |
635 CFX_ByteString CPDF_Dictionary::GetString(const CFX_ByteStringC& key, const CFX_
ByteStringC& def) const | |
636 { | |
637 CPDF_Object* p = NULL; | |
638 m_Map.Lookup(key, (void*&)p); | |
639 if (p) { | |
640 return p->GetString(); | |
641 } | |
642 return CFX_ByteString(def); | |
643 } | |
644 CFX_ByteStringC CPDF_Dictionary::GetConstString(const CFX_ByteStringC& key, cons
t CFX_ByteStringC& def) const | |
645 { | |
646 CPDF_Object* p = NULL; | |
647 m_Map.Lookup(key, (void*&)p); | |
648 if (p) { | |
649 return p->GetConstString(); | |
650 } | |
651 return CFX_ByteStringC(def); | |
652 } | |
653 int CPDF_Dictionary::GetInteger(const CFX_ByteStringC& key) const | |
654 { | |
655 CPDF_Object* p = NULL; | |
656 m_Map.Lookup(key, (void*&)p); | |
657 if (p) { | |
658 return p->GetInteger(); | |
659 } | |
660 return 0; | |
661 } | |
662 int CPDF_Dictionary::GetInteger(const CFX_ByteStringC& key, int def) const | |
663 { | |
664 CPDF_Object* p = NULL; | |
665 m_Map.Lookup(key, (void*&)p); | |
666 if (p) { | |
667 return p->GetInteger(); | |
668 } | |
669 return def; | |
670 } | |
671 FX_FLOAT CPDF_Dictionary::GetNumber(const CFX_ByteStringC& key) const | |
672 { | |
673 CPDF_Object* p = NULL; | |
674 m_Map.Lookup(key, (void*&)p); | |
675 if (p) { | |
676 return p->GetNumber(); | |
677 } | |
678 return 0; | |
679 } | |
680 FX_BOOL CPDF_Dictionary::GetBoolean(const CFX_ByteStringC& key, FX_BOOL bDefault
) const | |
681 { | |
682 CPDF_Object* p = NULL; | |
683 m_Map.Lookup(key, (void*&)p); | |
684 if (p && p->GetType() == PDFOBJ_BOOLEAN) { | |
685 return p->GetInteger(); | |
686 } | |
687 return bDefault; | |
688 } | |
689 CPDF_Dictionary* CPDF_Dictionary::GetDict(const CFX_ByteStringC& key) const | |
690 { | |
691 CPDF_Object* p = GetElementValue(key); | |
692 if (!p) { | |
693 return nullptr; | |
694 } | |
695 if (p->GetType() == PDFOBJ_DICTIONARY) { | |
696 return (CPDF_Dictionary*)p; | |
697 } | |
698 if (p->GetType() == PDFOBJ_STREAM) { | |
699 return ((CPDF_Stream*)p)->GetDict(); | |
700 } | |
701 return nullptr; | |
702 } | |
703 CPDF_Array* CPDF_Dictionary::GetArray(const CFX_ByteStringC& key) const | |
704 { | |
705 CPDF_Object* p = GetElementValue(key); | |
706 if (p == NULL || p->GetType() != PDFOBJ_ARRAY) { | |
707 return NULL; | |
708 } | |
709 return (CPDF_Array*)p; | |
710 } | |
711 CPDF_Stream* CPDF_Dictionary::GetStream(const CFX_ByteStringC& key) const | |
712 { | |
713 CPDF_Object* p = GetElementValue(key); | |
714 if (p == NULL || p->GetType() != PDFOBJ_STREAM) { | |
715 return NULL; | |
716 } | |
717 return (CPDF_Stream*)p; | |
718 } | |
719 CFX_FloatRect CPDF_Dictionary::GetRect(const CFX_ByteStringC& key) const | |
720 { | |
721 CFX_FloatRect rect; | |
722 CPDF_Array* pArray = GetArray(key); | |
723 if (pArray) { | |
724 rect = pArray->GetRect(); | |
725 } | |
726 return rect; | |
727 } | |
728 CFX_AffineMatrix CPDF_Dictionary::GetMatrix(const CFX_ByteStringC& key) const | |
729 { | |
730 CFX_AffineMatrix matrix; | |
731 CPDF_Array* pArray = GetArray(key); | |
732 if (pArray) { | |
733 matrix = pArray->GetMatrix(); | |
734 } | |
735 return matrix; | |
736 } | |
737 FX_BOOL CPDF_Dictionary::KeyExist(const CFX_ByteStringC& key) const | |
738 { | |
739 void* value; | 763 void* value; |
740 return m_Map.Lookup(key, value); | 764 m_Map.GetNextAssoc(pos, key, value); |
741 } | 765 if (!value) |
742 void CPDF_Dictionary::SetAt(const CFX_ByteStringC& key, CPDF_Object* pObj, CPDF_
IndirectObjects* pObjs) | 766 return FALSE; |
743 { | 767 if (!((CPDF_Object*)value)->IsIdentical(pOther->GetElement(key))) { |
744 ASSERT(m_Type == PDFOBJ_DICTIONARY); | 768 return FALSE; |
745 CPDF_Object* p = NULL; | 769 } |
746 m_Map.Lookup(key, (void*&)p); | 770 } |
747 if (p == pObj) { | 771 return TRUE; |
748 return; | 772 } |
749 } | 773 void CPDF_Dictionary::SetAtInteger(const CFX_ByteStringC& key, int i) { |
750 if (p) | 774 SetAt(key, new CPDF_Number(i)); |
751 p->Release(); | 775 } |
752 if (pObj) { | 776 void CPDF_Dictionary::SetAtName(const CFX_ByteStringC& key, |
753 if (pObj->GetObjNum()) { | 777 const CFX_ByteString& name) { |
754 ASSERT(pObjs != NULL); | 778 SetAt(key, new CPDF_Name(name)); |
755 pObj = new CPDF_Reference(pObjs, pObj->GetObjNum()); | 779 } |
756 } | 780 void CPDF_Dictionary::SetAtString(const CFX_ByteStringC& key, |
757 m_Map.SetAt(key, pObj); | 781 const CFX_ByteString& str) { |
758 } else { | 782 SetAt(key, new CPDF_String(str)); |
759 m_Map.RemoveKey(key); | 783 } |
760 } | 784 void CPDF_Dictionary::SetAtReference(const CFX_ByteStringC& key, |
761 } | 785 CPDF_IndirectObjects* pDoc, |
762 void CPDF_Dictionary::AddValue(const CFX_ByteStringC& key, CPDF_Object* pObj) | 786 FX_DWORD objnum) { |
763 { | 787 SetAt(key, new CPDF_Reference(pDoc, objnum)); |
764 ASSERT(m_Type == PDFOBJ_DICTIONARY); | 788 } |
765 m_Map.AddValue(key, pObj); | 789 void CPDF_Dictionary::AddReference(const CFX_ByteStringC& key, |
766 } | 790 CPDF_IndirectObjects* pDoc, |
767 void CPDF_Dictionary::RemoveAt(const CFX_ByteStringC& key) | 791 FX_DWORD objnum) { |
768 { | 792 AddValue(key, new CPDF_Reference(pDoc, objnum)); |
769 ASSERT(m_Type == PDFOBJ_DICTIONARY); | 793 } |
770 CPDF_Object* p = NULL; | 794 void CPDF_Dictionary::SetAtNumber(const CFX_ByteStringC& key, FX_FLOAT f) { |
771 m_Map.Lookup(key, (void*&)p); | 795 CPDF_Number* pNumber = new CPDF_Number; |
772 if (p == NULL) { | 796 pNumber->SetNumber(f); |
773 return; | 797 SetAt(key, pNumber); |
774 } | 798 } |
775 p->Release(); | 799 void CPDF_Dictionary::SetAtBoolean(const CFX_ByteStringC& key, FX_BOOL bValue) { |
776 m_Map.RemoveKey(key); | 800 SetAt(key, new CPDF_Boolean(bValue)); |
777 } | 801 } |
778 void CPDF_Dictionary::ReplaceKey(const CFX_ByteStringC& oldkey, const CFX_ByteSt
ringC& newkey) | 802 void CPDF_Dictionary::SetAtRect(const CFX_ByteStringC& key, |
779 { | 803 const CFX_FloatRect& rect) { |
780 ASSERT(m_Type == PDFOBJ_DICTIONARY); | 804 CPDF_Array* pArray = new CPDF_Array; |
781 CPDF_Object* p = NULL; | 805 pArray->AddNumber(rect.left); |
782 m_Map.Lookup(oldkey, (void*&)p); | 806 pArray->AddNumber(rect.bottom); |
783 if (p == NULL) { | 807 pArray->AddNumber(rect.right); |
784 return; | 808 pArray->AddNumber(rect.top); |
785 } | 809 SetAt(key, pArray); |
786 m_Map.RemoveKey(oldkey); | 810 } |
787 m_Map.SetAt(newkey, p); | 811 void CPDF_Dictionary::SetAtMatrix(const CFX_ByteStringC& key, |
788 } | 812 const CFX_AffineMatrix& matrix) { |
789 FX_BOOL CPDF_Dictionary::Identical(CPDF_Dictionary* pOther) const | 813 CPDF_Array* pArray = new CPDF_Array; |
790 { | 814 pArray->AddNumber16(matrix.a); |
791 if (pOther == NULL) { | 815 pArray->AddNumber16(matrix.b); |
792 return FALSE; | 816 pArray->AddNumber16(matrix.c); |
793 } | 817 pArray->AddNumber16(matrix.d); |
794 if (m_Map.GetCount() != pOther->m_Map.GetCount()) { | 818 pArray->AddNumber(matrix.e); |
795 return FALSE; | 819 pArray->AddNumber(matrix.f); |
796 } | 820 SetAt(key, pArray); |
797 FX_POSITION pos = m_Map.GetStartPosition(); | |
798 while (pos) { | |
799 CFX_ByteString key; | |
800 void* value; | |
801 m_Map.GetNextAssoc(pos, key, value); | |
802 if (!value) | |
803 return FALSE; | |
804 if (!((CPDF_Object*)value)->IsIdentical(pOther->GetElement(key))) { | |
805 return FALSE; | |
806 } | |
807 } | |
808 return TRUE; | |
809 } | |
810 void CPDF_Dictionary::SetAtInteger(const CFX_ByteStringC& key, int i) | |
811 { | |
812 SetAt(key, new CPDF_Number(i)); | |
813 } | |
814 void CPDF_Dictionary::SetAtName(const CFX_ByteStringC& key, const CFX_ByteString
& name) | |
815 { | |
816 SetAt(key, new CPDF_Name(name)); | |
817 } | |
818 void CPDF_Dictionary::SetAtString(const CFX_ByteStringC& key, const CFX_ByteStri
ng& str) | |
819 { | |
820 SetAt(key, new CPDF_String(str)); | |
821 } | |
822 void CPDF_Dictionary::SetAtReference(const CFX_ByteStringC& key, CPDF_IndirectOb
jects* pDoc, FX_DWORD objnum) | |
823 { | |
824 SetAt(key, new CPDF_Reference(pDoc, objnum)); | |
825 } | |
826 void CPDF_Dictionary::AddReference(const CFX_ByteStringC& key, CPDF_IndirectObje
cts* pDoc, FX_DWORD objnum) | |
827 { | |
828 AddValue(key, new CPDF_Reference(pDoc, objnum)); | |
829 } | |
830 void CPDF_Dictionary::SetAtNumber(const CFX_ByteStringC& key, FX_FLOAT f) | |
831 { | |
832 CPDF_Number* pNumber = new CPDF_Number; | |
833 pNumber->SetNumber(f); | |
834 SetAt(key, pNumber); | |
835 } | |
836 void CPDF_Dictionary::SetAtBoolean(const CFX_ByteStringC& key, FX_BOOL bValue) | |
837 { | |
838 SetAt(key, new CPDF_Boolean(bValue)); | |
839 } | |
840 void CPDF_Dictionary::SetAtRect(const CFX_ByteStringC& key, const CFX_FloatRect&
rect) | |
841 { | |
842 CPDF_Array* pArray = new CPDF_Array; | |
843 pArray->AddNumber(rect.left); | |
844 pArray->AddNumber(rect.bottom); | |
845 pArray->AddNumber(rect.right); | |
846 pArray->AddNumber(rect.top); | |
847 SetAt(key, pArray); | |
848 } | |
849 void CPDF_Dictionary::SetAtMatrix(const CFX_ByteStringC& key, const CFX_AffineMa
trix& matrix) | |
850 { | |
851 CPDF_Array* pArray = new CPDF_Array; | |
852 pArray->AddNumber16(matrix.a); | |
853 pArray->AddNumber16(matrix.b); | |
854 pArray->AddNumber16(matrix.c); | |
855 pArray->AddNumber16(matrix.d); | |
856 pArray->AddNumber(matrix.e); | |
857 pArray->AddNumber(matrix.f); | |
858 SetAt(key, pArray); | |
859 } | 821 } |
860 CPDF_Stream::CPDF_Stream(uint8_t* pData, FX_DWORD size, CPDF_Dictionary* pDict) | 822 CPDF_Stream::CPDF_Stream(uint8_t* pData, FX_DWORD size, CPDF_Dictionary* pDict) |
861 : CPDF_Object(PDFOBJ_STREAM) { | 823 : CPDF_Object(PDFOBJ_STREAM) { |
| 824 m_pDict = pDict; |
| 825 m_dwSize = size; |
| 826 m_GenNum = (FX_DWORD)-1; |
| 827 m_pDataBuf = pData; |
| 828 m_pCryptoHandler = NULL; |
| 829 } |
| 830 CPDF_Stream::~CPDF_Stream() { |
| 831 if (m_GenNum == (FX_DWORD)-1 && m_pDataBuf != NULL) { |
| 832 FX_Free(m_pDataBuf); |
| 833 } |
| 834 if (m_pDict) { |
| 835 m_pDict->Release(); |
| 836 } |
| 837 } |
| 838 void CPDF_Stream::InitStream(CPDF_Dictionary* pDict) { |
| 839 if (pDict) { |
| 840 if (m_pDict) { |
| 841 m_pDict->Release(); |
| 842 } |
862 m_pDict = pDict; | 843 m_pDict = pDict; |
863 m_dwSize = size; | 844 } |
864 m_GenNum = (FX_DWORD) - 1; | 845 if (m_GenNum == (FX_DWORD)-1) { |
865 m_pDataBuf = pData; | 846 if (m_pDataBuf) { |
| 847 FX_Free(m_pDataBuf); |
| 848 } |
| 849 } |
| 850 m_GenNum = 0; |
| 851 m_pFile = NULL; |
| 852 m_pCryptoHandler = NULL; |
| 853 m_FileOffset = 0; |
| 854 } |
| 855 void CPDF_Stream::InitStream(uint8_t* pData, |
| 856 FX_DWORD size, |
| 857 CPDF_Dictionary* pDict) { |
| 858 InitStream(pDict); |
| 859 m_GenNum = (FX_DWORD)-1; |
| 860 m_pDataBuf = FX_Alloc(uint8_t, size); |
| 861 if (pData) { |
| 862 FXSYS_memcpy(m_pDataBuf, pData, size); |
| 863 } |
| 864 m_dwSize = size; |
| 865 if (m_pDict) { |
| 866 m_pDict->SetAtInteger(FX_BSTRC("Length"), size); |
| 867 } |
| 868 } |
| 869 void CPDF_Stream::SetData(const uint8_t* pData, |
| 870 FX_DWORD size, |
| 871 FX_BOOL bCompressed, |
| 872 FX_BOOL bKeepBuf) { |
| 873 if (m_GenNum == (FX_DWORD)-1) { |
| 874 if (m_pDataBuf) { |
| 875 FX_Free(m_pDataBuf); |
| 876 } |
| 877 } else { |
| 878 m_GenNum = (FX_DWORD)-1; |
866 m_pCryptoHandler = NULL; | 879 m_pCryptoHandler = NULL; |
867 } | 880 } |
868 CPDF_Stream::~CPDF_Stream() | 881 if (bKeepBuf) { |
869 { | 882 m_pDataBuf = (uint8_t*)pData; |
870 if (m_GenNum == (FX_DWORD) - 1 && m_pDataBuf != NULL) { | 883 } else { |
871 FX_Free(m_pDataBuf); | |
872 } | |
873 if (m_pDict) { | |
874 m_pDict->Release(); | |
875 } | |
876 } | |
877 void CPDF_Stream::InitStream(CPDF_Dictionary* pDict) | |
878 { | |
879 if (pDict) { | |
880 if (m_pDict) { | |
881 m_pDict->Release(); | |
882 } | |
883 m_pDict = pDict; | |
884 } | |
885 if (m_GenNum == (FX_DWORD) - 1) { | |
886 if (m_pDataBuf) { | |
887 FX_Free(m_pDataBuf); | |
888 } | |
889 } | |
890 m_GenNum = 0; | |
891 m_pFile = NULL; | |
892 m_pCryptoHandler = NULL; | |
893 m_FileOffset = 0; | |
894 } | |
895 void CPDF_Stream::InitStream(uint8_t* pData, FX_DWORD size, CPDF_Dictionary* pDi
ct) | |
896 { | |
897 InitStream(pDict); | |
898 m_GenNum = (FX_DWORD) - 1; | |
899 m_pDataBuf = FX_Alloc(uint8_t, size); | 884 m_pDataBuf = FX_Alloc(uint8_t, size); |
900 if (pData) { | 885 if (pData) { |
901 FXSYS_memcpy(m_pDataBuf, pData, size); | 886 FXSYS_memcpy(m_pDataBuf, pData, size); |
902 } | 887 } |
903 m_dwSize = size; | 888 } |
904 if (m_pDict) { | 889 m_dwSize = size; |
905 m_pDict->SetAtInteger(FX_BSTRC("Length"), size); | 890 if (m_pDict == NULL) { |
906 } | 891 m_pDict = new CPDF_Dictionary; |
907 } | 892 } |
908 void CPDF_Stream::SetData(const uint8_t* pData, FX_DWORD size, FX_BOOL bCompress
ed, FX_BOOL bKeepBuf) | 893 m_pDict->SetAtInteger(FX_BSTRC("Length"), size); |
909 { | 894 if (!bCompressed) { |
910 if (m_GenNum == (FX_DWORD) - 1) { | 895 m_pDict->RemoveAt(FX_BSTRC("Filter")); |
911 if (m_pDataBuf) { | 896 m_pDict->RemoveAt(FX_BSTRC("DecodeParms")); |
912 FX_Free(m_pDataBuf); | 897 } |
913 } | 898 } |
914 } else { | 899 FX_BOOL CPDF_Stream::ReadRawData(FX_FILESIZE offset, |
915 m_GenNum = (FX_DWORD) - 1; | 900 uint8_t* buf, |
916 m_pCryptoHandler = NULL; | 901 FX_DWORD size) const { |
917 } | 902 if ((m_GenNum != (FX_DWORD)-1) && m_pFile) { |
918 if (bKeepBuf) { | 903 return m_pFile->ReadBlock(buf, m_FileOffset + offset, size); |
919 m_pDataBuf = (uint8_t*)pData; | 904 } |
920 } else { | 905 if (m_pDataBuf) { |
921 m_pDataBuf = FX_Alloc(uint8_t, size); | 906 FXSYS_memcpy(buf, m_pDataBuf + offset, size); |
922 if (pData) { | 907 } |
923 FXSYS_memcpy(m_pDataBuf, pData, size); | 908 return TRUE; |
924 } | 909 } |
925 } | 910 void CPDF_Stream::InitStream(IFX_FileRead* pFile, CPDF_Dictionary* pDict) { |
926 m_dwSize = size; | 911 InitStream(pDict); |
927 if (m_pDict == NULL) { | 912 m_pFile = pFile; |
928 m_pDict = new CPDF_Dictionary; | 913 m_dwSize = (FX_DWORD)pFile->GetSize(); |
929 } | 914 if (m_pDict) { |
930 m_pDict->SetAtInteger(FX_BSTRC("Length"), size); | 915 m_pDict->SetAtInteger(FX_BSTRC("Length"), m_dwSize); |
931 if (!bCompressed) { | 916 } |
932 m_pDict->RemoveAt(FX_BSTRC("Filter")); | 917 } |
933 m_pDict->RemoveAt(FX_BSTRC("DecodeParms")); | 918 FX_BOOL CPDF_Stream::Identical(CPDF_Stream* pOther) const { |
934 } | 919 if (!m_pDict) |
935 } | 920 return pOther->m_pDict ? FALSE : TRUE; |
936 FX_BOOL CPDF_Stream::ReadRawData(FX_FILESIZE offset, uint8_t* buf, FX_DWORD size
) const | 921 |
937 { | 922 if (!m_pDict->Identical(pOther->m_pDict)) { |
938 if ((m_GenNum != (FX_DWORD) - 1) && m_pFile) { | 923 return FALSE; |
939 return m_pFile->ReadBlock(buf, m_FileOffset + offset, size); | 924 } |
940 } | 925 if (m_dwSize != pOther->m_dwSize) { |
941 if (m_pDataBuf) { | 926 return FALSE; |
942 FXSYS_memcpy(buf, m_pDataBuf + offset, size); | 927 } |
| 928 if (m_GenNum != (FX_DWORD)-1 && pOther->m_GenNum != (FX_DWORD)-1) { |
| 929 if (m_pFile == pOther->m_pFile && m_pFile == NULL) { |
| 930 return TRUE; |
| 931 } |
| 932 if (!m_pFile || !pOther->m_pFile) { |
| 933 return FALSE; |
| 934 } |
| 935 uint8_t srcBuf[1024]; |
| 936 uint8_t destBuf[1024]; |
| 937 FX_DWORD size = m_dwSize; |
| 938 FX_DWORD srcOffset = m_FileOffset; |
| 939 FX_DWORD destOffset = pOther->m_FileOffset; |
| 940 if (m_pFile == pOther->m_pFile && srcOffset == destOffset) { |
| 941 return TRUE; |
| 942 } |
| 943 while (size > 0) { |
| 944 FX_DWORD actualSize = size > 1024 ? 1024 : size; |
| 945 m_pFile->ReadBlock(srcBuf, srcOffset, actualSize); |
| 946 pOther->m_pFile->ReadBlock(destBuf, destOffset, actualSize); |
| 947 if (FXSYS_memcmp(srcBuf, destBuf, actualSize) != 0) { |
| 948 return FALSE; |
| 949 } |
| 950 size -= actualSize; |
| 951 srcOffset += actualSize; |
| 952 destOffset += actualSize; |
943 } | 953 } |
944 return TRUE; | 954 return TRUE; |
945 } | 955 } |
946 void CPDF_Stream::InitStream(IFX_FileRead *pFile, CPDF_Dictionary* pDict) | 956 if (m_GenNum != (FX_DWORD)-1 || pOther->m_GenNum != (FX_DWORD)-1) { |
947 { | 957 IFX_FileRead* pFile = NULL; |
948 InitStream(pDict); | 958 uint8_t* pBuf = NULL; |
949 m_pFile = pFile; | 959 FX_DWORD offset = 0; |
950 m_dwSize = (FX_DWORD)pFile->GetSize(); | 960 if (pOther->m_GenNum != (FX_DWORD)-1) { |
951 if (m_pDict) { | 961 pFile = pOther->m_pFile; |
952 m_pDict->SetAtInteger(FX_BSTRC("Length"), m_dwSize); | 962 pBuf = m_pDataBuf; |
953 } | 963 offset = pOther->m_FileOffset; |
954 } | 964 } else if (m_GenNum != (FX_DWORD)-1) { |
955 FX_BOOL CPDF_Stream::Identical(CPDF_Stream* pOther) const | 965 pFile = m_pFile; |
956 { | 966 pBuf = pOther->m_pDataBuf; |
957 if (!m_pDict) | 967 offset = m_FileOffset; |
958 return pOther->m_pDict ? FALSE : TRUE; | 968 } |
959 | 969 if (NULL == pBuf) { |
960 if (!m_pDict->Identical(pOther->m_pDict)) { | 970 return FALSE; |
| 971 } |
| 972 uint8_t srcBuf[1024]; |
| 973 FX_DWORD size = m_dwSize; |
| 974 while (size > 0) { |
| 975 FX_DWORD actualSize = std::min(size, 1024U); |
| 976 pFile->ReadBlock(srcBuf, offset, actualSize); |
| 977 if (FXSYS_memcmp(srcBuf, pBuf, actualSize) != 0) { |
961 return FALSE; | 978 return FALSE; |
962 } | 979 } |
963 if (m_dwSize != pOther->m_dwSize) { | 980 pBuf += actualSize; |
964 return FALSE; | 981 size -= actualSize; |
965 } | 982 offset += actualSize; |
966 if (m_GenNum != (FX_DWORD) - 1 && pOther->m_GenNum != (FX_DWORD) - 1) { | 983 } |
967 if (m_pFile == pOther->m_pFile && m_pFile == NULL) { | 984 return TRUE; |
968 return TRUE; | 985 } |
969 } | 986 return FXSYS_memcmp(m_pDataBuf, pOther->m_pDataBuf, m_dwSize) == 0; |
970 if (!m_pFile || !pOther->m_pFile) { | 987 } |
971 return FALSE; | 988 CPDF_Stream* CPDF_Stream::Clone(FX_BOOL bDirect, |
972 } | 989 FPDF_LPFCloneStreamCallback lpfCallback, |
973 uint8_t srcBuf[1024]; | 990 void* pUserData) const { |
974 uint8_t destBuf[1024]; | 991 CPDF_Dictionary* pCloneDict = (CPDF_Dictionary*)m_pDict->Clone(bDirect); |
975 FX_DWORD size = m_dwSize; | 992 IFX_FileStream* pFS = NULL; |
976 FX_DWORD srcOffset = m_FileOffset; | 993 if (lpfCallback) { |
977 FX_DWORD destOffset = pOther->m_FileOffset; | 994 pFS = lpfCallback((CPDF_Stream*)this, pUserData); |
978 if (m_pFile == pOther->m_pFile && srcOffset == destOffset) { | 995 } |
979 return TRUE; | 996 if (!pFS) { |
980 } | 997 CPDF_StreamAcc acc; |
981 while (size > 0) { | 998 acc.LoadAllData(this, TRUE); |
982 FX_DWORD actualSize = size > 1024 ? 1024 : size; | 999 FX_DWORD streamSize = acc.GetSize(); |
983 m_pFile->ReadBlock(srcBuf, srcOffset, actualSize); | 1000 return new CPDF_Stream(acc.DetachData(), streamSize, pCloneDict); |
984 pOther->m_pFile->ReadBlock(destBuf, destOffset, actualSize); | 1001 } |
985 if (FXSYS_memcmp(srcBuf, destBuf, actualSize) != 0) { | 1002 CPDF_Stream* pObj = new CPDF_Stream(NULL, 0, NULL); |
986 return FALSE; | 1003 CPDF_StreamFilter* pSF = GetStreamFilter(TRUE); |
987 } | 1004 if (pSF) { |
988 size -= actualSize; | 1005 uint8_t* pBuf = FX_Alloc(uint8_t, 4096); |
989 srcOffset += actualSize; | 1006 FX_DWORD dwRead; |
990 destOffset += actualSize; | 1007 do { |
991 } | 1008 dwRead = pSF->ReadBlock(pBuf, 4096); |
992 return TRUE; | 1009 if (dwRead) { |
993 } | 1010 pFS->WriteBlock(pBuf, dwRead); |
994 if (m_GenNum != (FX_DWORD) - 1 || pOther->m_GenNum != (FX_DWORD) - 1) { | 1011 } |
995 IFX_FileRead* pFile = NULL; | 1012 } while (dwRead == 4096); |
996 uint8_t* pBuf = NULL; | 1013 pFS->Flush(); |
997 FX_DWORD offset = 0; | 1014 FX_Free(pBuf); |
998 if (pOther->m_GenNum != (FX_DWORD) - 1) { | 1015 delete pSF; |
999 pFile = pOther->m_pFile; | 1016 } |
1000 pBuf = m_pDataBuf; | 1017 pObj->InitStream((IFX_FileRead*)pFS, pCloneDict); |
1001 offset = pOther->m_FileOffset; | 1018 return pObj; |
1002 } else if (m_GenNum != (FX_DWORD) - 1) { | 1019 } |
1003 pFile = m_pFile; | 1020 extern FX_BOOL PDF_DataDecode(const uint8_t* src_buf, |
1004 pBuf = pOther->m_pDataBuf; | 1021 FX_DWORD src_size, |
1005 offset = m_FileOffset; | 1022 const CPDF_Dictionary* pDict, |
1006 } | 1023 uint8_t*& dest_buf, |
1007 if (NULL == pBuf) { | 1024 FX_DWORD& dest_size, |
1008 return FALSE; | 1025 CFX_ByteString& ImageEncoding, |
1009 } | 1026 CPDF_Dictionary*& pImageParms, |
1010 uint8_t srcBuf[1024]; | 1027 FX_DWORD estimated_size, |
1011 FX_DWORD size = m_dwSize; | 1028 FX_BOOL bImageAcc); |
1012 while (size > 0) { | 1029 CPDF_StreamAcc::CPDF_StreamAcc() { |
1013 FX_DWORD actualSize = std::min(size, 1024U); | 1030 m_bNewBuf = FALSE; |
1014 pFile->ReadBlock(srcBuf, offset, actualSize); | 1031 m_pData = NULL; |
1015 if (FXSYS_memcmp(srcBuf, pBuf, actualSize) != 0) { | 1032 m_dwSize = 0; |
1016 return FALSE; | 1033 m_pImageParam = NULL; |
1017 } | 1034 m_pStream = NULL; |
1018 pBuf += actualSize; | 1035 m_pSrcData = NULL; |
1019 size -= actualSize; | 1036 } |
1020 offset += actualSize; | 1037 void CPDF_StreamAcc::LoadAllData(const CPDF_Stream* pStream, |
1021 } | 1038 FX_BOOL bRawAccess, |
1022 return TRUE; | 1039 FX_DWORD estimated_size, |
1023 } | 1040 FX_BOOL bImageAcc) { |
1024 return FXSYS_memcmp(m_pDataBuf, pOther->m_pDataBuf, m_dwSize) == 0; | 1041 if (pStream == NULL || pStream->GetType() != PDFOBJ_STREAM) { |
1025 } | 1042 return; |
1026 CPDF_Stream* CPDF_Stream::Clone(FX_BOOL bDirect, FPDF_LPFCloneStreamCallback lpf
Callback, void* pUserData) const | 1043 } |
1027 { | 1044 m_pStream = pStream; |
1028 CPDF_Dictionary *pCloneDict = (CPDF_Dictionary*)m_pDict->Clone(bDirect); | 1045 if (pStream->IsMemoryBased() && |
1029 IFX_FileStream *pFS = NULL; | 1046 (!pStream->GetDict()->KeyExist(FX_BSTRC("Filter")) || bRawAccess)) { |
1030 if (lpfCallback) { | 1047 m_dwSize = pStream->m_dwSize; |
1031 pFS = lpfCallback((CPDF_Stream*)this, pUserData); | 1048 m_pData = (uint8_t*)pStream->m_pDataBuf; |
1032 } | 1049 return; |
1033 if (!pFS) { | 1050 } |
1034 CPDF_StreamAcc acc; | 1051 uint8_t* pSrcData; |
1035 acc.LoadAllData(this, TRUE); | 1052 FX_DWORD dwSrcSize = pStream->m_dwSize; |
1036 FX_DWORD streamSize = acc.GetSize(); | 1053 if (dwSrcSize == 0) { |
1037 return new CPDF_Stream(acc.DetachData(), streamSize, pCloneDict); | 1054 return; |
1038 } | 1055 } |
1039 CPDF_Stream* pObj = new CPDF_Stream(NULL, 0, NULL); | 1056 if (!pStream->IsMemoryBased()) { |
1040 CPDF_StreamFilter *pSF = GetStreamFilter(TRUE); | 1057 pSrcData = m_pSrcData = FX_Alloc(uint8_t, dwSrcSize); |
1041 if (pSF) { | 1058 if (!pStream->ReadRawData(0, pSrcData, dwSrcSize)) { |
1042 uint8_t* pBuf = FX_Alloc(uint8_t, 4096); | 1059 return; |
1043 FX_DWORD dwRead; | 1060 } |
1044 do { | 1061 } else { |
1045 dwRead = pSF->ReadBlock(pBuf, 4096); | 1062 pSrcData = pStream->m_pDataBuf; |
1046 if (dwRead) { | 1063 } |
1047 pFS->WriteBlock(pBuf, dwRead); | 1064 uint8_t* pDecryptedData; |
1048 } | 1065 FX_DWORD dwDecryptedSize; |
1049 } while (dwRead == 4096); | 1066 if (pStream->m_pCryptoHandler) { |
1050 pFS->Flush(); | 1067 CFX_BinaryBuf dest_buf; |
1051 FX_Free(pBuf); | 1068 dest_buf.EstimateSize(pStream->m_pCryptoHandler->DecryptGetSize(dwSrcSize)); |
1052 delete pSF; | 1069 void* context = pStream->m_pCryptoHandler->DecryptStart( |
1053 } | 1070 pStream->GetObjNum(), pStream->m_GenNum); |
1054 pObj->InitStream((IFX_FileRead*)pFS, pCloneDict); | 1071 pStream->m_pCryptoHandler->DecryptStream(context, pSrcData, dwSrcSize, |
1055 return pObj; | 1072 dest_buf); |
1056 } | 1073 pStream->m_pCryptoHandler->DecryptFinish(context, dest_buf); |
1057 extern FX_BOOL PDF_DataDecode(const uint8_t* src_buf, FX_DWORD src_size, const C
PDF_Dictionary* pDict, | 1074 pDecryptedData = dest_buf.GetBuffer(); |
1058 uint8_t*& dest_buf, FX_DWORD& dest_size, CFX_ByteS
tring& ImageEncoding, | 1075 dwDecryptedSize = dest_buf.GetSize(); |
1059 CPDF_Dictionary*& pImageParms, FX_DWORD estimated_
size, FX_BOOL bImageAcc); | 1076 dest_buf.DetachBuffer(); |
1060 CPDF_StreamAcc::CPDF_StreamAcc() | 1077 } else { |
1061 { | 1078 pDecryptedData = pSrcData; |
1062 m_bNewBuf = FALSE; | 1079 dwDecryptedSize = dwSrcSize; |
| 1080 } |
| 1081 if (!pStream->GetDict()->KeyExist(FX_BSTRC("Filter")) || bRawAccess) { |
| 1082 m_pData = pDecryptedData; |
| 1083 m_dwSize = dwDecryptedSize; |
| 1084 } else { |
| 1085 FX_BOOL bRet = PDF_DataDecode( |
| 1086 pDecryptedData, dwDecryptedSize, m_pStream->GetDict(), m_pData, |
| 1087 m_dwSize, m_ImageDecoder, m_pImageParam, estimated_size, bImageAcc); |
| 1088 if (!bRet) { |
| 1089 m_pData = pDecryptedData; |
| 1090 m_dwSize = dwDecryptedSize; |
| 1091 } |
| 1092 } |
| 1093 if (pSrcData != pStream->m_pDataBuf && pSrcData != m_pData) { |
| 1094 FX_Free(pSrcData); |
| 1095 } |
| 1096 if (pDecryptedData != pSrcData && pDecryptedData != m_pData) { |
| 1097 FX_Free(pDecryptedData); |
| 1098 } |
| 1099 m_pSrcData = NULL; |
| 1100 m_bNewBuf = m_pData != pStream->m_pDataBuf; |
| 1101 } |
| 1102 CPDF_StreamAcc::~CPDF_StreamAcc() { |
| 1103 if (m_bNewBuf && m_pData) { |
| 1104 FX_Free(m_pData); |
| 1105 } |
| 1106 if (m_pSrcData) { |
| 1107 FX_Free(m_pSrcData); |
| 1108 } |
| 1109 } |
| 1110 const uint8_t* CPDF_StreamAcc::GetData() const { |
| 1111 if (m_bNewBuf) { |
| 1112 return m_pData; |
| 1113 } |
| 1114 if (!m_pStream) { |
| 1115 return NULL; |
| 1116 } |
| 1117 return m_pStream->m_pDataBuf; |
| 1118 } |
| 1119 FX_DWORD CPDF_StreamAcc::GetSize() const { |
| 1120 if (m_bNewBuf) { |
| 1121 return m_dwSize; |
| 1122 } |
| 1123 if (!m_pStream) { |
| 1124 return 0; |
| 1125 } |
| 1126 return m_pStream->m_dwSize; |
| 1127 } |
| 1128 uint8_t* CPDF_StreamAcc::DetachData() { |
| 1129 if (m_bNewBuf) { |
| 1130 uint8_t* p = m_pData; |
1063 m_pData = NULL; | 1131 m_pData = NULL; |
1064 m_dwSize = 0; | 1132 m_dwSize = 0; |
1065 m_pImageParam = NULL; | 1133 return p; |
1066 m_pStream = NULL; | 1134 } |
1067 m_pSrcData = NULL; | 1135 uint8_t* p = FX_Alloc(uint8_t, m_dwSize); |
1068 } | 1136 FXSYS_memcpy(p, m_pData, m_dwSize); |
1069 void CPDF_StreamAcc::LoadAllData(const CPDF_Stream* pStream, FX_BOOL bRawAccess,
FX_DWORD estimated_size, | 1137 return p; |
1070 FX_BOOL bImageAcc) | 1138 } |
1071 { | 1139 void CPDF_Reference::SetRef(CPDF_IndirectObjects* pDoc, FX_DWORD objnum) { |
1072 if (pStream == NULL || pStream->GetType() != PDFOBJ_STREAM) { | 1140 m_pObjList = pDoc; |
| 1141 m_RefObjNum = objnum; |
| 1142 } |
| 1143 CPDF_IndirectObjects::CPDF_IndirectObjects(CPDF_Parser* pParser) { |
| 1144 m_pParser = pParser; |
| 1145 m_IndirectObjs.InitHashTable(1013); |
| 1146 if (pParser) { |
| 1147 m_LastObjNum = m_pParser->GetLastObjNum(); |
| 1148 } else { |
| 1149 m_LastObjNum = 0; |
| 1150 } |
| 1151 } |
| 1152 CPDF_IndirectObjects::~CPDF_IndirectObjects() { |
| 1153 FX_POSITION pos = m_IndirectObjs.GetStartPosition(); |
| 1154 while (pos) { |
| 1155 void* key; |
| 1156 void* value; |
| 1157 m_IndirectObjs.GetNextAssoc(pos, key, value); |
| 1158 ((CPDF_Object*)value)->Destroy(); |
| 1159 } |
| 1160 } |
| 1161 CPDF_Object* CPDF_IndirectObjects::GetIndirectObject( |
| 1162 FX_DWORD objnum, |
| 1163 struct PARSE_CONTEXT* pContext) { |
| 1164 if (objnum == 0) { |
| 1165 return NULL; |
| 1166 } |
| 1167 void* value; |
| 1168 { |
| 1169 if (m_IndirectObjs.Lookup((void*)(uintptr_t)objnum, value)) { |
| 1170 if (((CPDF_Object*)value)->GetObjNum() == -1) { |
| 1171 return NULL; |
| 1172 } |
| 1173 return (CPDF_Object*)value; |
| 1174 } |
| 1175 } |
| 1176 CPDF_Object* pObj = NULL; |
| 1177 if (m_pParser) { |
| 1178 pObj = m_pParser->ParseIndirectObject(this, objnum, pContext); |
| 1179 } |
| 1180 if (pObj == NULL) { |
| 1181 return NULL; |
| 1182 } |
| 1183 pObj->m_ObjNum = objnum; |
| 1184 if (m_LastObjNum < objnum) { |
| 1185 m_LastObjNum = objnum; |
| 1186 } |
| 1187 if (m_IndirectObjs.Lookup((void*)(uintptr_t)objnum, value)) { |
| 1188 if (value) { |
| 1189 ((CPDF_Object*)value)->Destroy(); |
| 1190 } |
| 1191 } |
| 1192 m_IndirectObjs.SetAt((void*)(uintptr_t)objnum, pObj); |
| 1193 return pObj; |
| 1194 } |
| 1195 int CPDF_IndirectObjects::GetIndirectType(FX_DWORD objnum) { |
| 1196 void* value; |
| 1197 if (m_IndirectObjs.Lookup((void*)(uintptr_t)objnum, value)) { |
| 1198 return ((CPDF_Object*)value)->GetType(); |
| 1199 } |
| 1200 if (m_pParser) { |
| 1201 PARSE_CONTEXT context; |
| 1202 FXSYS_memset(&context, 0, sizeof(PARSE_CONTEXT)); |
| 1203 context.m_Flags = PDFPARSE_TYPEONLY; |
| 1204 return (int)(uintptr_t)m_pParser->ParseIndirectObject(this, objnum, |
| 1205 &context); |
| 1206 } |
| 1207 return 0; |
| 1208 } |
| 1209 FX_DWORD CPDF_IndirectObjects::AddIndirectObject(CPDF_Object* pObj) { |
| 1210 if (pObj->m_ObjNum) { |
| 1211 return pObj->m_ObjNum; |
| 1212 } |
| 1213 m_LastObjNum++; |
| 1214 m_IndirectObjs.SetAt((void*)(uintptr_t)m_LastObjNum, pObj); |
| 1215 pObj->m_ObjNum = m_LastObjNum; |
| 1216 return m_LastObjNum; |
| 1217 } |
| 1218 void CPDF_IndirectObjects::ReleaseIndirectObject(FX_DWORD objnum) { |
| 1219 void* value; |
| 1220 if (!m_IndirectObjs.Lookup((void*)(uintptr_t)objnum, value)) { |
| 1221 return; |
| 1222 } |
| 1223 if (((CPDF_Object*)value)->GetObjNum() == -1) { |
| 1224 return; |
| 1225 } |
| 1226 ((CPDF_Object*)value)->Destroy(); |
| 1227 m_IndirectObjs.RemoveKey((void*)(uintptr_t)objnum); |
| 1228 } |
| 1229 void CPDF_IndirectObjects::InsertIndirectObject(FX_DWORD objnum, |
| 1230 CPDF_Object* pObj) { |
| 1231 if (objnum == 0 || pObj == NULL) { |
| 1232 return; |
| 1233 } |
| 1234 void* value = NULL; |
| 1235 if (m_IndirectObjs.Lookup((void*)(uintptr_t)objnum, value)) { |
| 1236 if (value) { |
| 1237 if (pObj->GetGenNum() <= ((CPDF_Object*)value)->GetGenNum()) { |
1073 return; | 1238 return; |
1074 } | 1239 } |
1075 m_pStream = pStream; | 1240 ((CPDF_Object*)value)->Destroy(); |
1076 if (pStream->IsMemoryBased() && | 1241 } |
1077 (!pStream->GetDict()->KeyExist(FX_BSTRC("Filter")) || bRawAccess)) { | 1242 } |
1078 m_dwSize = pStream->m_dwSize; | 1243 pObj->m_ObjNum = objnum; |
1079 m_pData = (uint8_t*)pStream->m_pDataBuf; | 1244 m_IndirectObjs.SetAt((void*)(uintptr_t)objnum, pObj); |
1080 return; | 1245 if (m_LastObjNum < objnum) { |
1081 } | 1246 m_LastObjNum = objnum; |
1082 uint8_t* pSrcData; | 1247 } |
1083 FX_DWORD dwSrcSize = pStream->m_dwSize; | 1248 } |
1084 if (dwSrcSize == 0) { | 1249 FX_DWORD CPDF_IndirectObjects::GetLastObjNum() const { |
1085 return; | 1250 return m_LastObjNum; |
1086 } | 1251 } |
1087 if (!pStream->IsMemoryBased()) { | |
1088 pSrcData = m_pSrcData = FX_Alloc(uint8_t, dwSrcSize); | |
1089 if (!pStream->ReadRawData(0, pSrcData, dwSrcSize)) { | |
1090 return; | |
1091 } | |
1092 } else { | |
1093 pSrcData = pStream->m_pDataBuf; | |
1094 } | |
1095 uint8_t* pDecryptedData; | |
1096 FX_DWORD dwDecryptedSize; | |
1097 if (pStream->m_pCryptoHandler) { | |
1098 CFX_BinaryBuf dest_buf; | |
1099 dest_buf.EstimateSize(pStream->m_pCryptoHandler->DecryptGetSize(dwSrcSiz
e)); | |
1100 void* context = pStream->m_pCryptoHandler->DecryptStart(pStream->GetObjN
um(), pStream->m_GenNum); | |
1101 pStream->m_pCryptoHandler->DecryptStream(context, pSrcData, dwSrcSize, d
est_buf); | |
1102 pStream->m_pCryptoHandler->DecryptFinish(context, dest_buf); | |
1103 pDecryptedData = dest_buf.GetBuffer(); | |
1104 dwDecryptedSize = dest_buf.GetSize(); | |
1105 dest_buf.DetachBuffer(); | |
1106 } else { | |
1107 pDecryptedData = pSrcData; | |
1108 dwDecryptedSize = dwSrcSize; | |
1109 } | |
1110 if (!pStream->GetDict()->KeyExist(FX_BSTRC("Filter")) || bRawAccess) { | |
1111 m_pData = pDecryptedData; | |
1112 m_dwSize = dwDecryptedSize; | |
1113 } else { | |
1114 FX_BOOL bRet = PDF_DataDecode(pDecryptedData, dwDecryptedSize, m_pStream
->GetDict(), | |
1115 m_pData, m_dwSize, m_ImageDecoder, m_pImag
eParam, estimated_size, bImageAcc); | |
1116 if (!bRet) { | |
1117 m_pData = pDecryptedData; | |
1118 m_dwSize = dwDecryptedSize; | |
1119 } | |
1120 } | |
1121 if (pSrcData != pStream->m_pDataBuf && pSrcData != m_pData) { | |
1122 FX_Free(pSrcData); | |
1123 } | |
1124 if (pDecryptedData != pSrcData && pDecryptedData != m_pData) { | |
1125 FX_Free(pDecryptedData); | |
1126 } | |
1127 m_pSrcData = NULL; | |
1128 m_bNewBuf = m_pData != pStream->m_pDataBuf; | |
1129 } | |
1130 CPDF_StreamAcc::~CPDF_StreamAcc() | |
1131 { | |
1132 if (m_bNewBuf && m_pData) { | |
1133 FX_Free(m_pData); | |
1134 } | |
1135 if (m_pSrcData) { | |
1136 FX_Free(m_pSrcData); | |
1137 } | |
1138 } | |
1139 const uint8_t* CPDF_StreamAcc::GetData() const | |
1140 { | |
1141 if (m_bNewBuf) { | |
1142 return m_pData; | |
1143 } | |
1144 if (!m_pStream) { | |
1145 return NULL; | |
1146 } | |
1147 return m_pStream->m_pDataBuf; | |
1148 } | |
1149 FX_DWORD CPDF_StreamAcc::GetSize() const | |
1150 { | |
1151 if (m_bNewBuf) { | |
1152 return m_dwSize; | |
1153 } | |
1154 if (!m_pStream) { | |
1155 return 0; | |
1156 } | |
1157 return m_pStream->m_dwSize; | |
1158 } | |
1159 uint8_t* CPDF_StreamAcc::DetachData() | |
1160 { | |
1161 if (m_bNewBuf) { | |
1162 uint8_t* p = m_pData; | |
1163 m_pData = NULL; | |
1164 m_dwSize = 0; | |
1165 return p; | |
1166 } | |
1167 uint8_t* p = FX_Alloc(uint8_t, m_dwSize); | |
1168 FXSYS_memcpy(p, m_pData, m_dwSize); | |
1169 return p; | |
1170 } | |
1171 void CPDF_Reference::SetRef(CPDF_IndirectObjects* pDoc, FX_DWORD objnum) | |
1172 { | |
1173 m_pObjList = pDoc; | |
1174 m_RefObjNum = objnum; | |
1175 } | |
1176 CPDF_IndirectObjects::CPDF_IndirectObjects(CPDF_Parser* pParser) | |
1177 { | |
1178 m_pParser = pParser; | |
1179 m_IndirectObjs.InitHashTable(1013); | |
1180 if (pParser) { | |
1181 m_LastObjNum = m_pParser->GetLastObjNum(); | |
1182 } else { | |
1183 m_LastObjNum = 0; | |
1184 } | |
1185 } | |
1186 CPDF_IndirectObjects::~CPDF_IndirectObjects() | |
1187 { | |
1188 FX_POSITION pos = m_IndirectObjs.GetStartPosition(); | |
1189 while (pos) { | |
1190 void* key; | |
1191 void* value; | |
1192 m_IndirectObjs.GetNextAssoc(pos, key, value); | |
1193 ((CPDF_Object*)value)->Destroy(); | |
1194 } | |
1195 } | |
1196 CPDF_Object* CPDF_IndirectObjects::GetIndirectObject(FX_DWORD objnum, struct PAR
SE_CONTEXT* pContext) | |
1197 { | |
1198 if (objnum == 0) { | |
1199 return NULL; | |
1200 } | |
1201 void* value; | |
1202 { | |
1203 if (m_IndirectObjs.Lookup((void*)(uintptr_t)objnum, value)) { | |
1204 if (((CPDF_Object*)value)->GetObjNum() == -1) { | |
1205 return NULL; | |
1206 } | |
1207 return (CPDF_Object*)value; | |
1208 } | |
1209 } | |
1210 CPDF_Object* pObj = NULL; | |
1211 if (m_pParser) { | |
1212 pObj = m_pParser->ParseIndirectObject(this, objnum, pContext); | |
1213 } | |
1214 if (pObj == NULL) { | |
1215 return NULL; | |
1216 } | |
1217 pObj->m_ObjNum = objnum; | |
1218 if (m_LastObjNum < objnum) { | |
1219 m_LastObjNum = objnum; | |
1220 } | |
1221 if (m_IndirectObjs.Lookup((void*)(uintptr_t)objnum, value)) { | |
1222 if (value) { | |
1223 ((CPDF_Object *)value)->Destroy(); | |
1224 } | |
1225 } | |
1226 m_IndirectObjs.SetAt((void*)(uintptr_t)objnum, pObj); | |
1227 return pObj; | |
1228 } | |
1229 int CPDF_IndirectObjects::GetIndirectType(FX_DWORD objnum) | |
1230 { | |
1231 void* value; | |
1232 if (m_IndirectObjs.Lookup((void*)(uintptr_t)objnum, value)) { | |
1233 return ((CPDF_Object*)value)->GetType(); | |
1234 } | |
1235 if (m_pParser) { | |
1236 PARSE_CONTEXT context; | |
1237 FXSYS_memset(&context, 0, sizeof(PARSE_CONTEXT)); | |
1238 context.m_Flags = PDFPARSE_TYPEONLY; | |
1239 return (int)(uintptr_t)m_pParser->ParseIndirectObject(this, objnum, &con
text); | |
1240 } | |
1241 return 0; | |
1242 } | |
1243 FX_DWORD CPDF_IndirectObjects::AddIndirectObject(CPDF_Object* pObj) | |
1244 { | |
1245 if (pObj->m_ObjNum) { | |
1246 return pObj->m_ObjNum; | |
1247 } | |
1248 m_LastObjNum ++; | |
1249 m_IndirectObjs.SetAt((void*)(uintptr_t)m_LastObjNum, pObj); | |
1250 pObj->m_ObjNum = m_LastObjNum; | |
1251 return m_LastObjNum; | |
1252 } | |
1253 void CPDF_IndirectObjects::ReleaseIndirectObject(FX_DWORD objnum) | |
1254 { | |
1255 void* value; | |
1256 if (!m_IndirectObjs.Lookup((void*)(uintptr_t)objnum, value)) { | |
1257 return; | |
1258 } | |
1259 if (((CPDF_Object*)value)->GetObjNum() == -1) { | |
1260 return; | |
1261 } | |
1262 ((CPDF_Object*)value)->Destroy(); | |
1263 m_IndirectObjs.RemoveKey((void*)(uintptr_t)objnum); | |
1264 } | |
1265 void CPDF_IndirectObjects::InsertIndirectObject(FX_DWORD objnum, CPDF_Object* pO
bj) | |
1266 { | |
1267 if (objnum == 0 || pObj == NULL) { | |
1268 return; | |
1269 } | |
1270 void* value = NULL; | |
1271 if (m_IndirectObjs.Lookup((void*)(uintptr_t)objnum, value)) { | |
1272 if (value) { | |
1273 if (pObj->GetGenNum() <= ((CPDF_Object*)value)->GetGenNum()) { | |
1274 return; | |
1275 } | |
1276 ((CPDF_Object*)value)->Destroy(); | |
1277 } | |
1278 } | |
1279 pObj->m_ObjNum = objnum; | |
1280 m_IndirectObjs.SetAt((void*)(uintptr_t)objnum, pObj); | |
1281 if (m_LastObjNum < objnum) { | |
1282 m_LastObjNum = objnum; | |
1283 } | |
1284 } | |
1285 FX_DWORD CPDF_IndirectObjects::GetLastObjNum() const | |
1286 { | |
1287 return m_LastObjNum; | |
1288 } | |
OLD | NEW |