Coverage Report

Created: 2026-07-30 07:17

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/poppler/poppler/Outline.h
Line
Count
Source
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, 2026 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 "CharTypes.h"
33
#include "Ref.h"
34
#include "poppler_private_export.h"
35
36
class Dict;
37
class Object;
38
class PDFDoc;
39
class XRef;
40
class LinkAction;
41
class OutlineItem;
42
43
//------------------------------------------------------------------------
44
45
class POPPLER_PRIVATE_EXPORT Outline
46
{
47
    PDFDoc *doc;
48
    XRef *xref;
49
    Object *outlineObj; // outline dict in catalog
50
51
public:
52
    Outline(Object *outlineObj, XRef *xref, PDFDoc *doc);
53
    ~Outline();
54
55
    Outline(const Outline &) = delete;
56
    Outline &operator=(const Outline &) = delete;
57
58
    const std::vector<OutlineItem *> *getItems() const
59
0
    {
60
0
        if (!items || items->empty()) {
61
0
            return nullptr;
62
0
        }
63
0
        return items;
64
0
    }
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
0
    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
0
    const LinkAction *getAction() const { return action.get(); }
101
    void setStartsOpen(bool value);
102
0
    bool isOpen() const { return startsOpen; }
103
    bool hasKids();
104
    void open();
105
    const std::vector<OutlineItem *> *getKids();
106
0
    int getRefNum() const { return ref.num; }
107
0
    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