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 if (m_ObjNum) { | 14 if (m_ObjNum) { |
15 return; | 15 return; |
16 } | 16 } |
17 Destroy(); | 17 Destroy(); |
18 } | 18 } |
19 void CPDF_Object::Destroy() { | 19 void CPDF_Object::Destroy() { |
20 switch (m_Type) { | 20 switch (m_Type) { |
21 case PDFOBJ_STRING: | 21 case PDFOBJ_STRING: |
22 delete (CPDF_String*)this; | 22 delete (CPDF_String*)this; |
23 break; | 23 break; |
24 case PDFOBJ_NAME: | 24 case PDFOBJ_NAME: |
25 delete (CPDF_Name*)this; | 25 delete AsName(); |
26 break; | 26 break; |
27 case PDFOBJ_ARRAY: | 27 case PDFOBJ_ARRAY: |
28 delete (CPDF_Array*)this; | 28 delete (CPDF_Array*)this; |
29 break; | 29 break; |
30 case PDFOBJ_DICTIONARY: | 30 case PDFOBJ_DICTIONARY: |
31 delete AsDictionary(); | 31 delete AsDictionary(); |
32 break; | 32 break; |
33 case PDFOBJ_STREAM: | 33 case PDFOBJ_STREAM: |
34 delete (CPDF_Stream*)this; | 34 delete (CPDF_Stream*)this; |
35 break; | 35 break; |
36 default: | 36 default: |
37 delete this; | 37 delete this; |
38 } | 38 } |
39 } | 39 } |
40 CFX_ByteString CPDF_Object::GetString() const { | 40 CFX_ByteString CPDF_Object::GetString() const { |
41 switch (m_Type) { | 41 switch (m_Type) { |
42 case PDFOBJ_BOOLEAN: | 42 case PDFOBJ_BOOLEAN: |
43 return AsBoolean()->m_bValue ? "true" : "false"; | 43 return AsBoolean()->m_bValue ? "true" : "false"; |
44 case PDFOBJ_NUMBER: | 44 case PDFOBJ_NUMBER: |
45 return AsNumber()->GetString(); | 45 return AsNumber()->GetString(); |
46 case PDFOBJ_STRING: | 46 case PDFOBJ_STRING: |
47 return ((CPDF_String*)this)->m_String; | 47 return ((CPDF_String*)this)->m_String; |
48 case PDFOBJ_NAME: | 48 case PDFOBJ_NAME: |
49 return ((CPDF_Name*)this)->m_Name; | 49 return AsName()->m_Name; |
50 case PDFOBJ_REFERENCE: { | 50 case PDFOBJ_REFERENCE: { |
51 CPDF_Reference* pRef = (CPDF_Reference*)(void*)this; | 51 CPDF_Reference* pRef = (CPDF_Reference*)(void*)this; |
52 if (pRef->m_pObjList == NULL) { | 52 if (pRef->m_pObjList == NULL) { |
53 break; | 53 break; |
54 } | 54 } |
55 CPDF_Object* pObj = | 55 CPDF_Object* pObj = |
56 pRef->m_pObjList->GetIndirectObject(pRef->GetRefObjNum()); | 56 pRef->m_pObjList->GetIndirectObject(pRef->GetRefObjNum()); |
57 if (pObj == NULL) { | 57 if (pObj == NULL) { |
58 return CFX_ByteString(); | 58 return CFX_ByteString(); |
59 } | 59 } |
60 return pObj->GetString(); | 60 return pObj->GetString(); |
61 } | 61 } |
62 } | 62 } |
63 return CFX_ByteString(); | 63 return CFX_ByteString(); |
64 } | 64 } |
65 CFX_ByteStringC CPDF_Object::GetConstString() const { | 65 CFX_ByteStringC CPDF_Object::GetConstString() const { |
66 switch (m_Type) { | 66 switch (m_Type) { |
67 case PDFOBJ_STRING: | 67 case PDFOBJ_STRING: |
68 return CFX_ByteStringC((const uint8_t*)((CPDF_String*)this)->m_String, | 68 return CFX_ByteStringC((const uint8_t*)((CPDF_String*)this)->m_String, |
69 ((CPDF_String*)this)->m_String.GetLength()); | 69 ((CPDF_String*)this)->m_String.GetLength()); |
70 case PDFOBJ_NAME: | 70 case PDFOBJ_NAME: { |
71 return CFX_ByteStringC((const uint8_t*)((CPDF_Name*)this)->m_Name, | 71 const CPDF_Name* pName = AsName(); |
72 ((CPDF_Name*)this)->m_Name.GetLength()); | 72 return CFX_ByteStringC((const uint8_t*)pName->m_Name, |
73 pName->m_Name.GetLength()); | |
Tom Sepez
2015/10/21 17:26:18
nit: same comment as thestig in last cl about mayb
dsinclair
2015/10/21 17:52:41
Done.
| |
74 } | |
73 case PDFOBJ_REFERENCE: { | 75 case PDFOBJ_REFERENCE: { |
74 CPDF_Reference* pRef = (CPDF_Reference*)(void*)this; | 76 CPDF_Reference* pRef = (CPDF_Reference*)(void*)this; |
75 if (pRef->m_pObjList == NULL) { | 77 if (pRef->m_pObjList == NULL) { |
76 break; | 78 break; |
77 } | 79 } |
78 CPDF_Object* pObj = | 80 CPDF_Object* pObj = |
79 pRef->m_pObjList->GetIndirectObject(pRef->GetRefObjNum()); | 81 pRef->m_pObjList->GetIndirectObject(pRef->GetRefObjNum()); |
80 if (pObj == NULL) { | 82 if (pObj == NULL) { |
81 return CFX_ByteStringC(); | 83 return CFX_ByteStringC(); |
82 } | 84 } |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
170 case PDFOBJ_BOOLEAN: | 172 case PDFOBJ_BOOLEAN: |
171 AsBoolean()->m_bValue = (str == FX_BSTRC("true")); | 173 AsBoolean()->m_bValue = (str == FX_BSTRC("true")); |
172 return; | 174 return; |
173 case PDFOBJ_NUMBER: | 175 case PDFOBJ_NUMBER: |
174 AsNumber()->SetString(str); | 176 AsNumber()->SetString(str); |
175 return; | 177 return; |
176 case PDFOBJ_STRING: | 178 case PDFOBJ_STRING: |
177 ((CPDF_String*)this)->m_String = str; | 179 ((CPDF_String*)this)->m_String = str; |
178 return; | 180 return; |
179 case PDFOBJ_NAME: | 181 case PDFOBJ_NAME: |
180 ((CPDF_Name*)this)->m_Name = str; | 182 AsName()->m_Name = str; |
181 return; | 183 return; |
182 } | 184 } |
183 ASSERT(FALSE); | 185 ASSERT(FALSE); |
184 } | 186 } |
185 int CPDF_Object::GetDirectType() const { | 187 int CPDF_Object::GetDirectType() const { |
186 if (m_Type != PDFOBJ_REFERENCE) { | 188 if (m_Type != PDFOBJ_REFERENCE) { |
187 return m_Type; | 189 return m_Type; |
188 } | 190 } |
189 CPDF_Reference* pRef = (CPDF_Reference*)this; | 191 CPDF_Reference* pRef = (CPDF_Reference*)this; |
190 return pRef->m_pObjList->GetIndirectType(pRef->GetRefObjNum()); | 192 return pRef->m_pObjList->GetIndirectType(pRef->GetRefObjNum()); |
(...skipping 15 matching lines...) Expand all Loading... | |
206 return FALSE; | 208 return FALSE; |
207 } | 209 } |
208 switch (m_Type) { | 210 switch (m_Type) { |
209 case PDFOBJ_BOOLEAN: | 211 case PDFOBJ_BOOLEAN: |
210 return AsBoolean()->Identical(pOther->AsBoolean()); | 212 return AsBoolean()->Identical(pOther->AsBoolean()); |
211 case PDFOBJ_NUMBER: | 213 case PDFOBJ_NUMBER: |
212 return AsNumber()->Identical(pOther->AsNumber()); | 214 return AsNumber()->Identical(pOther->AsNumber()); |
213 case PDFOBJ_STRING: | 215 case PDFOBJ_STRING: |
214 return (((CPDF_String*)this)->Identical((CPDF_String*)pOther)); | 216 return (((CPDF_String*)this)->Identical((CPDF_String*)pOther)); |
215 case PDFOBJ_NAME: | 217 case PDFOBJ_NAME: |
216 return (((CPDF_Name*)this)->Identical((CPDF_Name*)pOther)); | 218 return AsName()->Identical(pOther->AsName()); |
217 case PDFOBJ_ARRAY: | 219 case PDFOBJ_ARRAY: |
218 return (((CPDF_Array*)this)->Identical((CPDF_Array*)pOther)); | 220 return (((CPDF_Array*)this)->Identical((CPDF_Array*)pOther)); |
219 case PDFOBJ_DICTIONARY: | 221 case PDFOBJ_DICTIONARY: |
220 return AsDictionary()->Identical(pOther->AsDictionary()); | 222 return AsDictionary()->Identical(pOther->AsDictionary()); |
221 case PDFOBJ_NULL: | 223 case PDFOBJ_NULL: |
222 return TRUE; | 224 return TRUE; |
223 case PDFOBJ_STREAM: | 225 case PDFOBJ_STREAM: |
224 return (((CPDF_Stream*)this)->Identical((CPDF_Stream*)pOther)); | 226 return (((CPDF_Stream*)this)->Identical((CPDF_Stream*)pOther)); |
225 case PDFOBJ_REFERENCE: | 227 case PDFOBJ_REFERENCE: |
226 return (((CPDF_Reference*)this)->Identical((CPDF_Reference*)pOther)); | 228 return (((CPDF_Reference*)this)->Identical((CPDF_Reference*)pOther)); |
(...skipping 21 matching lines...) Expand all Loading... | |
248 return new CPDF_Boolean(AsBoolean()->m_bValue); | 250 return new CPDF_Boolean(AsBoolean()->m_bValue); |
249 case PDFOBJ_NUMBER: { | 251 case PDFOBJ_NUMBER: { |
250 const CPDF_Number* pThis = AsNumber(); | 252 const CPDF_Number* pThis = AsNumber(); |
251 return new CPDF_Number(pThis->m_bInteger ? pThis->m_Integer | 253 return new CPDF_Number(pThis->m_bInteger ? pThis->m_Integer |
252 : pThis->m_Float); | 254 : pThis->m_Float); |
253 } | 255 } |
254 case PDFOBJ_STRING: | 256 case PDFOBJ_STRING: |
255 return new CPDF_String(((CPDF_String*)this)->m_String, | 257 return new CPDF_String(((CPDF_String*)this)->m_String, |
256 ((CPDF_String*)this)->IsHex()); | 258 ((CPDF_String*)this)->IsHex()); |
257 case PDFOBJ_NAME: | 259 case PDFOBJ_NAME: |
258 return new CPDF_Name(((CPDF_Name*)this)->m_Name); | 260 return new CPDF_Name(AsName()->m_Name); |
259 case PDFOBJ_ARRAY: { | 261 case PDFOBJ_ARRAY: { |
260 CPDF_Array* pCopy = new CPDF_Array(); | 262 CPDF_Array* pCopy = new CPDF_Array(); |
261 CPDF_Array* pThis = (CPDF_Array*)this; | 263 CPDF_Array* pThis = (CPDF_Array*)this; |
262 int n = pThis->GetCount(); | 264 int n = pThis->GetCount(); |
263 for (int i = 0; i < n; i++) { | 265 for (int i = 0; i < n; i++) { |
264 CPDF_Object* value = (CPDF_Object*)pThis->m_Objects.GetAt(i); | 266 CPDF_Object* value = (CPDF_Object*)pThis->m_Objects.GetAt(i); |
265 pCopy->m_Objects.Add(value->CloneInternal(bDirect, visited)); | 267 pCopy->m_Objects.Add(value->CloneInternal(bDirect, visited)); |
266 } | 268 } |
267 return pCopy; | 269 return pCopy; |
268 } | 270 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
317 if (m_Type == PDFOBJ_STRING) { | 319 if (m_Type == PDFOBJ_STRING) { |
318 return PDF_DecodeText(((CPDF_String*)this)->m_String, pCharMap); | 320 return PDF_DecodeText(((CPDF_String*)this)->m_String, pCharMap); |
319 } | 321 } |
320 if (m_Type == PDFOBJ_STREAM) { | 322 if (m_Type == PDFOBJ_STREAM) { |
321 CPDF_StreamAcc stream; | 323 CPDF_StreamAcc stream; |
322 stream.LoadAllData((CPDF_Stream*)this, FALSE); | 324 stream.LoadAllData((CPDF_Stream*)this, FALSE); |
323 CFX_WideString result = | 325 CFX_WideString result = |
324 PDF_DecodeText(stream.GetData(), stream.GetSize(), pCharMap); | 326 PDF_DecodeText(stream.GetData(), stream.GetSize(), pCharMap); |
325 return result; | 327 return result; |
326 } | 328 } |
327 if (m_Type == PDFOBJ_NAME) { | 329 |
Tom Sepez
2015/10/21 17:26:17
nit: I might have not opted for the ? operator her
dsinclair
2015/10/21 17:52:41
Done.
| |
328 return PDF_DecodeText(((CPDF_Name*)this)->m_Name, pCharMap); | 330 const CPDF_Name* pName = AsName(); |
329 } | 331 return pName ? PDF_DecodeText(pName->m_Name, pCharMap) : CFX_WideString(); |
330 return CFX_WideString(); | |
331 } | 332 } |
332 void CPDF_Object::SetUnicodeText(const FX_WCHAR* pUnicodes, int len) { | 333 void CPDF_Object::SetUnicodeText(const FX_WCHAR* pUnicodes, int len) { |
333 if (m_Type == PDFOBJ_STRING) { | 334 if (m_Type == PDFOBJ_STRING) { |
334 ((CPDF_String*)this)->m_String = PDF_EncodeText(pUnicodes, len); | 335 ((CPDF_String*)this)->m_String = PDF_EncodeText(pUnicodes, len); |
335 } else if (m_Type == PDFOBJ_STREAM) { | 336 } else if (m_Type == PDFOBJ_STREAM) { |
336 CFX_ByteString result = PDF_EncodeText(pUnicodes, len); | 337 CFX_ByteString result = PDF_EncodeText(pUnicodes, len); |
337 ((CPDF_Stream*)this) | 338 ((CPDF_Stream*)this) |
338 ->SetData((uint8_t*)result.c_str(), result.GetLength(), FALSE, FALSE); | 339 ->SetData((uint8_t*)result.c_str(), result.GetLength(), FALSE, FALSE); |
339 } | 340 } |
340 } | 341 } |
341 | 342 |
342 CPDF_Boolean* CPDF_Object::AsBoolean() { | 343 CPDF_Boolean* CPDF_Object::AsBoolean() { |
343 return IsBoolean() ? static_cast<CPDF_Boolean*>(this) : nullptr; | 344 return IsBoolean() ? static_cast<CPDF_Boolean*>(this) : nullptr; |
344 } | 345 } |
345 | 346 |
346 const CPDF_Boolean* CPDF_Object::AsBoolean() const { | 347 const CPDF_Boolean* CPDF_Object::AsBoolean() const { |
347 return IsBoolean() ? static_cast<const CPDF_Boolean*>(this) : nullptr; | 348 return IsBoolean() ? static_cast<const CPDF_Boolean*>(this) : nullptr; |
348 } | 349 } |
349 | 350 |
350 CPDF_Dictionary* CPDF_Object::AsDictionary() { | 351 CPDF_Dictionary* CPDF_Object::AsDictionary() { |
351 return IsDictionary() ? static_cast<CPDF_Dictionary*>(this) : nullptr; | 352 return IsDictionary() ? static_cast<CPDF_Dictionary*>(this) : nullptr; |
352 } | 353 } |
353 | 354 |
354 const CPDF_Dictionary* CPDF_Object::AsDictionary() const { | 355 const CPDF_Dictionary* CPDF_Object::AsDictionary() const { |
355 return IsDictionary() ? static_cast<const CPDF_Dictionary*>(this) : nullptr; | 356 return IsDictionary() ? static_cast<const CPDF_Dictionary*>(this) : nullptr; |
356 } | 357 } |
357 | 358 |
359 CPDF_Name* CPDF_Object::AsName() { | |
360 return IsName() ? static_cast<CPDF_Name*>(this) : nullptr; | |
361 } | |
362 | |
363 const CPDF_Name* CPDF_Object::AsName() const { | |
364 return IsName() ? static_cast<const CPDF_Name*>(this) : nullptr; | |
365 } | |
366 | |
358 CPDF_Number* CPDF_Object::AsNumber() { | 367 CPDF_Number* CPDF_Object::AsNumber() { |
359 return IsNumber() ? static_cast<CPDF_Number*>(this) : nullptr; | 368 return IsNumber() ? static_cast<CPDF_Number*>(this) : nullptr; |
360 } | 369 } |
361 | 370 |
362 const CPDF_Number* CPDF_Object::AsNumber() const { | 371 const CPDF_Number* CPDF_Object::AsNumber() const { |
363 return IsNumber() ? static_cast<const CPDF_Number*>(this) : nullptr; | 372 return IsNumber() ? static_cast<const CPDF_Number*>(this) : nullptr; |
364 } | 373 } |
365 | 374 |
366 CPDF_Number::CPDF_Number(int value) | 375 CPDF_Number::CPDF_Number(int value) |
367 : CPDF_Object(PDFOBJ_NUMBER), m_bInteger(TRUE), m_Integer(value) {} | 376 : CPDF_Object(PDFOBJ_NUMBER), m_bInteger(TRUE), m_Integer(value) {} |
(...skipping 852 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1220 } | 1229 } |
1221 pObj->m_ObjNum = objnum; | 1230 pObj->m_ObjNum = objnum; |
1222 m_IndirectObjs.SetAt((void*)(uintptr_t)objnum, pObj); | 1231 m_IndirectObjs.SetAt((void*)(uintptr_t)objnum, pObj); |
1223 if (m_LastObjNum < objnum) { | 1232 if (m_LastObjNum < objnum) { |
1224 m_LastObjNum = objnum; | 1233 m_LastObjNum = objnum; |
1225 } | 1234 } |
1226 } | 1235 } |
1227 FX_DWORD CPDF_IndirectObjects::GetLastObjNum() const { | 1236 FX_DWORD CPDF_IndirectObjects::GetLastObjNum() const { |
1228 return m_LastObjNum; | 1237 return m_LastObjNum; |
1229 } | 1238 } |
OLD | NEW |