summaryrefslogtreecommitdiff
path: root/core/fpdfapi/parser/cpdf_hint_tables.h
blob: 84f48cf41f6dd256c75fe11e357b5f229f7c57a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright 2016 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

#ifndef CORE_FPDFAPI_PARSER_CPDF_HINT_TABLES_H_
#define CORE_FPDFAPI_PARSER_CPDF_HINT_TABLES_H_

#include <vector>

#include "core/fpdfapi/parser/cpdf_data_avail.h"
#include "core/fxcrt/fx_basic.h"
#include "core/fxcrt/fx_stream.h"

class CFX_BitStream;
class CPDF_Dictionary;
class CPDF_Stream;

class CPDF_HintTables {
 public:
  CPDF_HintTables(CPDF_DataAvail* pDataAvail, CPDF_Dictionary* pLinearized);
  virtual ~CPDF_HintTables();

  bool GetPagePos(uint32_t index,
                  FX_FILESIZE* szPageStartPos,
                  FX_FILESIZE* szPageLength,
                  uint32_t* dwObjNum);

  CPDF_DataAvail::DocAvailStatus CheckPage(
      uint32_t index,
      CPDF_DataAvail::DownloadHints* pHints);

  bool LoadHintStream(CPDF_Stream* pHintStream);

 protected:
  bool ReadPageHintTable(CFX_BitStream* hStream);
  bool ReadSharedObjHintTable(CFX_BitStream* hStream, uint32_t offset);

 private:
  // Tests can override.
  virtual int GetEndOfFirstPageOffset() const;
  virtual int GetNumberOfPages() const;
  virtual int GetFirstPageObjectNumber() const;
  virtual int GetFirstPageNumber() const;
  virtual int ReadPrimaryHintStreamOffset() const;
  virtual int ReadPrimaryHintStreamLength() const;

  // Helper for the ReadPrimaryHintStream methods above.
  int ReadPrimaryHintStream(int index) const;

  uint32_t GetItemLength(uint32_t index,
                         const std::vector<FX_FILESIZE>& szArray);

  // Owner, outlives this object.
  CPDF_DataAvail* const m_pDataAvail;

  // Owned by |m_pDataAvail|.
  CPDF_Dictionary* const m_pLinearizedDict;

  uint32_t m_nFirstPageSharedObjs;
  FX_FILESIZE m_szFirstPageObjOffset;
  std::vector<uint32_t> m_dwDeltaNObjsArray;
  std::vector<uint32_t> m_dwNSharedObjsArray;
  std::vector<uint32_t> m_dwSharedObjNumArray;
  std::vector<uint32_t> m_dwIdentifierArray;
  std::vector<FX_FILESIZE> m_szPageOffsetArray;
  std::vector<FX_FILESIZE> m_szSharedObjOffsetArray;
};

#endif  // CORE_FPDFAPI_PARSER_CPDF_HINT_TABLES_H_