Coverage Report

Created: 2026-03-12 06:58

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/qpdf/include/qpdf/QPDFOutlineDocumentHelper.hh
Line
Count
Source
1
// Copyright (c) 2005-2021 Jay Berkenbilt
2
// Copyright (c) 2022-2026 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 QPDFOUTLINEDOCUMENTHELPER_HH
21
#define QPDFOUTLINEDOCUMENTHELPER_HH
22
23
#include <qpdf/QPDF.hh>
24
#include <qpdf/QPDFDocumentHelper.hh>
25
#include <qpdf/QPDFNameTreeObjectHelper.hh>
26
#include <qpdf/QPDFObjGen.hh>
27
#include <qpdf/QPDFOutlineObjectHelper.hh>
28
29
#include <map>
30
#include <vector>
31
32
#include <qpdf/DLL.h>
33
34
// This is a document helper for outlines, also known as bookmarks. Outlines are discussed in
35
// section 12.3.3 of the PDF spec (ISO-32000). With the help of QPDFOutlineObjectHelper, the
36
// outlines tree is traversed, and a bidirectional map is made between pages and outlines. See also
37
// QPDFOutlineObjectHelper.
38
class QPDFOutlineDocumentHelper: public QPDFDocumentHelper
39
{
40
  public:
41
    // Get a shared document helper for a given QPDF object.
42
    //
43
    // Retrieving a document helper for a QPDF object rather than creating a new one avoids repeated
44
    // validation of the Acroform structure, which can be expensive.
45
    QPDF_DLL
46
    static QPDFOutlineDocumentHelper& get(QPDF& qpdf);
47
48
    // Re-validate the Outlines structure. This is useful if you have modified the structure of the
49
    // Outlines dictionary in a way that would invalidate the cache.
50
    //
51
    // If repair is true, the document will be repaired if possible if the validation encounters
52
    // errors.
53
    QPDF_DLL
54
    void validate(bool repair = true);
55
56
    QPDF_DLL
57
    QPDFOutlineDocumentHelper(QPDF&);
58
59
9.20k
    ~QPDFOutlineDocumentHelper() override = default;
60
61
    QPDF_DLL
62
    bool hasOutlines();
63
64
    QPDF_DLL
65
    std::vector<QPDFOutlineObjectHelper> getTopLevelOutlines();
66
67
    // If the name is a name object, look it up in the /Dests key of the document catalog. If the
68
    // name is a string, look it up in the name tree pointed to by the /Dests key of the names
69
    // dictionary.
70
    QPDF_DLL
71
    QPDFObjectHandle resolveNamedDest(QPDFObjectHandle name);
72
73
    // Return a list outlines that are known to target the specified page.
74
    QPDF_DLL
75
    std::vector<QPDFOutlineObjectHelper> getOutlinesForPage(QPDFObjGen);
76
77
    class Accessor
78
    {
79
        friend class QPDFOutlineObjectHelper;
80
81
        static bool checkSeen(QPDFOutlineDocumentHelper& dh, QPDFObjGen og);
82
    };
83
84
  private:
85
    void initializeByPage();
86
87
    class Members;
88
89
    std::shared_ptr<Members> m;
90
};
91
92
#endif // QPDFOUTLINEDOCUMENTHELPER_HH