1 | //======================================================================== |
2 | // |
3 | // Outline.h |
4 | // |
5 | // Copyright 2002-2003 Glyph & Cog, LLC |
6 | // |
7 | //======================================================================== |
8 | |
9 | //======================================================================== |
10 | // |
11 | // Modified under the Poppler project - http://poppler.freedesktop.org |
12 | // |
13 | // All changes made under the Poppler project to this file are licensed |
14 | // under GPL version 2 or later |
15 | // |
16 | // Copyright (C) 2005 Marco Pesenti Gritti <mpg@redhat.com> |
17 | // Copyright (C) 2016, 2018, 2021 Albert Astals Cid <aacid@kde.org> |
18 | // Copyright (C) 2019, 2020 Oliver Sander <oliver.sander@tu-dresden.de> |
19 | // Copyright (C) 2021 RM <rm+git@arcsin.org> |
20 | // Copyright (C) 2024 g10 Code GmbH, Author: Sune Stolborg Vuorela <sune@vuorela.dk> |
21 | // |
22 | // To see a description of the changes please see the Changelog file that |
23 | // came with your tarball or type make ChangeLog if you are building from git |
24 | // |
25 | //======================================================================== |
26 | |
27 | #ifndef OUTLINE_H |
28 | #define OUTLINE_H |
29 | |
30 | #include <memory> |
31 | #include <vector> |
32 | #include "Object.h" |
33 | #include "CharTypes.h" |
34 | #include "poppler_private_export.h" |
35 | |
36 | class PDFDoc; |
37 | class GooString; |
38 | class XRef; |
39 | class LinkAction; |
40 | class OutlineItem; |
41 | |
42 | //------------------------------------------------------------------------ |
43 | |
44 | class POPPLER_PRIVATE_EXPORT Outline |
45 | { |
46 | PDFDoc *doc; |
47 | XRef *xref; |
48 | Object *outlineObj; // outline dict in catalog |
49 | |
50 | public: |
51 | Outline(Object *outlineObj, XRef *xref, PDFDoc *doc); |
52 | ~Outline(); |
53 | |
54 | Outline(const Outline &) = delete; |
55 | Outline &operator=(const Outline &) = delete; |
56 | |
57 | const std::vector<OutlineItem *> *getItems() const |
58 | { |
59 | if (!items || items->empty()) { |
60 | return nullptr; |
61 | } else { |
62 | return items; |
63 | } |
64 | } |
65 | |
66 | struct OutlineTreeNode |
67 | { |
68 | std::string title; |
69 | int destPageNum; |
70 | std::vector<OutlineTreeNode> children; |
71 | }; |
72 | |
73 | // insert/remove child don't propagate changes to 'Count' up the entire |
74 | // tree |
75 | void setOutline(const std::vector<OutlineTreeNode> &nodeList); |
76 | void insertChild(const std::string &itemTitle, int destPageNum, unsigned int pos); |
77 | void removeChild(unsigned int pos); |
78 | |
79 | private: |
80 | std::vector<OutlineItem *> *items; // nullptr if document has no outline |
81 | int addOutlineTreeNodeList(const std::vector<OutlineTreeNode> &nodeList, Ref &parentRef, Ref &firstRef, Ref &lastRef); |
82 | }; |
83 | |
84 | //------------------------------------------------------------------------ |
85 | |
86 | class POPPLER_PRIVATE_EXPORT OutlineItem |
87 | { |
88 | friend Outline; |
89 | |
90 | public: |
91 | OutlineItem(const Dict *dict, Ref refA, OutlineItem *parentA, XRef *xrefA, PDFDoc *docA); |
92 | ~OutlineItem(); |
93 | OutlineItem(const OutlineItem &) = delete; |
94 | OutlineItem &operator=(const OutlineItem &) = delete; |
95 | static std::vector<OutlineItem *> *readItemList(OutlineItem *parent, const Object *firstItemRef, XRef *xrefA, PDFDoc *docA); |
96 | const std::vector<Unicode> &getTitle() const { return title; } |
97 | void setTitle(const std::string &titleA); |
98 | bool setPageDest(int i); |
99 | // OutlineItem keeps the ownership of the action |
100 | const LinkAction *getAction() const { return action.get(); } |
101 | void setStartsOpen(bool value); |
102 | bool isOpen() const { return startsOpen; } |
103 | bool hasKids(); |
104 | void open(); |
105 | const std::vector<OutlineItem *> *getKids(); |
106 | int getRefNum() const { return ref.num; } |
107 | Ref getRef() const { return ref; } |
108 | void insertChild(const std::string &itemTitle, int destPageNum, unsigned int pos); |
109 | void removeChild(unsigned int pos); |
110 | |
111 | private: |
112 | Ref ref; |
113 | OutlineItem *parent; |
114 | PDFDoc *doc; |
115 | XRef *xref; |
116 | std::vector<Unicode> title; |
117 | std::unique_ptr<LinkAction> action; |
118 | bool startsOpen; |
119 | std::vector<OutlineItem *> *kids; // nullptr if this item is closed or has no kids |
120 | }; |
121 | |
122 | #endif |
123 | |