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 "core/include/fpdfapi/fpdf_parser.h" | 7 #include "core/include/fpdfapi/fpdf_parser.h" |
8 | 8 |
9 #include "core/include/fxcrt/fx_string.h" | 9 #include "core/include/fxcrt/fx_string.h" |
10 | 10 |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 const CPDF_String* pString = AsString(); | 244 const CPDF_String* pString = AsString(); |
245 return new CPDF_String(pString->m_String, pString->IsHex()); | 245 return new CPDF_String(pString->m_String, pString->IsHex()); |
246 } | 246 } |
247 case PDFOBJ_NAME: | 247 case PDFOBJ_NAME: |
248 return new CPDF_Name(AsName()->m_Name); | 248 return new CPDF_Name(AsName()->m_Name); |
249 case PDFOBJ_ARRAY: { | 249 case PDFOBJ_ARRAY: { |
250 CPDF_Array* pCopy = new CPDF_Array(); | 250 CPDF_Array* pCopy = new CPDF_Array(); |
251 const CPDF_Array* pThis = AsArray(); | 251 const CPDF_Array* pThis = AsArray(); |
252 int n = pThis->GetCount(); | 252 int n = pThis->GetCount(); |
253 for (int i = 0; i < n; i++) { | 253 for (int i = 0; i < n; i++) { |
254 CPDF_Object* value = | 254 CPDF_Object* value = pThis->m_Objects.GetAt(i); |
255 static_cast<CPDF_Object*>(pThis->m_Objects.GetAt(i)); | |
256 pCopy->m_Objects.Add(value->CloneInternal(bDirect, visited)); | 255 pCopy->m_Objects.Add(value->CloneInternal(bDirect, visited)); |
257 } | 256 } |
258 return pCopy; | 257 return pCopy; |
259 } | 258 } |
260 case PDFOBJ_DICTIONARY: { | 259 case PDFOBJ_DICTIONARY: { |
261 CPDF_Dictionary* pCopy = new CPDF_Dictionary(); | 260 CPDF_Dictionary* pCopy = new CPDF_Dictionary(); |
262 const CPDF_Dictionary* pThis = AsDictionary(); | 261 const CPDF_Dictionary* pThis = AsDictionary(); |
263 FX_POSITION pos = pThis->m_Map.GetStartPosition(); | 262 FX_POSITION pos = pThis->m_Map.GetStartPosition(); |
264 while (pos) { | 263 while (pos) { |
265 CFX_ByteString key; | 264 CFX_ByteString key; |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 void CPDF_Number::SetNumber(FX_FLOAT value) { | 416 void CPDF_Number::SetNumber(FX_FLOAT value) { |
418 m_bInteger = FALSE; | 417 m_bInteger = FALSE; |
419 m_Float = value; | 418 m_Float = value; |
420 } | 419 } |
421 CPDF_String::CPDF_String(const CFX_WideString& str) | 420 CPDF_String::CPDF_String(const CFX_WideString& str) |
422 : CPDF_Object(PDFOBJ_STRING), m_bHex(FALSE) { | 421 : CPDF_Object(PDFOBJ_STRING), m_bHex(FALSE) { |
423 m_String = PDF_EncodeText(str); | 422 m_String = PDF_EncodeText(str); |
424 } | 423 } |
425 CPDF_Array::~CPDF_Array() { | 424 CPDF_Array::~CPDF_Array() { |
426 int size = m_Objects.GetSize(); | 425 int size = m_Objects.GetSize(); |
427 CPDF_Object** pList = (CPDF_Object**)m_Objects.GetData(); | 426 CPDF_Object** pList = m_Objects.GetData(); |
428 for (int i = 0; i < size; i++) { | 427 for (int i = 0; i < size; i++) { |
429 if (pList[i]) | 428 if (pList[i]) |
430 pList[i]->Release(); | 429 pList[i]->Release(); |
431 } | 430 } |
432 } | 431 } |
433 CFX_FloatRect CPDF_Array::GetRect() { | 432 CFX_FloatRect CPDF_Array::GetRect() { |
434 CFX_FloatRect rect; | 433 CFX_FloatRect rect; |
435 if (!IsArray() || m_Objects.GetSize() != 4) | 434 if (!IsArray() || m_Objects.GetSize() != 4) |
436 return rect; | 435 return rect; |
437 | 436 |
438 rect.left = GetNumber(0); | 437 rect.left = GetNumber(0); |
439 rect.bottom = GetNumber(1); | 438 rect.bottom = GetNumber(1); |
440 rect.right = GetNumber(2); | 439 rect.right = GetNumber(2); |
441 rect.top = GetNumber(3); | 440 rect.top = GetNumber(3); |
442 return rect; | 441 return rect; |
443 } | 442 } |
444 CFX_AffineMatrix CPDF_Array::GetMatrix() { | 443 CFX_AffineMatrix CPDF_Array::GetMatrix() { |
445 CFX_AffineMatrix matrix; | 444 CFX_AffineMatrix matrix; |
446 if (!IsArray() || m_Objects.GetSize() != 6) | 445 if (!IsArray() || m_Objects.GetSize() != 6) |
447 return matrix; | 446 return matrix; |
448 | 447 |
449 matrix.Set(GetNumber(0), GetNumber(1), GetNumber(2), GetNumber(3), | 448 matrix.Set(GetNumber(0), GetNumber(1), GetNumber(2), GetNumber(3), |
450 GetNumber(4), GetNumber(5)); | 449 GetNumber(4), GetNumber(5)); |
451 return matrix; | 450 return matrix; |
452 } | 451 } |
453 CPDF_Object* CPDF_Array::GetElement(FX_DWORD i) const { | 452 CPDF_Object* CPDF_Array::GetElement(FX_DWORD i) const { |
454 if (i >= (FX_DWORD)m_Objects.GetSize()) | 453 if (i >= (FX_DWORD)m_Objects.GetSize()) |
455 return nullptr; | 454 return nullptr; |
456 return static_cast<CPDF_Object*>(m_Objects.GetAt(i)); | 455 return m_Objects.GetAt(i); |
457 } | 456 } |
458 CPDF_Object* CPDF_Array::GetElementValue(FX_DWORD i) const { | 457 CPDF_Object* CPDF_Array::GetElementValue(FX_DWORD i) const { |
459 if (i >= (FX_DWORD)m_Objects.GetSize()) | 458 if (i >= (FX_DWORD)m_Objects.GetSize()) |
460 return nullptr; | 459 return nullptr; |
461 return static_cast<CPDF_Object*>(m_Objects.GetAt(i))->GetDirect(); | 460 return m_Objects.GetAt(i)->GetDirect(); |
462 } | 461 } |
463 CFX_ByteString CPDF_Array::GetString(FX_DWORD i) const { | 462 CFX_ByteString CPDF_Array::GetString(FX_DWORD i) const { |
464 if (i < (FX_DWORD)m_Objects.GetSize()) | 463 if (i >= (FX_DWORD)m_Objects.GetSize()) |
465 return static_cast<CPDF_Object*>(m_Objects.GetAt(i))->GetString(); | 464 return CFX_ByteString(); |
466 return CFX_ByteString(); | 465 return m_Objects.GetAt(i)->GetString(); |
467 } | 466 } |
468 CFX_ByteStringC CPDF_Array::GetConstString(FX_DWORD i) const { | 467 CFX_ByteStringC CPDF_Array::GetConstString(FX_DWORD i) const { |
469 if (i < (FX_DWORD)m_Objects.GetSize()) | 468 if (i >= (FX_DWORD)m_Objects.GetSize()) |
470 return static_cast<CPDF_Object*>(m_Objects.GetAt(i))->GetConstString(); | 469 return CFX_ByteStringC(); |
471 return CFX_ByteStringC(); | 470 return m_Objects.GetAt(i)->GetConstString(); |
472 } | 471 } |
473 int CPDF_Array::GetInteger(FX_DWORD i) const { | 472 int CPDF_Array::GetInteger(FX_DWORD i) const { |
474 if (i >= (FX_DWORD)m_Objects.GetSize()) | 473 if (i >= (FX_DWORD)m_Objects.GetSize()) |
475 return 0; | 474 return 0; |
476 return static_cast<CPDF_Object*>(m_Objects.GetAt(i))->GetInteger(); | 475 return m_Objects.GetAt(i)->GetInteger(); |
477 } | 476 } |
478 FX_FLOAT CPDF_Array::GetNumber(FX_DWORD i) const { | 477 FX_FLOAT CPDF_Array::GetNumber(FX_DWORD i) const { |
479 if (i >= (FX_DWORD)m_Objects.GetSize()) | 478 if (i >= (FX_DWORD)m_Objects.GetSize()) |
480 return 0; | 479 return 0; |
481 return static_cast<CPDF_Object*>(m_Objects.GetAt(i))->GetNumber(); | 480 return m_Objects.GetAt(i)->GetNumber(); |
482 } | 481 } |
483 CPDF_Dictionary* CPDF_Array::GetDict(FX_DWORD i) const { | 482 CPDF_Dictionary* CPDF_Array::GetDict(FX_DWORD i) const { |
484 CPDF_Object* p = GetElementValue(i); | 483 CPDF_Object* p = GetElementValue(i); |
485 if (!p) | 484 if (!p) |
486 return NULL; | 485 return NULL; |
487 if (CPDF_Dictionary* pDict = p->AsDictionary()) | 486 if (CPDF_Dictionary* pDict = p->AsDictionary()) |
488 return pDict; | 487 return pDict; |
489 if (CPDF_Stream* pStream = p->AsStream()) | 488 if (CPDF_Stream* pStream = p->AsStream()) |
490 return pStream->GetDict(); | 489 return pStream->GetDict(); |
491 return NULL; | 490 return NULL; |
492 } | 491 } |
493 CPDF_Stream* CPDF_Array::GetStream(FX_DWORD i) const { | 492 CPDF_Stream* CPDF_Array::GetStream(FX_DWORD i) const { |
494 return ToStream(GetElementValue(i)); | 493 return ToStream(GetElementValue(i)); |
495 } | 494 } |
496 CPDF_Array* CPDF_Array::GetArray(FX_DWORD i) const { | 495 CPDF_Array* CPDF_Array::GetArray(FX_DWORD i) const { |
497 return ToArray(GetElementValue(i)); | 496 return ToArray(GetElementValue(i)); |
498 } | 497 } |
499 void CPDF_Array::RemoveAt(FX_DWORD i, int nCount) { | 498 void CPDF_Array::RemoveAt(FX_DWORD i, int nCount) { |
500 if (i >= (FX_DWORD)m_Objects.GetSize()) | 499 if (i >= (FX_DWORD)m_Objects.GetSize()) |
501 return; | 500 return; |
502 | 501 |
503 if (nCount <= 0 || nCount > m_Objects.GetSize() - i) | 502 if (nCount <= 0 || nCount > m_Objects.GetSize() - i) |
504 return; | 503 return; |
505 | 504 |
506 for (int j = 0; j < nCount; ++j) { | 505 for (int j = 0; j < nCount; ++j) { |
507 if (CPDF_Object* p = static_cast<CPDF_Object*>(m_Objects.GetAt(i + j))) | 506 if (CPDF_Object* p = m_Objects.GetAt(i + j)) |
508 p->Release(); | 507 p->Release(); |
509 } | 508 } |
510 m_Objects.RemoveAt(i, nCount); | 509 m_Objects.RemoveAt(i, nCount); |
511 } | 510 } |
512 void CPDF_Array::SetAt(FX_DWORD i, | 511 void CPDF_Array::SetAt(FX_DWORD i, |
513 CPDF_Object* pObj, | 512 CPDF_Object* pObj, |
514 CPDF_IndirectObjects* pObjs) { | 513 CPDF_IndirectObjects* pObjs) { |
515 ASSERT(IsArray()); | 514 ASSERT(IsArray()); |
516 ASSERT(i < (FX_DWORD)m_Objects.GetSize()); | 515 ASSERT(i < (FX_DWORD)m_Objects.GetSize()); |
517 if (i >= (FX_DWORD)m_Objects.GetSize()) | 516 if (i >= (FX_DWORD)m_Objects.GetSize()) |
518 return; | 517 return; |
519 if (CPDF_Object* pOld = static_cast<CPDF_Object*>(m_Objects.GetAt(i))) | 518 if (CPDF_Object* pOld = m_Objects.GetAt(i)) |
520 pOld->Release(); | 519 pOld->Release(); |
521 if (pObj->GetObjNum()) { | 520 if (pObj->GetObjNum()) { |
522 ASSERT(pObjs); | 521 ASSERT(pObjs); |
523 pObj = new CPDF_Reference(pObjs, pObj->GetObjNum()); | 522 pObj = new CPDF_Reference(pObjs, pObj->GetObjNum()); |
524 } | 523 } |
525 m_Objects.SetAt(i, pObj); | 524 m_Objects.SetAt(i, pObj); |
526 } | 525 } |
527 void CPDF_Array::InsertAt(FX_DWORD index, | 526 void CPDF_Array::InsertAt(FX_DWORD index, |
528 CPDF_Object* pObj, | 527 CPDF_Object* pObj, |
529 CPDF_IndirectObjects* pObjs) { | 528 CPDF_IndirectObjects* pObjs) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 Add(pNumber); | 560 Add(pNumber); |
562 } | 561 } |
563 void CPDF_Array::AddReference(CPDF_IndirectObjects* pDoc, FX_DWORD objnum) { | 562 void CPDF_Array::AddReference(CPDF_IndirectObjects* pDoc, FX_DWORD objnum) { |
564 ASSERT(IsArray()); | 563 ASSERT(IsArray()); |
565 Add(new CPDF_Reference(pDoc, objnum)); | 564 Add(new CPDF_Reference(pDoc, objnum)); |
566 } | 565 } |
567 FX_BOOL CPDF_Array::Identical(CPDF_Array* pOther) const { | 566 FX_BOOL CPDF_Array::Identical(CPDF_Array* pOther) const { |
568 if (m_Objects.GetSize() != pOther->m_Objects.GetSize()) { | 567 if (m_Objects.GetSize() != pOther->m_Objects.GetSize()) { |
569 return FALSE; | 568 return FALSE; |
570 } | 569 } |
571 for (int i = 0; i < m_Objects.GetSize(); i++) | 570 for (int i = 0; i < m_Objects.GetSize(); i++) { |
572 if (!static_cast<CPDF_Object*>(m_Objects[i]) | 571 if (!m_Objects[i]->IsIdentical(pOther->m_Objects[i])) |
573 ->IsIdentical(static_cast<CPDF_Object*>(pOther->m_Objects[i]))) { | |
574 return FALSE; | 572 return FALSE; |
575 } | 573 } |
576 return TRUE; | 574 return TRUE; |
577 } | 575 } |
578 CPDF_Dictionary::~CPDF_Dictionary() { | 576 CPDF_Dictionary::~CPDF_Dictionary() { |
579 FX_POSITION pos = m_Map.GetStartPosition(); | 577 FX_POSITION pos = m_Map.GetStartPosition(); |
580 while (pos) { | 578 while (pos) { |
581 if (CPDF_Object* value = static_cast<CPDF_Object*>(m_Map.GetNextValue(pos))) | 579 if (CPDF_Object* value = static_cast<CPDF_Object*>(m_Map.GetNextValue(pos))) |
582 value->Release(); | 580 value->Release(); |
583 } | 581 } |
584 } | 582 } |
585 FX_POSITION CPDF_Dictionary::GetStartPos() const { | 583 FX_POSITION CPDF_Dictionary::GetStartPos() const { |
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1174 } | 1172 } |
1175 pObj->m_ObjNum = objnum; | 1173 pObj->m_ObjNum = objnum; |
1176 m_IndirectObjs.SetAt((void*)(uintptr_t)objnum, pObj); | 1174 m_IndirectObjs.SetAt((void*)(uintptr_t)objnum, pObj); |
1177 if (m_LastObjNum < objnum) { | 1175 if (m_LastObjNum < objnum) { |
1178 m_LastObjNum = objnum; | 1176 m_LastObjNum = objnum; |
1179 } | 1177 } |
1180 } | 1178 } |
1181 FX_DWORD CPDF_IndirectObjects::GetLastObjNum() const { | 1179 FX_DWORD CPDF_IndirectObjects::GetLastObjNum() const { |
1182 return m_LastObjNum; | 1180 return m_LastObjNum; |
1183 } | 1181 } |
OLD | NEW |