Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //========================================================================
0002 //
0003 // Outline.h
0004 //
0005 // Copyright 2002-2003 Glyph & Cog, LLC
0006 //
0007 //========================================================================
0008 
0009 //========================================================================
0010 //
0011 // Modified under the Poppler project - http://poppler.freedesktop.org
0012 //
0013 // All changes made under the Poppler project to this file are licensed
0014 // under GPL version 2 or later
0015 //
0016 // Copyright (C) 2005 Marco Pesenti Gritti <mpg@redhat.com>
0017 // Copyright (C) 2016, 2018, 2021 Albert Astals Cid <aacid@kde.org>
0018 // Copyright (C) 2019, 2020 Oliver Sander <oliver.sander@tu-dresden.de>
0019 // Copyright (C) 2021 RM <rm+git@arcsin.org>
0020 //
0021 // To see a description of the changes please see the Changelog file that
0022 // came with your tarball or type make ChangeLog if you are building from git
0023 //
0024 //========================================================================
0025 
0026 #ifndef OUTLINE_H
0027 #define OUTLINE_H
0028 
0029 #include <memory>
0030 #include "Object.h"
0031 #include "CharTypes.h"
0032 #include "poppler_private_export.h"
0033 
0034 class PDFDoc;
0035 class GooString;
0036 class XRef;
0037 class LinkAction;
0038 class OutlineItem;
0039 
0040 //------------------------------------------------------------------------
0041 
0042 class POPPLER_PRIVATE_EXPORT Outline
0043 {
0044     PDFDoc *doc;
0045     XRef *xref;
0046     Object *outlineObj; // outline dict in catalog
0047 
0048 public:
0049     Outline(Object *outlineObj, XRef *xref, PDFDoc *doc);
0050     ~Outline();
0051 
0052     Outline(const Outline &) = delete;
0053     Outline &operator=(const Outline &) = delete;
0054 
0055     const std::vector<OutlineItem *> *getItems() const
0056     {
0057         if (!items || items->empty()) {
0058             return nullptr;
0059         } else {
0060             return items;
0061         }
0062     }
0063 
0064     struct OutlineTreeNode
0065     {
0066         std::string title;
0067         int destPageNum;
0068         std::vector<OutlineTreeNode> children;
0069     };
0070 
0071     // insert/remove child don't propagate changes to 'Count' up the entire
0072     // tree
0073     void setOutline(const std::vector<OutlineTreeNode> &nodeList);
0074     void insertChild(const std::string &itemTitle, int destPageNum, unsigned int pos);
0075     void removeChild(unsigned int pos);
0076 
0077 private:
0078     std::vector<OutlineItem *> *items; // nullptr if document has no outline
0079     int addOutlineTreeNodeList(const std::vector<OutlineTreeNode> &nodeList, Ref &parentRef, Ref &firstRef, Ref &lastRef);
0080 };
0081 
0082 //------------------------------------------------------------------------
0083 
0084 class POPPLER_PRIVATE_EXPORT OutlineItem
0085 {
0086     friend Outline;
0087 
0088 public:
0089     OutlineItem(const Dict *dict, Ref refA, OutlineItem *parentA, XRef *xrefA, PDFDoc *docA);
0090     ~OutlineItem();
0091     OutlineItem(const OutlineItem &) = delete;
0092     OutlineItem &operator=(const OutlineItem &) = delete;
0093     static std::vector<OutlineItem *> *readItemList(OutlineItem *parent, const Object *firstItemRef, XRef *xrefA, PDFDoc *docA);
0094     const Unicode *getTitle() const { return title; }
0095     void setTitle(const std::string &titleA);
0096     int getTitleLength() const { return titleLen; }
0097     bool setPageDest(int i);
0098     // OutlineItem keeps the ownership of the action
0099     const LinkAction *getAction() const { return action.get(); }
0100     void setStartsOpen(bool value);
0101     bool isOpen() const { return startsOpen; }
0102     bool hasKids();
0103     void open();
0104     const std::vector<OutlineItem *> *getKids();
0105     int getRefNum() const { return ref.num; }
0106     Ref getRef() const { return ref; }
0107     void insertChild(const std::string &itemTitle, int destPageNum, unsigned int pos);
0108     void removeChild(unsigned int pos);
0109 
0110 private:
0111     Ref ref;
0112     OutlineItem *parent;
0113     PDFDoc *doc;
0114     XRef *xref;
0115     Unicode *title;
0116     int titleLen;
0117     std::unique_ptr<LinkAction> action;
0118     bool startsOpen;
0119     std::vector<OutlineItem *> *kids; // nullptr if this item is closed or has no kids
0120 };
0121 
0122 #endif