Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-10 10:23:51

0001 //========================================================================
0002 //
0003 // StructTreeRoot.h
0004 //
0005 // This file is licensed under the GPLv2 or later
0006 //
0007 // Copyright 2013, 2014 Igalia S.L.
0008 // Copyright 2018, 2019 Albert Astals Cid <aacid@kde.org>
0009 // Copyright 2018 Adrian Johnson <ajohnson@redneon.com>
0010 // Copyright 2018 Adam Reichold <adam.reichold@t-online.de>
0011 //
0012 //========================================================================
0013 
0014 #ifndef STRUCTTREEROOT_H
0015 #define STRUCTTREEROOT_H
0016 
0017 #include "Object.h"
0018 #include "StructElement.h"
0019 #include <map>
0020 #include <vector>
0021 
0022 class Dict;
0023 class PDFDoc;
0024 
0025 class StructTreeRoot
0026 {
0027 public:
0028     StructTreeRoot(PDFDoc *docA, Dict *rootDict);
0029     ~StructTreeRoot();
0030 
0031     StructTreeRoot &operator=(const StructTreeRoot &) = delete;
0032     StructTreeRoot(const StructTreeRoot &) = delete;
0033 
0034     PDFDoc *getDoc() { return doc; }
0035     Dict *getRoleMap() { return roleMap.isDict() ? roleMap.getDict() : nullptr; }
0036     Dict *getClassMap() { return classMap.isDict() ? classMap.getDict() : nullptr; }
0037     unsigned getNumChildren() const { return elements.size(); }
0038     const StructElement *getChild(int i) const { return elements.at(i); }
0039     StructElement *getChild(int i) { return elements.at(i); }
0040 
0041     void appendChild(StructElement *element)
0042     {
0043         if (element && element->isOk()) {
0044             elements.push_back(element);
0045         }
0046     }
0047 
0048     const StructElement *findParentElement(int key, unsigned mcid = 0) const
0049     {
0050         auto it = parentTree.find(key);
0051         if (it != parentTree.end()) {
0052             if (mcid < it->second.size()) {
0053                 return it->second[mcid].element;
0054             }
0055         }
0056         return nullptr;
0057     }
0058 
0059 private:
0060     typedef std::vector<StructElement *> ElemPtrArray;
0061 
0062     // Structure for items in /ParentTree, it keeps a mapping of
0063     // object references and pointers to StructElement objects.
0064     struct Parent
0065     {
0066         Ref ref;
0067         StructElement *element;
0068 
0069         Parent() : element(nullptr) { ref = Ref::INVALID(); }
0070         Parent(const Parent &p) = default;
0071         Parent &operator=(const Parent &) = default;
0072         ~Parent() { }
0073     };
0074 
0075     PDFDoc *doc;
0076     Object roleMap;
0077     Object classMap;
0078     ElemPtrArray elements;
0079     std::map<int, std::vector<Parent>> parentTree;
0080     std::multimap<Ref, Parent *> refToParentMap;
0081 
0082     void parse(Dict *rootDict);
0083     void parseNumberTreeNode(Dict *node);
0084     void parentTreeAdd(const Ref objectRef, StructElement *element);
0085 
0086     friend class StructElement;
0087 };
0088 
0089 #endif