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