summaryrefslogtreecommitdiff
path: root/core/fpdfdoc/cpdf_structtree.h
blob: 9f1d50e0663869c3fc8a288b53d59f8797e46c36 (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
// Copyright 2017 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_FPDFDOC_CPDF_STRUCTTREE_H_
#define CORE_FPDFDOC_CPDF_STRUCTTREE_H_

#include <map>
#include <memory>
#include <vector>

#include "core/fxcrt/retain_ptr.h"
#include "core/fxcrt/unowned_ptr.h"

class CPDF_Dictionary;
class CPDF_Document;
class CPDF_StructElement;

class CPDF_StructTree {
 public:
  static std::unique_ptr<CPDF_StructTree> LoadPage(
      const CPDF_Document* pDoc,
      const CPDF_Dictionary* pPageDict);

  explicit CPDF_StructTree(const CPDF_Document* pDoc);
  ~CPDF_StructTree();

  int CountTopElements() const;
  CPDF_StructElement* GetTopElement(int i) const;
  const CPDF_Dictionary* GetRoleMap() const { return m_pRoleMap.Get(); }
  const CPDF_Dictionary* GetPage() const { return m_pPage.Get(); }
  const CPDF_Dictionary* GetTreeRoot() const { return m_pTreeRoot.Get(); }

 private:
  void LoadPageTree(const CPDF_Dictionary* pPageDict);
  RetainPtr<CPDF_StructElement> AddPageNode(
      CPDF_Dictionary* pElement,
      std::map<CPDF_Dictionary*, RetainPtr<CPDF_StructElement>>* map,
      int nLevel);
  bool AddTopLevelNode(CPDF_Dictionary* pDict,
                       const RetainPtr<CPDF_StructElement>& pElement);

  UnownedPtr<const CPDF_Dictionary> const m_pTreeRoot;
  UnownedPtr<const CPDF_Dictionary> const m_pRoleMap;
  UnownedPtr<const CPDF_Dictionary> m_pPage;
  std::vector<RetainPtr<CPDF_StructElement>> m_Kids;
};

#endif  // CORE_FPDFDOC_CPDF_STRUCTTREE_H_