summaryrefslogtreecommitdiff
path: root/poppler/StructTreeRoot.h
blob: f42cdd53d3e073c6a5fc1bc9591bf74fe61fca3a (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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//========================================================================
//
// StructTreeRoot.h
//
// This file is licensed under the GPLv2 or later
//
// Copyright 2013 Igalia S.L.
//
//========================================================================

#ifndef STRUCTTREEROOT_H
#define STRUCTTREEROOT_H

#ifdef USE_GCC_PRAGMAS
#pragma interface
#endif

#include "goo/gtypes.h"
#include "Object.h"
#include "StructElement.h"
#include <vector>

class Dict;
class PDFDoc;


class StructTreeRoot
{
public:
  StructTreeRoot(PDFDoc *docA, Dict *rootDict);
  ~StructTreeRoot();

  PDFDoc *getDoc() { return doc; }
  Dict *getRoleMap() { return roleMap.isDict() ? roleMap.getDict() : NULL; }
  Dict *getClassMap() { return classMap.isDict() ? classMap.getDict() : NULL; }
  unsigned getNumChildren() const { return elements.size(); }
  const StructElement *getChild(int i) const { return elements.at(i); }
  StructElement *getChild(int i) { return elements.at(i); }

  void appendChild(StructElement *element) {
    if (element && element->isOk()) {
      elements.push_back(element);
    }
  }

  const StructElement *findParentElement(unsigned index) const {
    if (index < parentTree.size() && parentTree[index].size() == 1) {
      return parentTree[index][0].element;
    }
    return NULL;
  }

private:
  typedef std::vector<StructElement*> ElemPtrArray;

  // Structure for items in /ParentTree, it keeps a mapping of
  // object references and pointers to StructElement objects.
  struct Parent {
    Ref            ref;
    StructElement *element;

    Parent(): element(NULL) { ref.num = ref.gen = -1; }
    Parent(const Parent &p): element(p.element) {
      ref.num = p.ref.num;
      ref.gen = p.ref.gen;
    }
    ~Parent() {}
  };

  PDFDoc *doc;
  Object roleMap;
  Object classMap;
  ElemPtrArray elements;
  std::vector< std::vector<Parent> > parentTree;

  void parse(Dict *rootDict);
  void parentTreeAdd(const Ref &objectRef, StructElement *element);

  friend class StructElement;
};

#endif