| OLD | NEW |
| 1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 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/fpdfapi/fpdf_parser/cpdf_hint_tables.h" | 7 #include "core/fpdfapi/fpdf_parser/cpdf_hint_tables.h" |
| 8 | 8 |
| 9 #include <limits> | 9 #include <limits> |
| 10 | 10 |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 } | 448 } |
| 449 } | 449 } |
| 450 return CPDF_DataAvail::DataAvailable; | 450 return CPDF_DataAvail::DataAvailable; |
| 451 } | 451 } |
| 452 | 452 |
| 453 bool CPDF_HintTables::LoadHintStream(CPDF_Stream* pHintStream) { | 453 bool CPDF_HintTables::LoadHintStream(CPDF_Stream* pHintStream) { |
| 454 if (!pHintStream) | 454 if (!pHintStream) |
| 455 return false; | 455 return false; |
| 456 | 456 |
| 457 CPDF_Dictionary* pDict = pHintStream->GetDict(); | 457 CPDF_Dictionary* pDict = pHintStream->GetDict(); |
| 458 CPDF_Object* pOffset = pDict ? pDict->GetObjectBy("S") : nullptr; | 458 CPDF_Object* pOffset = pDict ? pDict->GetObjectFor("S") : nullptr; |
| 459 if (!pOffset || !pOffset->IsNumber()) | 459 if (!pOffset || !pOffset->IsNumber()) |
| 460 return false; | 460 return false; |
| 461 | 461 |
| 462 int shared_hint_table_offset = pOffset->GetInteger(); | 462 int shared_hint_table_offset = pOffset->GetInteger(); |
| 463 if (shared_hint_table_offset <= 0) | 463 if (shared_hint_table_offset <= 0) |
| 464 return false; | 464 return false; |
| 465 | 465 |
| 466 CPDF_StreamAcc acc; | 466 CPDF_StreamAcc acc; |
| 467 acc.LoadAllData(pHintStream); | 467 acc.LoadAllData(pHintStream); |
| 468 | 468 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 480 return false; | 480 return false; |
| 481 } | 481 } |
| 482 | 482 |
| 483 CFX_BitStream bs; | 483 CFX_BitStream bs; |
| 484 bs.Init(acc.GetData(), size); | 484 bs.Init(acc.GetData(), size); |
| 485 return ReadPageHintTable(&bs) && | 485 return ReadPageHintTable(&bs) && |
| 486 ReadSharedObjHintTable(&bs, shared_hint_table_offset); | 486 ReadSharedObjHintTable(&bs, shared_hint_table_offset); |
| 487 } | 487 } |
| 488 | 488 |
| 489 int CPDF_HintTables::GetEndOfFirstPageOffset() const { | 489 int CPDF_HintTables::GetEndOfFirstPageOffset() const { |
| 490 CPDF_Object* pOffsetE = m_pLinearizedDict->GetDirectObjectBy("E"); | 490 CPDF_Object* pOffsetE = m_pLinearizedDict->GetDirectObjectFor("E"); |
| 491 return pOffsetE ? pOffsetE->GetInteger() : -1; | 491 return pOffsetE ? pOffsetE->GetInteger() : -1; |
| 492 } | 492 } |
| 493 | 493 |
| 494 int CPDF_HintTables::GetNumberOfPages() const { | 494 int CPDF_HintTables::GetNumberOfPages() const { |
| 495 CPDF_Object* pPageNum = m_pLinearizedDict->GetDirectObjectBy("N"); | 495 CPDF_Object* pPageNum = m_pLinearizedDict->GetDirectObjectFor("N"); |
| 496 return pPageNum ? pPageNum->GetInteger() : 0; | 496 return pPageNum ? pPageNum->GetInteger() : 0; |
| 497 } | 497 } |
| 498 | 498 |
| 499 int CPDF_HintTables::GetFirstPageObjectNumber() const { | 499 int CPDF_HintTables::GetFirstPageObjectNumber() const { |
| 500 CPDF_Object* pFirstPageObj = m_pLinearizedDict->GetDirectObjectBy("O"); | 500 CPDF_Object* pFirstPageObj = m_pLinearizedDict->GetDirectObjectFor("O"); |
| 501 return pFirstPageObj ? pFirstPageObj->GetInteger() : -1; | 501 return pFirstPageObj ? pFirstPageObj->GetInteger() : -1; |
| 502 } | 502 } |
| 503 | 503 |
| 504 int CPDF_HintTables::GetFirstPageNumber() const { | 504 int CPDF_HintTables::GetFirstPageNumber() const { |
| 505 CPDF_Object* pFirstPageNum = m_pLinearizedDict->GetDirectObjectBy("P"); | 505 CPDF_Object* pFirstPageNum = m_pLinearizedDict->GetDirectObjectFor("P"); |
| 506 return pFirstPageNum ? pFirstPageNum->GetInteger() : 0; | 506 return pFirstPageNum ? pFirstPageNum->GetInteger() : 0; |
| 507 } | 507 } |
| 508 | 508 |
| 509 int CPDF_HintTables::ReadPrimaryHintStreamOffset() const { | 509 int CPDF_HintTables::ReadPrimaryHintStreamOffset() const { |
| 510 return ReadPrimaryHintStream(0); | 510 return ReadPrimaryHintStream(0); |
| 511 } | 511 } |
| 512 | 512 |
| 513 int CPDF_HintTables::ReadPrimaryHintStreamLength() const { | 513 int CPDF_HintTables::ReadPrimaryHintStreamLength() const { |
| 514 return ReadPrimaryHintStream(1); | 514 return ReadPrimaryHintStream(1); |
| 515 } | 515 } |
| 516 | 516 |
| 517 int CPDF_HintTables::ReadPrimaryHintStream(int index) const { | 517 int CPDF_HintTables::ReadPrimaryHintStream(int index) const { |
| 518 CPDF_Array* pRange = m_pLinearizedDict->GetArrayBy("H"); | 518 CPDF_Array* pRange = m_pLinearizedDict->GetArrayFor("H"); |
| 519 if (!pRange) | 519 if (!pRange) |
| 520 return -1; | 520 return -1; |
| 521 | 521 |
| 522 CPDF_Object* pStreamLen = pRange->GetDirectObjectAt(index); | 522 CPDF_Object* pStreamLen = pRange->GetDirectObjectAt(index); |
| 523 return pStreamLen ? pStreamLen->GetInteger() : -1; | 523 return pStreamLen ? pStreamLen->GetInteger() : -1; |
| 524 } | 524 } |
| OLD | NEW |