Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(365)

Side by Side Diff: core/fpdfapi/parser/cpdf_hint_tables.cpp

Issue 2466023002: Unify some code (Closed)
Patch Set: Fix compilation Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/parser/cpdf_hint_tables.h" 7 #include "core/fpdfapi/parser/cpdf_hint_tables.h"
8 8
9 #include <limits> 9 #include <limits>
10 10
11 #include "core/fpdfapi/parser/cpdf_array.h" 11 #include "core/fpdfapi/parser/cpdf_array.h"
12 #include "core/fpdfapi/parser/cpdf_data_avail.h" 12 #include "core/fpdfapi/parser/cpdf_data_avail.h"
13 #include "core/fpdfapi/parser/cpdf_dictionary.h" 13 #include "core/fpdfapi/parser/cpdf_dictionary.h"
14 #include "core/fpdfapi/parser/cpdf_document.h" 14 #include "core/fpdfapi/parser/cpdf_document.h"
15 #include "core/fpdfapi/parser/cpdf_linearized.h"
15 #include "core/fpdfapi/parser/cpdf_stream.h" 16 #include "core/fpdfapi/parser/cpdf_stream.h"
16 #include "core/fpdfapi/parser/cpdf_stream_acc.h" 17 #include "core/fpdfapi/parser/cpdf_stream_acc.h"
17 #include "core/fxcrt/fx_safe_types.h" 18 #include "core/fxcrt/fx_safe_types.h"
18 #include "third_party/base/numerics/safe_conversions.h" 19 #include "third_party/base/numerics/safe_conversions.h"
19 20
20 namespace { 21 namespace {
21 22
22 bool CanReadFromBitStream(const CFX_BitStream* hStream, 23 bool CanReadFromBitStream(const CFX_BitStream* hStream,
23 const FX_SAFE_UINT32& bits) { 24 const FX_SAFE_UINT32& bits) {
24 return bits.IsValid() && hStream->BitsRemaining() >= bits.ValueOrDie(); 25 return bits.IsValid() && hStream->BitsRemaining() >= bits.ValueOrDie();
25 } 26 }
26 27
27 // Sanity check values from the page table header. The note in the PDF 1.7 28 // Sanity check values from the page table header. The note in the PDF 1.7
28 // reference for Table F.3 says the valid range is only 0 through 32. Though 0 29 // reference for Table F.3 says the valid range is only 0 through 32. Though 0
29 // is not useful either. 30 // is not useful either.
30 bool IsValidPageOffsetHintTableBitCount(uint32_t bits) { 31 bool IsValidPageOffsetHintTableBitCount(uint32_t bits) {
31 return bits > 0 && bits <= 32; 32 return bits > 0 && bits <= 32;
32 } 33 }
33 34
34 } // namespace 35 } // namespace
35 36
36 CPDF_HintTables::CPDF_HintTables(CPDF_DataAvail* pDataAvail, 37 CPDF_HintTables::CPDF_HintTables(CPDF_DataAvail* pDataAvail,
37 CPDF_Dictionary* pLinearized) 38 CPDF_Linearized* pLinearized)
38 : m_pDataAvail(pDataAvail), 39 : m_pDataAvail(pDataAvail),
39 m_pLinearizedDict(pLinearized), 40 m_pLinearized(pLinearized),
40 m_nFirstPageSharedObjs(0), 41 m_nFirstPageSharedObjs(0),
41 m_szFirstPageObjOffset(0) { 42 m_szFirstPageObjOffset(0) {
42 ASSERT(m_pLinearizedDict); 43 ASSERT(m_pLinearized);
43 } 44 }
44 45
45 CPDF_HintTables::~CPDF_HintTables() {} 46 CPDF_HintTables::~CPDF_HintTables() {}
46 47
47 uint32_t CPDF_HintTables::GetItemLength( 48 uint32_t CPDF_HintTables::GetItemLength(
48 uint32_t index, 49 uint32_t index,
49 const std::vector<FX_FILESIZE>& szArray) { 50 const std::vector<FX_FILESIZE>& szArray) {
50 if (szArray.size() < 2 || index > szArray.size() - 2 || 51 if (szArray.size() < 2 || index > szArray.size() - 2 ||
51 szArray[index] > szArray[index + 1]) { 52 szArray[index] > szArray[index + 1]) {
52 return 0; 53 return 0;
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 return false; 481 return false;
481 } 482 }
482 483
483 CFX_BitStream bs; 484 CFX_BitStream bs;
484 bs.Init(acc.GetData(), size); 485 bs.Init(acc.GetData(), size);
485 return ReadPageHintTable(&bs) && 486 return ReadPageHintTable(&bs) &&
486 ReadSharedObjHintTable(&bs, shared_hint_table_offset); 487 ReadSharedObjHintTable(&bs, shared_hint_table_offset);
487 } 488 }
488 489
489 int CPDF_HintTables::GetEndOfFirstPageOffset() const { 490 int CPDF_HintTables::GetEndOfFirstPageOffset() const {
490 CPDF_Object* pOffsetE = m_pLinearizedDict->GetDirectObjectFor("E"); 491 return static_cast<int>(m_pLinearized->GetFirstPageEndOffset());
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->GetDirectObjectFor("N"); 495 return static_cast<int>(m_pLinearized->GetPageCount());
496 return pPageNum ? pPageNum->GetInteger() : 0;
497 } 496 }
498 497
499 int CPDF_HintTables::GetFirstPageObjectNumber() const { 498 int CPDF_HintTables::GetFirstPageObjectNumber() const {
500 CPDF_Object* pFirstPageObj = m_pLinearizedDict->GetDirectObjectFor("O"); 499 return static_cast<int>(m_pLinearized->GetFirstPageObjNum());
501 return pFirstPageObj ? pFirstPageObj->GetInteger() : -1;
502 } 500 }
503 501
504 int CPDF_HintTables::GetFirstPageNumber() const { 502 int CPDF_HintTables::GetFirstPageNumber() const {
505 CPDF_Object* pFirstPageNum = m_pLinearizedDict->GetDirectObjectFor("P"); 503 return static_cast<int>(m_pLinearized->GetFirstPageNo());
506 return pFirstPageNum ? pFirstPageNum->GetInteger() : 0;
507 } 504 }
508 505
509 int CPDF_HintTables::ReadPrimaryHintStreamOffset() const { 506 int CPDF_HintTables::ReadPrimaryHintStreamOffset() const {
510 return ReadPrimaryHintStream(0); 507 return static_cast<int>(m_pLinearized->GetHintStart());
511 } 508 }
512 509
513 int CPDF_HintTables::ReadPrimaryHintStreamLength() const { 510 int CPDF_HintTables::ReadPrimaryHintStreamLength() const {
514 return ReadPrimaryHintStream(1); 511 return static_cast<int>(m_pLinearized->GetHintLength());
515 } 512 }
516
517 int CPDF_HintTables::ReadPrimaryHintStream(int index) const {
518 CPDF_Array* pRange = m_pLinearizedDict->GetArrayFor("H");
519 if (!pRange)
520 return -1;
521
522 CPDF_Object* pStreamLen = pRange->GetDirectObjectAt(index);
523 return pStreamLen ? pStreamLen->GetInteger() : -1;
524 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698