2018-12-19 02:08:53 +00:00
|
|
|
#include <qpdf/QPDFOutlineObjectHelper.hh>
|
2022-02-04 21:31:31 +00:00
|
|
|
|
2018-12-19 02:08:53 +00:00
|
|
|
#include <qpdf/QPDFOutlineDocumentHelper.hh>
|
|
|
|
#include <qpdf/QTC.hh>
|
|
|
|
|
|
|
|
QPDFOutlineObjectHelper::Members::Members(QPDFOutlineDocumentHelper& dh) :
|
|
|
|
dh(dh)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QPDFOutlineObjectHelper::QPDFOutlineObjectHelper(
|
|
|
|
QPDFObjectHandle oh, QPDFOutlineDocumentHelper& dh, int depth) :
|
|
|
|
QPDFObjectHelper(oh),
|
|
|
|
m(new Members(dh))
|
|
|
|
{
|
2022-04-02 21:14:10 +00:00
|
|
|
if (depth > 50) {
|
2023-05-27 17:19:52 +00:00
|
|
|
// Not exercised in test suite, but was tested manually by temporarily changing max depth
|
|
|
|
// to 1.
|
2018-12-19 02:08:53 +00:00
|
|
|
return;
|
|
|
|
}
|
2023-05-21 17:35:09 +00:00
|
|
|
if (QPDFOutlineDocumentHelper::Accessor::checkSeen(m->dh, this->oh.getObjGen())) {
|
2018-12-19 02:08:53 +00:00
|
|
|
QTC::TC("qpdf", "QPDFOutlineObjectHelper loop");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-06-29 11:38:07 +00:00
|
|
|
QPDFObjGen::set children;
|
2018-12-19 02:08:53 +00:00
|
|
|
QPDFObjectHandle cur = oh.getKey("/First");
|
2024-06-29 11:38:07 +00:00
|
|
|
while (!cur.isNull() && children.add(cur)) {
|
2018-12-19 02:08:53 +00:00
|
|
|
QPDFOutlineObjectHelper new_ooh(cur, dh, 1 + depth);
|
2022-04-09 18:35:56 +00:00
|
|
|
new_ooh.m->parent = std::make_shared<QPDFOutlineObjectHelper>(*this);
|
2023-05-21 13:42:34 +00:00
|
|
|
m->kids.push_back(new_ooh);
|
2018-12-19 02:08:53 +00:00
|
|
|
cur = cur.getKey("/Next");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-09 18:35:56 +00:00
|
|
|
std::shared_ptr<QPDFOutlineObjectHelper>
|
2018-12-19 02:08:53 +00:00
|
|
|
QPDFOutlineObjectHelper::getParent()
|
|
|
|
{
|
2023-05-21 13:42:34 +00:00
|
|
|
return m->parent;
|
2018-12-19 02:08:53 +00:00
|
|
|
}
|
|
|
|
|
2019-07-03 17:34:02 +00:00
|
|
|
std::vector<QPDFOutlineObjectHelper>
|
2018-12-19 02:08:53 +00:00
|
|
|
QPDFOutlineObjectHelper::getKids()
|
|
|
|
{
|
2023-05-21 13:42:34 +00:00
|
|
|
return m->kids;
|
2018-12-19 02:08:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QPDFObjectHandle
|
|
|
|
QPDFOutlineObjectHelper::getDest()
|
|
|
|
{
|
|
|
|
QPDFObjectHandle dest;
|
|
|
|
QPDFObjectHandle A;
|
2022-04-02 21:14:10 +00:00
|
|
|
if (this->oh.hasKey("/Dest")) {
|
2018-12-19 02:08:53 +00:00
|
|
|
QTC::TC("qpdf", "QPDFOutlineObjectHelper direct dest");
|
|
|
|
dest = this->oh.getKey("/Dest");
|
2022-04-02 21:14:10 +00:00
|
|
|
} else if (
|
|
|
|
(A = this->oh.getKey("/A")).isDictionary() && A.getKey("/S").isName() &&
|
|
|
|
(A.getKey("/S").getName() == "/GoTo") && A.hasKey("/D")) {
|
2018-12-19 02:08:53 +00:00
|
|
|
QTC::TC("qpdf", "QPDFOutlineObjectHelper action dest");
|
|
|
|
dest = A.getKey("/D");
|
|
|
|
}
|
2022-04-02 21:14:10 +00:00
|
|
|
if (!dest.isInitialized()) {
|
2018-12-19 02:08:53 +00:00
|
|
|
dest = QPDFObjectHandle::newNull();
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
if (dest.isName() || dest.isString()) {
|
2018-12-19 02:08:53 +00:00
|
|
|
QTC::TC("qpdf", "QPDFOutlineObjectHelper named dest");
|
2023-05-21 13:42:34 +00:00
|
|
|
dest = m->dh.resolveNamedDest(dest);
|
2018-12-19 02:08:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return dest;
|
|
|
|
}
|
|
|
|
|
|
|
|
QPDFObjectHandle
|
|
|
|
QPDFOutlineObjectHelper::getDestPage()
|
|
|
|
{
|
|
|
|
QPDFObjectHandle dest = getDest();
|
2022-04-02 21:14:10 +00:00
|
|
|
if ((dest.isArray()) && (dest.getArrayNItems() > 0)) {
|
2018-12-19 02:08:53 +00:00
|
|
|
return dest.getArrayItem(0);
|
|
|
|
}
|
|
|
|
return QPDFObjectHandle::newNull();
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
QPDFOutlineObjectHelper::getCount()
|
|
|
|
{
|
|
|
|
int count = 0;
|
2022-04-02 21:14:10 +00:00
|
|
|
if (this->oh.hasKey("/Count")) {
|
2019-06-21 03:35:23 +00:00
|
|
|
count = this->oh.getKey("/Count").getIntValueAsInt();
|
2018-12-19 02:08:53 +00:00
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string
|
|
|
|
QPDFOutlineObjectHelper::getTitle()
|
|
|
|
{
|
|
|
|
std::string result;
|
2022-04-02 21:14:10 +00:00
|
|
|
if (this->oh.hasKey("/Title")) {
|
2018-12-19 02:08:53 +00:00
|
|
|
result = this->oh.getKey("/Title").getUTF8Value();
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|