File: QPDFOutlineObjectHelper.cc

package info (click to toggle)
qpdf 12.3.2-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 72,660 kB
  • sloc: cpp: 59,054; perl: 12,189; ansic: 6,809; sh: 1,231; python: 1,041; xml: 43; makefile: 42
file content (100 lines) | stat: -rw-r--r-- 2,429 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include <qpdf/QPDFOutlineObjectHelper.hh>

#include <qpdf/QPDFObjectHandle_private.hh>
#include <qpdf/QPDFOutlineDocumentHelper.hh>
#include <qpdf/QTC.hh>

QPDFOutlineObjectHelper::Members::Members(QPDFOutlineDocumentHelper& dh) :
    dh(dh)
{
}

QPDFOutlineObjectHelper::QPDFOutlineObjectHelper(
    QPDFObjectHandle a_oh, QPDFOutlineDocumentHelper& dh, int depth) :
    QPDFObjectHelper(a_oh),
    m(new Members(dh))
{
    if (depth > 50) {
        // Not exercised in test suite, but was tested manually by temporarily changing max depth
        // to 1.
        return;
    }
    if (QPDFOutlineDocumentHelper::Accessor::checkSeen(m->dh, a_oh.getObjGen())) {
        a_oh.warn("Loop detected loop in /Outlines tree");
        return;
    }

    QPDFObjGen::set children;
    QPDFObjectHandle cur = a_oh.getKey("/First");
    while (!cur.null() && cur.isIndirect()) {
        if (!children.add(cur)) {
            cur.warn("Loop detected loop in /Outlines tree");
            break;
        }
        QPDFOutlineObjectHelper new_ooh(cur, dh, 1 + depth);
        new_ooh.m->parent = std::make_shared<QPDFOutlineObjectHelper>(*this);
        m->kids.emplace_back(new_ooh);
        cur = cur.getKey("/Next");
    }
}

std::shared_ptr<QPDFOutlineObjectHelper>
QPDFOutlineObjectHelper::getParent()
{
    return m->parent;
}

std::vector<QPDFOutlineObjectHelper>
QPDFOutlineObjectHelper::getKids()
{
    return m->kids;
}

QPDFObjectHandle
QPDFOutlineObjectHelper::getDest()
{
    auto dest = get("/Dest");
    if (dest.null()) {
        auto const& A = get("/A");
        if (Name(A["/S"]) == "/GoTo") {
            dest = A["/D"];
        }
    }
    if (dest.null()) {
        return QPDFObjectHandle::newNull();
    }
    if (dest.isName() || dest.isString()) {
        return m->dh.resolveNamedDest(dest);
    }
    return dest;
}

QPDFObjectHandle
QPDFOutlineObjectHelper::getDestPage()
{
    QPDFObjectHandle dest = getDest();
    if (!dest.empty() && dest.isArray()) {
        return dest.getArrayItem(0);
    }
    return QPDFObjectHandle::newNull();
}

int
QPDFOutlineObjectHelper::getCount()
{
    int count = 0;
    if (oh().hasKey("/Count")) {
        count = oh().getKey("/Count").getIntValueAsInt();
    }
    return count;
}

std::string
QPDFOutlineObjectHelper::getTitle()
{
    std::string result;
    if (oh().hasKey("/Title")) {
        result = oh().getKey("/Title").getUTF8Value();
    }
    return result;
}