| 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 AsString(); | 22 delete AsString(); |
| 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 AsString()->m_String; | 47 return AsString()->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 CFX_ByteString str = AsString()->m_String; | 68 CFX_ByteString str = AsString()->m_String; |
| 69 return CFX_ByteStringC((const uint8_t*)str, str.GetLength()); | 69 return CFX_ByteStringC((const uint8_t*)str, str.GetLength()); |
| 70 } | 70 } |
| 71 case PDFOBJ_NAME: | 71 case PDFOBJ_NAME: { |
| 72 return CFX_ByteStringC((const uint8_t*)((CPDF_Name*)this)->m_Name, | 72 CFX_ByteString name = AsName()->m_Name; |
| 73 ((CPDF_Name*)this)->m_Name.GetLength()); | 73 return CFX_ByteStringC((const uint8_t*)name, name.GetLength()); |
| 74 } |
| 74 case PDFOBJ_REFERENCE: { | 75 case PDFOBJ_REFERENCE: { |
| 75 CPDF_Reference* pRef = (CPDF_Reference*)(void*)this; | 76 CPDF_Reference* pRef = (CPDF_Reference*)(void*)this; |
| 76 if (pRef->m_pObjList == NULL) { | 77 if (pRef->m_pObjList == NULL) { |
| 77 break; | 78 break; |
| 78 } | 79 } |
| 79 CPDF_Object* pObj = | 80 CPDF_Object* pObj = |
| 80 pRef->m_pObjList->GetIndirectObject(pRef->GetRefObjNum()); | 81 pRef->m_pObjList->GetIndirectObject(pRef->GetRefObjNum()); |
| 81 if (pObj == NULL) { | 82 if (pObj == NULL) { |
| 82 return CFX_ByteStringC(); | 83 return CFX_ByteStringC(); |
| 83 } | 84 } |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 case PDFOBJ_BOOLEAN: | 172 case PDFOBJ_BOOLEAN: |
| 172 AsBoolean()->m_bValue = (str == FX_BSTRC("true")); | 173 AsBoolean()->m_bValue = (str == FX_BSTRC("true")); |
| 173 return; | 174 return; |
| 174 case PDFOBJ_NUMBER: | 175 case PDFOBJ_NUMBER: |
| 175 AsNumber()->SetString(str); | 176 AsNumber()->SetString(str); |
| 176 return; | 177 return; |
| 177 case PDFOBJ_STRING: | 178 case PDFOBJ_STRING: |
| 178 AsString()->m_String = str; | 179 AsString()->m_String = str; |
| 179 return; | 180 return; |
| 180 case PDFOBJ_NAME: | 181 case PDFOBJ_NAME: |
| 181 ((CPDF_Name*)this)->m_Name = str; | 182 AsName()->m_Name = str; |
| 182 return; | 183 return; |
| 183 } | 184 } |
| 184 ASSERT(FALSE); | 185 ASSERT(FALSE); |
| 185 } | 186 } |
| 186 int CPDF_Object::GetDirectType() const { | 187 int CPDF_Object::GetDirectType() const { |
| 187 if (m_Type != PDFOBJ_REFERENCE) { | 188 if (m_Type != PDFOBJ_REFERENCE) { |
| 188 return m_Type; | 189 return m_Type; |
| 189 } | 190 } |
| 190 CPDF_Reference* pRef = (CPDF_Reference*)this; | 191 CPDF_Reference* pRef = (CPDF_Reference*)this; |
| 191 return pRef->m_pObjList->GetIndirectType(pRef->GetRefObjNum()); | 192 return pRef->m_pObjList->GetIndirectType(pRef->GetRefObjNum()); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 207 return FALSE; | 208 return FALSE; |
| 208 } | 209 } |
| 209 switch (m_Type) { | 210 switch (m_Type) { |
| 210 case PDFOBJ_BOOLEAN: | 211 case PDFOBJ_BOOLEAN: |
| 211 return AsBoolean()->Identical(pOther->AsBoolean()); | 212 return AsBoolean()->Identical(pOther->AsBoolean()); |
| 212 case PDFOBJ_NUMBER: | 213 case PDFOBJ_NUMBER: |
| 213 return AsNumber()->Identical(pOther->AsNumber()); | 214 return AsNumber()->Identical(pOther->AsNumber()); |
| 214 case PDFOBJ_STRING: | 215 case PDFOBJ_STRING: |
| 215 return AsString()->Identical(pOther->AsString()); | 216 return AsString()->Identical(pOther->AsString()); |
| 216 case PDFOBJ_NAME: | 217 case PDFOBJ_NAME: |
| 217 return (((CPDF_Name*)this)->Identical((CPDF_Name*)pOther)); | 218 return AsName()->Identical(pOther->AsName()); |
| 218 case PDFOBJ_ARRAY: | 219 case PDFOBJ_ARRAY: |
| 219 return (((CPDF_Array*)this)->Identical((CPDF_Array*)pOther)); | 220 return (((CPDF_Array*)this)->Identical((CPDF_Array*)pOther)); |
| 220 case PDFOBJ_DICTIONARY: | 221 case PDFOBJ_DICTIONARY: |
| 221 return AsDictionary()->Identical(pOther->AsDictionary()); | 222 return AsDictionary()->Identical(pOther->AsDictionary()); |
| 222 case PDFOBJ_NULL: | 223 case PDFOBJ_NULL: |
| 223 return TRUE; | 224 return TRUE; |
| 224 case PDFOBJ_STREAM: | 225 case PDFOBJ_STREAM: |
| 225 return (((CPDF_Stream*)this)->Identical((CPDF_Stream*)pOther)); | 226 return (((CPDF_Stream*)this)->Identical((CPDF_Stream*)pOther)); |
| 226 case PDFOBJ_REFERENCE: | 227 case PDFOBJ_REFERENCE: |
| 227 return (((CPDF_Reference*)this)->Identical((CPDF_Reference*)pOther)); | 228 return (((CPDF_Reference*)this)->Identical((CPDF_Reference*)pOther)); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 250 case PDFOBJ_NUMBER: { | 251 case PDFOBJ_NUMBER: { |
| 251 const CPDF_Number* pThis = AsNumber(); | 252 const CPDF_Number* pThis = AsNumber(); |
| 252 return new CPDF_Number(pThis->m_bInteger ? pThis->m_Integer | 253 return new CPDF_Number(pThis->m_bInteger ? pThis->m_Integer |
| 253 : pThis->m_Float); | 254 : pThis->m_Float); |
| 254 } | 255 } |
| 255 case PDFOBJ_STRING: { | 256 case PDFOBJ_STRING: { |
| 256 const CPDF_String* pString = AsString(); | 257 const CPDF_String* pString = AsString(); |
| 257 return new CPDF_String(pString->m_String, pString->IsHex()); | 258 return new CPDF_String(pString->m_String, pString->IsHex()); |
| 258 } | 259 } |
| 259 case PDFOBJ_NAME: | 260 case PDFOBJ_NAME: |
| 260 return new CPDF_Name(((CPDF_Name*)this)->m_Name); | 261 return new CPDF_Name(AsName()->m_Name); |
| 261 case PDFOBJ_ARRAY: { | 262 case PDFOBJ_ARRAY: { |
| 262 CPDF_Array* pCopy = new CPDF_Array(); | 263 CPDF_Array* pCopy = new CPDF_Array(); |
| 263 CPDF_Array* pThis = (CPDF_Array*)this; | 264 CPDF_Array* pThis = (CPDF_Array*)this; |
| 264 int n = pThis->GetCount(); | 265 int n = pThis->GetCount(); |
| 265 for (int i = 0; i < n; i++) { | 266 for (int i = 0; i < n; i++) { |
| 266 CPDF_Object* value = (CPDF_Object*)pThis->m_Objects.GetAt(i); | 267 CPDF_Object* value = (CPDF_Object*)pThis->m_Objects.GetAt(i); |
| 267 pCopy->m_Objects.Add(value->CloneInternal(bDirect, visited)); | 268 pCopy->m_Objects.Add(value->CloneInternal(bDirect, visited)); |
| 268 } | 269 } |
| 269 return pCopy; | 270 return pCopy; |
| 270 } | 271 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 if (const CPDF_String* pString = AsString()) | 320 if (const CPDF_String* pString = AsString()) |
| 320 return PDF_DecodeText(pString->m_String, pCharMap); | 321 return PDF_DecodeText(pString->m_String, pCharMap); |
| 321 | 322 |
| 322 if (m_Type == PDFOBJ_STREAM) { | 323 if (m_Type == PDFOBJ_STREAM) { |
| 323 CPDF_StreamAcc stream; | 324 CPDF_StreamAcc stream; |
| 324 stream.LoadAllData((CPDF_Stream*)this, FALSE); | 325 stream.LoadAllData((CPDF_Stream*)this, FALSE); |
| 325 CFX_WideString result = | 326 CFX_WideString result = |
| 326 PDF_DecodeText(stream.GetData(), stream.GetSize(), pCharMap); | 327 PDF_DecodeText(stream.GetData(), stream.GetSize(), pCharMap); |
| 327 return result; | 328 return result; |
| 328 } | 329 } |
| 329 if (m_Type == PDFOBJ_NAME) { | 330 if (const CPDF_Name* pName = AsName()) |
| 330 return PDF_DecodeText(((CPDF_Name*)this)->m_Name, pCharMap); | 331 return PDF_DecodeText(pName->m_Name, pCharMap); |
| 331 } | |
| 332 return CFX_WideString(); | 332 return CFX_WideString(); |
| 333 } | 333 } |
| 334 void CPDF_Object::SetUnicodeText(const FX_WCHAR* pUnicodes, int len) { | 334 void CPDF_Object::SetUnicodeText(const FX_WCHAR* pUnicodes, int len) { |
| 335 if (CPDF_String* pString = AsString()) { | 335 if (CPDF_String* pString = AsString()) { |
| 336 pString->m_String = PDF_EncodeText(pUnicodes, len); | 336 pString->m_String = PDF_EncodeText(pUnicodes, len); |
| 337 } else if (m_Type == PDFOBJ_STREAM) { | 337 } else if (m_Type == PDFOBJ_STREAM) { |
| 338 CFX_ByteString result = PDF_EncodeText(pUnicodes, len); | 338 CFX_ByteString result = PDF_EncodeText(pUnicodes, len); |
| 339 ((CPDF_Stream*)this) | 339 ((CPDF_Stream*)this) |
| 340 ->SetData((uint8_t*)result.c_str(), result.GetLength(), FALSE, FALSE); | 340 ->SetData((uint8_t*)result.c_str(), result.GetLength(), FALSE, FALSE); |
| 341 } | 341 } |
| 342 } | 342 } |
| 343 | 343 |
| 344 CPDF_Boolean* CPDF_Object::AsBoolean() { | 344 CPDF_Boolean* CPDF_Object::AsBoolean() { |
| 345 return IsBoolean() ? static_cast<CPDF_Boolean*>(this) : nullptr; | 345 return IsBoolean() ? static_cast<CPDF_Boolean*>(this) : nullptr; |
| 346 } | 346 } |
| 347 | 347 |
| 348 const CPDF_Boolean* CPDF_Object::AsBoolean() const { | 348 const CPDF_Boolean* CPDF_Object::AsBoolean() const { |
| 349 return IsBoolean() ? static_cast<const CPDF_Boolean*>(this) : nullptr; | 349 return IsBoolean() ? static_cast<const CPDF_Boolean*>(this) : nullptr; |
| 350 } | 350 } |
| 351 | 351 |
| 352 CPDF_Dictionary* CPDF_Object::AsDictionary() { | 352 CPDF_Dictionary* CPDF_Object::AsDictionary() { |
| 353 return IsDictionary() ? static_cast<CPDF_Dictionary*>(this) : nullptr; | 353 return IsDictionary() ? static_cast<CPDF_Dictionary*>(this) : nullptr; |
| 354 } | 354 } |
| 355 | 355 |
| 356 const CPDF_Dictionary* CPDF_Object::AsDictionary() const { | 356 const CPDF_Dictionary* CPDF_Object::AsDictionary() const { |
| 357 return IsDictionary() ? static_cast<const CPDF_Dictionary*>(this) : nullptr; | 357 return IsDictionary() ? static_cast<const CPDF_Dictionary*>(this) : nullptr; |
| 358 } | 358 } |
| 359 | 359 |
| 360 CPDF_Name* CPDF_Object::AsName() { |
| 361 return IsName() ? static_cast<CPDF_Name*>(this) : nullptr; |
| 362 } |
| 363 |
| 364 const CPDF_Name* CPDF_Object::AsName() const { |
| 365 return IsName() ? static_cast<const CPDF_Name*>(this) : nullptr; |
| 366 } |
| 367 |
| 360 CPDF_Number* CPDF_Object::AsNumber() { | 368 CPDF_Number* CPDF_Object::AsNumber() { |
| 361 return IsNumber() ? static_cast<CPDF_Number*>(this) : nullptr; | 369 return IsNumber() ? static_cast<CPDF_Number*>(this) : nullptr; |
| 362 } | 370 } |
| 363 | 371 |
| 364 const CPDF_Number* CPDF_Object::AsNumber() const { | 372 const CPDF_Number* CPDF_Object::AsNumber() const { |
| 365 return IsNumber() ? static_cast<const CPDF_Number*>(this) : nullptr; | 373 return IsNumber() ? static_cast<const CPDF_Number*>(this) : nullptr; |
| 366 } | 374 } |
| 367 | 375 |
| 368 CPDF_String* CPDF_Object::AsString() { | 376 CPDF_String* CPDF_Object::AsString() { |
| 369 return IsString() ? static_cast<CPDF_String*>(this) : nullptr; | 377 return IsString() ? static_cast<CPDF_String*>(this) : nullptr; |
| (...skipping 891 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1261 } | 1269 } |
| 1262 pObj->m_ObjNum = objnum; | 1270 pObj->m_ObjNum = objnum; |
| 1263 m_IndirectObjs.SetAt((void*)(uintptr_t)objnum, pObj); | 1271 m_IndirectObjs.SetAt((void*)(uintptr_t)objnum, pObj); |
| 1264 if (m_LastObjNum < objnum) { | 1272 if (m_LastObjNum < objnum) { |
| 1265 m_LastObjNum = objnum; | 1273 m_LastObjNum = objnum; |
| 1266 } | 1274 } |
| 1267 } | 1275 } |
| 1268 FX_DWORD CPDF_IndirectObjects::GetLastObjNum() const { | 1276 FX_DWORD CPDF_IndirectObjects::GetLastObjNum() const { |
| 1269 return m_LastObjNum; | 1277 return m_LastObjNum; |
| 1270 } | 1278 } |
| OLD | NEW |