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 // 21 // To see a description of the changes please see the Changelog file that 22 // came with your tarball or type make ChangeLog if you are building from git 23 // 24 //======================================================================== 25 26 #ifndef OUTLINE_H 27 #define OUTLINE_H 28 29 #include <memory> 30 #include "Object.h" 31 #include "CharTypes.h" 32 #include "poppler_private_export.h" 33 34 class PDFDoc; 35 class GooString; 36 class XRef; 37 class LinkAction; 38 class OutlineItem; 39 40 //------------------------------------------------------------------------ 41 42 class POPPLER_PRIVATE_EXPORT Outline 43 { 44 PDFDoc *doc; 45 XRef *xref; 46 Object *outlineObj; // outline dict in catalog 47 48 public: 49 Outline(Object *outlineObj, XRef *xref, PDFDoc *doc); 50 ~Outline(); 51 52 Outline(const Outline &) = delete; 53 Outline &operator=(const Outline &) = delete; 54 getItems()55 const std::vector<OutlineItem *> *getItems() const 56 { 57 if (!items || items->empty()) 58 return nullptr; 59 else 60 return items; 61 } 62 63 struct OutlineTreeNode 64 { 65 std::string title; 66 int destPageNum; 67 std::vector<OutlineTreeNode> children; 68 }; 69 70 // insert/remove child don't propagate changes to 'Count' up the entire 71 // tree 72 void setOutline(const std::vector<OutlineTreeNode> &nodeList); 73 void insertChild(const std::string &itemTitle, int destPageNum, unsigned int pos); 74 void removeChild(unsigned int pos); 75 76 private: 77 std::vector<OutlineItem *> *items; // nullptr if document has no outline 78 int addOutlineTreeNodeList(const std::vector<OutlineTreeNode> &nodeList, Ref &parentRef, Ref &firstRef, Ref &lastRef); 79 }; 80 81 //------------------------------------------------------------------------ 82 83 class POPPLER_PRIVATE_EXPORT OutlineItem 84 { 85 friend Outline; 86 87 public: 88 OutlineItem(const Dict *dict, Ref refA, OutlineItem *parentA, XRef *xrefA, PDFDoc *docA); 89 ~OutlineItem(); 90 OutlineItem(const OutlineItem &) = delete; 91 OutlineItem &operator=(const OutlineItem &) = delete; 92 static std::vector<OutlineItem *> *readItemList(OutlineItem *parent, const Object *firstItemRef, XRef *xrefA, PDFDoc *docA); getTitle()93 const Unicode *getTitle() const { return title; } 94 void setTitle(const std::string &titleA); getTitleLength()95 int getTitleLength() const { return titleLen; } 96 bool setPageDest(int i); 97 // OutlineItem keeps the ownership of the action getAction()98 const LinkAction *getAction() const { return action.get(); } 99 void setStartsOpen(bool value); isOpen()100 bool isOpen() const { return startsOpen; } 101 bool hasKids(); 102 void open(); 103 const std::vector<OutlineItem *> *getKids(); getRefNum()104 int getRefNum() const { return ref.num; } getRef()105 Ref getRef() const { return ref; } 106 void insertChild(const std::string &itemTitle, int destPageNum, unsigned int pos); 107 void removeChild(unsigned int pos); 108 109 private: 110 Ref ref; 111 OutlineItem *parent; 112 PDFDoc *doc; 113 XRef *xref; 114 Unicode *title; 115 int titleLen; 116 std::unique_ptr<LinkAction> action; 117 bool startsOpen; 118 std::vector<OutlineItem *> *kids; // nullptr if this item is closed or has no kids 119 }; 120 121 #endif 122