Coverage Report

Created: 2025-12-05 06:54

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/qpdf/include/qpdf/QPDFOutlineObjectHelper.hh
Line
Count
Source
1
// Copyright (c) 2005-2021 Jay Berkenbilt
2
// Copyright (c) 2022-2025 Jay Berkenbilt and Manfred Holger
3
//
4
// This file is part of qpdf.
5
//
6
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
7
// in compliance with the License. You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing, software distributed under the License
12
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13
// or implied. See the License for the specific language governing permissions and limitations under
14
// the License.
15
//
16
// Versions of qpdf prior to version 7 were released under the terms of version 2.0 of the Artistic
17
// License. At your option, you may continue to consider qpdf to be licensed under those terms.
18
// Please see the manual for additional information.
19
20
#ifndef QPDFOUTLINEOBJECTHELPER_HH
21
#define QPDFOUTLINEOBJECTHELPER_HH
22
23
#include <qpdf/QPDFObjGen.hh>
24
#include <qpdf/QPDFObjectHelper.hh>
25
#include <vector>
26
27
class QPDFOutlineDocumentHelper;
28
29
#include <qpdf/DLL.h>
30
31
// This is an object helper for outline items. Outlines, also known as bookmarks, are described in
32
// section 12.3.3 of the PDF spec (ISO-32000). See comments below for details.
33
class QPDFOutlineObjectHelper: public QPDFObjectHelper
34
{
35
  public:
36
    ~QPDFOutlineObjectHelper() override
37
0
    {
38
0
        // This must be cleared explicitly to avoid circular references that prevent cleanup of
39
0
        // shared pointers.
40
0
        m->parent = nullptr;
41
0
    }
42
43
    // All constructors are private. You can only create one of these using
44
    // QPDFOutlineDocumentHelper.
45
46
    // Return parent pointer. Returns a null pointer if this is a top-level outline.
47
    QPDF_DLL
48
    std::shared_ptr<QPDFOutlineObjectHelper> getParent();
49
50
    // Return children as a list.
51
    QPDF_DLL
52
    std::vector<QPDFOutlineObjectHelper> getKids();
53
54
    // Return the destination, regardless of whether it is named or explicit and whether it is
55
    // directly provided or in a GoTo action. Returns a null object if the destination can't be
56
    // determined. Named destinations can be resolved using the older root /Dest dictionary or the
57
    // current names tree.
58
    QPDF_DLL
59
    QPDFObjectHandle getDest();
60
61
    // Return the page that the outline points to. Returns a null object if the destination page
62
    // can't be determined.
63
    QPDF_DLL
64
    QPDFObjectHandle getDestPage();
65
66
    // Returns the value of /Count as present in the object, or 0 if not present. If count is
67
    // positive, the outline is open. If negative, it is closed. Either way, the absolute value is
68
    // the number of descendant items that would be visible if this were open.
69
    QPDF_DLL
70
    int getCount();
71
72
    // Returns the title as a UTF-8 string. Returns an empty string if there is no title.
73
    QPDF_DLL
74
    std::string getTitle();
75
76
    class Accessor
77
    {
78
        friend class QPDFOutlineDocumentHelper;
79
80
        static QPDFOutlineObjectHelper
81
        create(QPDFObjectHandle oh, QPDFOutlineDocumentHelper& dh, int depth)
82
0
        {
83
0
            return {oh, dh, depth};
84
0
        }
85
    };
86
87
  private:
88
    QPDFOutlineObjectHelper(QPDFObjectHandle, QPDFOutlineDocumentHelper&, int);
89
90
    class Members
91
    {
92
        friend class QPDFOutlineObjectHelper;
93
94
      public:
95
        ~Members() = default;
96
97
      private:
98
        Members(QPDFOutlineDocumentHelper& dh);
99
        Members(Members const&) = delete;
100
101
        QPDFOutlineDocumentHelper& dh;
102
        std::shared_ptr<QPDFOutlineObjectHelper> parent;
103
        std::vector<QPDFOutlineObjectHelper> kids;
104
    };
105
106
    std::shared_ptr<Members> m;
107
};
108
109
#endif // QPDFOUTLINEOBJECTHELPER_HH