| 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 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 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 ((CPDF_Boolean*)this)->m_bValue ? "true" : "false"; | 43 return AsBoolean()->m_bValue ? "true" : "false"; |
| 44 case PDFOBJ_NUMBER: | 44 case PDFOBJ_NUMBER: |
| 45 return ((CPDF_Number*)this)->GetString(); | 45 return ((CPDF_Number*)this)->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 ((CPDF_Name*)this)->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; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 FX_FLOAT CPDF_Object::GetNumber16() const { | 107 FX_FLOAT CPDF_Object::GetNumber16() const { |
| 108 return GetNumber(); | 108 return GetNumber(); |
| 109 } | 109 } |
| 110 int CPDF_Object::GetInteger() const { | 110 int CPDF_Object::GetInteger() const { |
| 111 CFX_AutoRestorer<int> restorer(&s_nCurRefDepth); | 111 CFX_AutoRestorer<int> restorer(&s_nCurRefDepth); |
| 112 if (++s_nCurRefDepth > OBJECT_REF_MAX_DEPTH) { | 112 if (++s_nCurRefDepth > OBJECT_REF_MAX_DEPTH) { |
| 113 return 0; | 113 return 0; |
| 114 } | 114 } |
| 115 switch (m_Type) { | 115 switch (m_Type) { |
| 116 case PDFOBJ_BOOLEAN: | 116 case PDFOBJ_BOOLEAN: |
| 117 return ((CPDF_Boolean*)this)->m_bValue; | 117 return this->AsBoolean()->m_bValue; |
| 118 case PDFOBJ_NUMBER: | 118 case PDFOBJ_NUMBER: |
| 119 return ((CPDF_Number*)this)->GetInteger(); | 119 return ((CPDF_Number*)this)->GetInteger(); |
| 120 case PDFOBJ_REFERENCE: { | 120 case PDFOBJ_REFERENCE: { |
| 121 CPDF_Reference* pRef = (CPDF_Reference*)(void*)this; | 121 CPDF_Reference* pRef = (CPDF_Reference*)(void*)this; |
| 122 PARSE_CONTEXT context; | 122 PARSE_CONTEXT context; |
| 123 FXSYS_memset(&context, 0, sizeof(PARSE_CONTEXT)); | 123 FXSYS_memset(&context, 0, sizeof(PARSE_CONTEXT)); |
| 124 if (pRef->m_pObjList == NULL) { | 124 if (pRef->m_pObjList == NULL) { |
| 125 return 0; | 125 return 0; |
| 126 } | 126 } |
| 127 CPDF_Object* pObj = | 127 CPDF_Object* pObj = |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 CPDF_Array* CPDF_Object::GetArray() const { | 161 CPDF_Array* CPDF_Object::GetArray() const { |
| 162 if (m_Type == PDFOBJ_ARRAY) | 162 if (m_Type == PDFOBJ_ARRAY) |
| 163 return (CPDF_Array*)this; | 163 return (CPDF_Array*)this; |
| 164 | 164 |
| 165 return NULL; | 165 return NULL; |
| 166 } | 166 } |
| 167 void CPDF_Object::SetString(const CFX_ByteString& str) { | 167 void CPDF_Object::SetString(const CFX_ByteString& str) { |
| 168 ASSERT(this != NULL); | 168 ASSERT(this != NULL); |
| 169 switch (m_Type) { | 169 switch (m_Type) { |
| 170 case PDFOBJ_BOOLEAN: | 170 case PDFOBJ_BOOLEAN: |
| 171 ((CPDF_Boolean*)this)->m_bValue = str == FX_BSTRC("true") ? 1 : 0; | 171 AsBoolean()->m_bValue = (str == FX_BSTRC("true")); |
| 172 return; | 172 return; |
| 173 case PDFOBJ_NUMBER: | 173 case PDFOBJ_NUMBER: |
| 174 ((CPDF_Number*)this)->SetString(str); | 174 ((CPDF_Number*)this)->SetString(str); |
| 175 return; | 175 return; |
| 176 case PDFOBJ_STRING: | 176 case PDFOBJ_STRING: |
| 177 ((CPDF_String*)this)->m_String = str; | 177 ((CPDF_String*)this)->m_String = str; |
| 178 return; | 178 return; |
| 179 case PDFOBJ_NAME: | 179 case PDFOBJ_NAME: |
| 180 ((CPDF_Name*)this)->m_Name = str; | 180 ((CPDF_Name*)this)->m_Name = str; |
| 181 return; | 181 return; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 200 if (m_Type == PDFOBJ_REFERENCE && GetDirect()) { | 200 if (m_Type == PDFOBJ_REFERENCE && GetDirect()) { |
| 201 return GetDirect()->IsIdentical(pOther); | 201 return GetDirect()->IsIdentical(pOther); |
| 202 } | 202 } |
| 203 if (pOther->m_Type == PDFOBJ_REFERENCE) { | 203 if (pOther->m_Type == PDFOBJ_REFERENCE) { |
| 204 return IsIdentical(pOther->GetDirect()); | 204 return IsIdentical(pOther->GetDirect()); |
| 205 } | 205 } |
| 206 return FALSE; | 206 return FALSE; |
| 207 } | 207 } |
| 208 switch (m_Type) { | 208 switch (m_Type) { |
| 209 case PDFOBJ_BOOLEAN: | 209 case PDFOBJ_BOOLEAN: |
| 210 return (((CPDF_Boolean*)this)->Identical((CPDF_Boolean*)pOther)); | 210 return this->AsBoolean()->Identical(pOther->AsBoolean()); |
| 211 case PDFOBJ_NUMBER: | 211 case PDFOBJ_NUMBER: |
| 212 return (((CPDF_Number*)this)->Identical((CPDF_Number*)pOther)); | 212 return (((CPDF_Number*)this)->Identical((CPDF_Number*)pOther)); |
| 213 case PDFOBJ_STRING: | 213 case PDFOBJ_STRING: |
| 214 return (((CPDF_String*)this)->Identical((CPDF_String*)pOther)); | 214 return (((CPDF_String*)this)->Identical((CPDF_String*)pOther)); |
| 215 case PDFOBJ_NAME: | 215 case PDFOBJ_NAME: |
| 216 return (((CPDF_Name*)this)->Identical((CPDF_Name*)pOther)); | 216 return (((CPDF_Name*)this)->Identical((CPDF_Name*)pOther)); |
| 217 case PDFOBJ_ARRAY: | 217 case PDFOBJ_ARRAY: |
| 218 return (((CPDF_Array*)this)->Identical((CPDF_Array*)pOther)); | 218 return (((CPDF_Array*)this)->Identical((CPDF_Array*)pOther)); |
| 219 case PDFOBJ_DICTIONARY: | 219 case PDFOBJ_DICTIONARY: |
| 220 return this->AsDictionary()->Identical(pOther->AsDictionary()); | 220 return this->AsDictionary()->Identical(pOther->AsDictionary()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 238 return pRef->m_pObjList->GetIndirectObject(pRef->GetRefObjNum()); | 238 return pRef->m_pObjList->GetIndirectObject(pRef->GetRefObjNum()); |
| 239 } | 239 } |
| 240 CPDF_Object* CPDF_Object::Clone(FX_BOOL bDirect) const { | 240 CPDF_Object* CPDF_Object::Clone(FX_BOOL bDirect) const { |
| 241 CFX_MapPtrToPtr visited; | 241 CFX_MapPtrToPtr visited; |
| 242 return CloneInternal(bDirect, &visited); | 242 return CloneInternal(bDirect, &visited); |
| 243 } | 243 } |
| 244 CPDF_Object* CPDF_Object::CloneInternal(FX_BOOL bDirect, | 244 CPDF_Object* CPDF_Object::CloneInternal(FX_BOOL bDirect, |
| 245 CFX_MapPtrToPtr* visited) const { | 245 CFX_MapPtrToPtr* visited) const { |
| 246 switch (m_Type) { | 246 switch (m_Type) { |
| 247 case PDFOBJ_BOOLEAN: | 247 case PDFOBJ_BOOLEAN: |
| 248 return new CPDF_Boolean(((CPDF_Boolean*)this)->m_bValue); | 248 return new CPDF_Boolean(this->AsBoolean()->m_bValue); |
| 249 case PDFOBJ_NUMBER: | 249 case PDFOBJ_NUMBER: |
| 250 return new CPDF_Number(((CPDF_Number*)this)->m_bInteger, | 250 return new CPDF_Number(((CPDF_Number*)this)->m_bInteger, |
| 251 &((CPDF_Number*)this)->m_Integer); | 251 &((CPDF_Number*)this)->m_Integer); |
| 252 case PDFOBJ_STRING: | 252 case PDFOBJ_STRING: |
| 253 return new CPDF_String(((CPDF_String*)this)->m_String, | 253 return new CPDF_String(((CPDF_String*)this)->m_String, |
| 254 ((CPDF_String*)this)->IsHex()); | 254 ((CPDF_String*)this)->IsHex()); |
| 255 case PDFOBJ_NAME: | 255 case PDFOBJ_NAME: |
| 256 return new CPDF_Name(((CPDF_Name*)this)->m_Name); | 256 return new CPDF_Name(((CPDF_Name*)this)->m_Name); |
| 257 case PDFOBJ_ARRAY: { | 257 case PDFOBJ_ARRAY: { |
| 258 CPDF_Array* pCopy = new CPDF_Array(); | 258 CPDF_Array* pCopy = new CPDF_Array(); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 void CPDF_Object::SetUnicodeText(const FX_WCHAR* pUnicodes, int len) { | 330 void CPDF_Object::SetUnicodeText(const FX_WCHAR* pUnicodes, int len) { |
| 331 if (m_Type == PDFOBJ_STRING) { | 331 if (m_Type == PDFOBJ_STRING) { |
| 332 ((CPDF_String*)this)->m_String = PDF_EncodeText(pUnicodes, len); | 332 ((CPDF_String*)this)->m_String = PDF_EncodeText(pUnicodes, len); |
| 333 } else if (m_Type == PDFOBJ_STREAM) { | 333 } else if (m_Type == PDFOBJ_STREAM) { |
| 334 CFX_ByteString result = PDF_EncodeText(pUnicodes, len); | 334 CFX_ByteString result = PDF_EncodeText(pUnicodes, len); |
| 335 ((CPDF_Stream*)this) | 335 ((CPDF_Stream*)this) |
| 336 ->SetData((uint8_t*)result.c_str(), result.GetLength(), FALSE, FALSE); | 336 ->SetData((uint8_t*)result.c_str(), result.GetLength(), FALSE, FALSE); |
| 337 } | 337 } |
| 338 } | 338 } |
| 339 | 339 |
| 340 CPDF_Boolean* CPDF_Object::AsBoolean() { |
| 341 return IsBoolean() ? static_cast<CPDF_Boolean*>(this) : nullptr; |
| 342 } |
| 343 |
| 344 const CPDF_Boolean* CPDF_Object::AsBoolean() const { |
| 345 return IsBoolean() ? static_cast<const CPDF_Boolean*>(this) : nullptr; |
| 346 } |
| 347 |
| 340 CPDF_Dictionary* CPDF_Object::AsDictionary() { | 348 CPDF_Dictionary* CPDF_Object::AsDictionary() { |
| 341 return IsDictionary() ? static_cast<CPDF_Dictionary*>(this) : nullptr; | 349 return IsDictionary() ? static_cast<CPDF_Dictionary*>(this) : nullptr; |
| 342 } | 350 } |
| 343 | 351 |
| 344 const CPDF_Dictionary* CPDF_Object::AsDictionary() const { | 352 const CPDF_Dictionary* CPDF_Object::AsDictionary() const { |
| 345 return IsDictionary() ? static_cast<const CPDF_Dictionary*>(this) : nullptr; | 353 return IsDictionary() ? static_cast<const CPDF_Dictionary*>(this) : nullptr; |
| 346 } | 354 } |
| 347 | 355 |
| 348 CPDF_Number::CPDF_Number(int value) | 356 CPDF_Number::CPDF_Number(int value) |
| 349 : CPDF_Object(PDFOBJ_NUMBER), m_bInteger(TRUE), m_Integer(value) {} | 357 : CPDF_Object(PDFOBJ_NUMBER), m_bInteger(TRUE), m_Integer(value) {} |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 656 m_Map.Lookup(key, (void*&)p); | 664 m_Map.Lookup(key, (void*&)p); |
| 657 if (p) { | 665 if (p) { |
| 658 return p->GetNumber(); | 666 return p->GetNumber(); |
| 659 } | 667 } |
| 660 return 0; | 668 return 0; |
| 661 } | 669 } |
| 662 FX_BOOL CPDF_Dictionary::GetBoolean(const CFX_ByteStringC& key, | 670 FX_BOOL CPDF_Dictionary::GetBoolean(const CFX_ByteStringC& key, |
| 663 FX_BOOL bDefault) const { | 671 FX_BOOL bDefault) const { |
| 664 CPDF_Object* p = NULL; | 672 CPDF_Object* p = NULL; |
| 665 m_Map.Lookup(key, (void*&)p); | 673 m_Map.Lookup(key, (void*&)p); |
| 666 if (p && p->GetType() == PDFOBJ_BOOLEAN) { | 674 if (ToBoolean(p)) |
| 667 return p->GetInteger(); | 675 return p->GetInteger(); |
| 668 } | |
| 669 return bDefault; | 676 return bDefault; |
| 670 } | 677 } |
| 671 CPDF_Dictionary* CPDF_Dictionary::GetDict(const CFX_ByteStringC& key) const { | 678 CPDF_Dictionary* CPDF_Dictionary::GetDict(const CFX_ByteStringC& key) const { |
| 672 CPDF_Object* p = GetElementValue(key); | 679 CPDF_Object* p = GetElementValue(key); |
| 673 if (!p) { | 680 if (!p) { |
| 674 return nullptr; | 681 return nullptr; |
| 675 } | 682 } |
| 676 if (CPDF_Dictionary* pDict = p->AsDictionary()) { | 683 if (CPDF_Dictionary* pDict = p->AsDictionary()) { |
| 677 return pDict; | 684 return pDict; |
| 678 } | 685 } |
| (...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1208 } | 1215 } |
| 1209 pObj->m_ObjNum = objnum; | 1216 pObj->m_ObjNum = objnum; |
| 1210 m_IndirectObjs.SetAt((void*)(uintptr_t)objnum, pObj); | 1217 m_IndirectObjs.SetAt((void*)(uintptr_t)objnum, pObj); |
| 1211 if (m_LastObjNum < objnum) { | 1218 if (m_LastObjNum < objnum) { |
| 1212 m_LastObjNum = objnum; | 1219 m_LastObjNum = objnum; |
| 1213 } | 1220 } |
| 1214 } | 1221 } |
| 1215 FX_DWORD CPDF_IndirectObjects::GetLastObjNum() const { | 1222 FX_DWORD CPDF_IndirectObjects::GetLastObjNum() const { |
| 1216 return m_LastObjNum; | 1223 return m_LastObjNum; |
| 1217 } | 1224 } |
| OLD | NEW |