2018-12-19 02:08:53 +00:00
|
|
|
#include <qpdf/QPDFOutlineDocumentHelper.hh>
|
2022-02-04 21:31:31 +00:00
|
|
|
|
2018-12-19 02:08:53 +00:00
|
|
|
#include <qpdf/QTC.hh>
|
|
|
|
|
|
|
|
QPDFOutlineDocumentHelper::QPDFOutlineDocumentHelper(QPDF& qpdf) :
|
|
|
|
QPDFDocumentHelper(qpdf),
|
|
|
|
m(new Members())
|
|
|
|
{
|
|
|
|
QPDFObjectHandle root = qpdf.getRoot();
|
|
|
|
if (!root.hasKey("/Outlines")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
QPDFObjectHandle outlines = root.getKey("/Outlines");
|
|
|
|
if (!(outlines.isDictionary() && outlines.hasKey("/First"))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
QPDFObjectHandle cur = outlines.getKey("/First");
|
2023-01-05 12:20:37 +00:00
|
|
|
QPDFObjGen::set seen;
|
|
|
|
while (!cur.isNull() && seen.add(cur)) {
|
2018-12-19 02:08:53 +00:00
|
|
|
m->outlines.push_back(QPDFOutlineObjectHelper::Accessor::create(cur, *this, 1));
|
|
|
|
cur = cur.getKey("/Next");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
QPDFOutlineDocumentHelper::hasOutlines()
|
|
|
|
{
|
|
|
|
return !m->outlines.empty();
|
|
|
|
}
|
|
|
|
|
2019-07-03 17:34:02 +00:00
|
|
|
std::vector<QPDFOutlineObjectHelper>
|
2018-12-19 02:08:53 +00:00
|
|
|
QPDFOutlineDocumentHelper::getTopLevelOutlines()
|
|
|
|
{
|
|
|
|
return m->outlines;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
QPDFOutlineDocumentHelper::initializeByPage()
|
|
|
|
{
|
|
|
|
std::list<QPDFOutlineObjectHelper> queue;
|
|
|
|
queue.insert(queue.end(), m->outlines.begin(), m->outlines.end());
|
|
|
|
|
|
|
|
while (!queue.empty()) {
|
|
|
|
QPDFOutlineObjectHelper oh = queue.front();
|
|
|
|
queue.pop_front();
|
|
|
|
m->by_page[oh.getDestPage().getObjGen()].push_back(oh);
|
2019-07-03 17:34:02 +00:00
|
|
|
std::vector<QPDFOutlineObjectHelper> kids = oh.getKids();
|
2018-12-19 02:08:53 +00:00
|
|
|
queue.insert(queue.end(), kids.begin(), kids.end());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-03 17:34:02 +00:00
|
|
|
std::vector<QPDFOutlineObjectHelper>
|
2018-12-19 02:08:53 +00:00
|
|
|
QPDFOutlineDocumentHelper::getOutlinesForPage(QPDFObjGen const& og)
|
|
|
|
{
|
|
|
|
if (m->by_page.empty()) {
|
|
|
|
initializeByPage();
|
|
|
|
}
|
2019-07-03 17:34:02 +00:00
|
|
|
std::vector<QPDFOutlineObjectHelper> result;
|
2018-12-19 02:08:53 +00:00
|
|
|
if (m->by_page.count(og)) {
|
|
|
|
result = m->by_page[og];
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
QPDFObjectHandle
|
|
|
|
QPDFOutlineDocumentHelper::resolveNamedDest(QPDFObjectHandle name)
|
|
|
|
{
|
|
|
|
QPDFObjectHandle result;
|
|
|
|
if (name.isName()) {
|
|
|
|
if (!m->dest_dict.isInitialized()) {
|
2024-07-13 10:00:19 +00:00
|
|
|
m->dest_dict = qpdf.getRoot().getKey("/Dests");
|
2018-12-19 02:08:53 +00:00
|
|
|
}
|
2024-07-13 10:00:19 +00:00
|
|
|
QTC::TC("qpdf", "QPDFOutlineDocumentHelper name named dest");
|
2024-07-25 09:22:35 +00:00
|
|
|
result = m->dest_dict.getKeyIfDict(name.getName());
|
2018-12-19 02:08:53 +00:00
|
|
|
} else if (name.isString()) {
|
2024-07-13 10:00:19 +00:00
|
|
|
if (!m->names_dest) {
|
|
|
|
auto dests = qpdf.getRoot().getKey("/Names").getKeyIfDict("/Dests");
|
|
|
|
if (dests.isDictionary()) {
|
|
|
|
m->names_dest = std::make_shared<QPDFNameTreeObjectHelper>(dests, qpdf);
|
2018-12-19 02:08:53 +00:00
|
|
|
}
|
|
|
|
}
|
2024-07-13 10:00:19 +00:00
|
|
|
if (m->names_dest) {
|
2018-12-19 02:08:53 +00:00
|
|
|
if (m->names_dest->findObject(name.getUTF8Value(), result)) {
|
|
|
|
QTC::TC("qpdf", "QPDFOutlineDocumentHelper string named dest");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!result.isInitialized()) {
|
2024-07-13 10:00:19 +00:00
|
|
|
return QPDFObjectHandle::newNull();
|
2018-12-19 02:08:53 +00:00
|
|
|
}
|
2024-07-13 11:14:51 +00:00
|
|
|
if (result.isDictionary()) {
|
|
|
|
QTC::TC("qpdf", "QPDFOutlineDocumentHelper named dest dictionary");
|
|
|
|
return result.getKey("/D");
|
|
|
|
}
|
2018-12-19 02:08:53 +00:00
|
|
|
return result;
|
|
|
|
}
|