1 // Copyright 2017 The PDFium Authors 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_FPDFDOC_CPDF_STRUCTTREE_H_ 8 #define CORE_FPDFDOC_CPDF_STRUCTTREE_H_ 9 10 #include <functional> 11 #include <map> 12 #include <memory> 13 #include <vector> 14 15 #include "core/fpdfapi/parser/cpdf_dictionary.h" 16 #include "core/fxcrt/bytestring.h" 17 #include "core/fxcrt/retain_ptr.h" 18 19 class CPDF_Document; 20 class CPDF_StructElement; 21 22 class CPDF_StructTree { 23 public: 24 static std::unique_ptr<CPDF_StructTree> LoadPage( 25 const CPDF_Document* pDoc, 26 RetainPtr<const CPDF_Dictionary> pPageDict); 27 28 explicit CPDF_StructTree(const CPDF_Document* pDoc); 29 ~CPDF_StructTree(); 30 CountTopElements()31 size_t CountTopElements() const { return m_Kids.size(); } GetTopElement(size_t i)32 CPDF_StructElement* GetTopElement(size_t i) const { return m_Kids[i].Get(); } GetPageObjNum()33 uint32_t GetPageObjNum() const { return m_pPage->GetObjNum(); } 34 ByteString GetRoleMapNameFor(const ByteString& type) const; 35 36 private: 37 using StructElementMap = std::map<RetainPtr<const CPDF_Dictionary>, 38 RetainPtr<CPDF_StructElement>, 39 std::less<>>; 40 41 void LoadPageTree(RetainPtr<const CPDF_Dictionary> pPageDict); 42 RetainPtr<CPDF_StructElement> AddPageNode( 43 RetainPtr<const CPDF_Dictionary> pDict, 44 StructElementMap* map, 45 int nLevel); 46 bool AddTopLevelNode(const CPDF_Dictionary* pDict, 47 const RetainPtr<CPDF_StructElement>& pElement); 48 49 RetainPtr<const CPDF_Dictionary> const m_pTreeRoot; 50 RetainPtr<const CPDF_Dictionary> const m_pRoleMap; 51 RetainPtr<const CPDF_Dictionary> m_pPage; 52 std::vector<RetainPtr<CPDF_StructElement>> m_Kids; 53 }; 54 55 #endif // CORE_FPDFDOC_CPDF_STRUCTTREE_H_ 56