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