1 // Copyright 2016 PDFium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6 7 #ifndef CORE_FPDFAPI_PARSER_CPDF_HINT_TABLES_H_ 8 #define CORE_FPDFAPI_PARSER_CPDF_HINT_TABLES_H_ 9 10 #include <memory> 11 #include <vector> 12 13 #include "core/fpdfapi/parser/cpdf_data_avail.h" 14 #include "core/fxcrt/unowned_ptr.h" 15 16 class CFX_BitStream; 17 class CPDF_LinearizedHeader; 18 class CPDF_ReadValidator; 19 class CPDF_Stream; 20 class CPDF_SyntaxParser; 21 22 class CPDF_HintTables { 23 public: 24 struct SharedObjGroupInfo { 25 FX_FILESIZE m_szOffset = 0; 26 uint32_t m_dwLength = 0; 27 uint32_t m_dwObjectsCount = 0; 28 uint32_t m_dwStartObjNum = 0; 29 }; 30 31 class PageInfo { 32 public: 33 PageInfo(); 34 ~PageInfo(); 35 set_objects_count(uint32_t objects_count)36 void set_objects_count(uint32_t objects_count) { 37 m_dwObjectsCount = objects_count; 38 } objects_count()39 uint32_t objects_count() const { return m_dwObjectsCount; } 40 set_page_offset(FX_FILESIZE offset)41 void set_page_offset(FX_FILESIZE offset) { m_szOffset = offset; } page_offset()42 FX_FILESIZE page_offset() const { return m_szOffset; } 43 set_page_length(uint32_t length)44 void set_page_length(uint32_t length) { m_dwLength = length; } page_length()45 uint32_t page_length() const { return m_dwLength; } 46 set_start_obj_num(uint32_t start_obj_num)47 void set_start_obj_num(uint32_t start_obj_num) { 48 m_dwStartObjNum = start_obj_num; 49 } start_obj_num()50 uint32_t start_obj_num() const { return m_dwStartObjNum; } 51 AddIdentifier(uint32_t Identifier)52 void AddIdentifier(uint32_t Identifier) { 53 m_dwIdentifierArray.push_back(Identifier); 54 } 55 Identifiers()56 const std::vector<uint32_t>& Identifiers() const { 57 return m_dwIdentifierArray; 58 } 59 60 private: 61 uint32_t m_dwObjectsCount = 0; 62 FX_FILESIZE m_szOffset = 0; 63 uint32_t m_dwLength = 0; 64 uint32_t m_dwStartObjNum = 0; 65 std::vector<uint32_t> m_dwIdentifierArray; 66 67 PageInfo(const PageInfo& other) = delete; 68 PageInfo& operator=(const PageInfo&) = delete; 69 }; 70 71 static std::unique_ptr<CPDF_HintTables> Parse( 72 CPDF_SyntaxParser* parser, 73 CPDF_LinearizedHeader* pLinearized); 74 75 CPDF_HintTables(CPDF_ReadValidator* pValidator, 76 CPDF_LinearizedHeader* pLinearized); 77 virtual ~CPDF_HintTables(); 78 79 bool GetPagePos(uint32_t index, 80 FX_FILESIZE* szPageStartPos, 81 FX_FILESIZE* szPageLength, 82 uint32_t* dwObjNum) const; 83 84 CPDF_DataAvail::DocAvailStatus CheckPage(uint32_t index); 85 86 bool LoadHintStream(CPDF_Stream* pHintStream); 87 PageInfos()88 const std::vector<PageInfo>& PageInfos() const { return m_PageInfos; } SharedGroupInfos()89 const std::vector<SharedObjGroupInfo>& SharedGroupInfos() const { 90 return m_SharedObjGroupInfos; 91 } 92 GetFirstPageObjOffset()93 FX_FILESIZE GetFirstPageObjOffset() const { return m_szFirstPageObjOffset; } 94 95 protected: 96 bool ReadPageHintTable(CFX_BitStream* hStream); 97 bool ReadSharedObjHintTable(CFX_BitStream* hStream, uint32_t offset); 98 99 private: 100 FX_FILESIZE HintsOffsetToFileOffset(uint32_t hints_offset) const; 101 102 // Owned by |m_pDataAvail|. 103 UnownedPtr<CPDF_ReadValidator> m_pValidator; 104 105 // Owned by |m_pDataAvail|. 106 UnownedPtr<CPDF_LinearizedHeader> const m_pLinearized; 107 108 uint32_t m_nFirstPageSharedObjs; 109 FX_FILESIZE m_szFirstPageObjOffset; 110 111 std::vector<PageInfo> m_PageInfos; 112 std::vector<SharedObjGroupInfo> m_SharedObjGroupInfos; 113 }; 114 115 #endif // CORE_FPDFAPI_PARSER_CPDF_HINT_TABLES_H_ 116