Commit 4e89757a authored by Albert Astals Cid's avatar Albert Astals Cid
Browse files

Poppler: Use non xml API for toc if possible

The xml api will be removed in Qt6 so better to move away from it as
soon as possible
parent 88e6eadc
Pipeline #28135 passed with stage
in 12 minutes and 58 seconds
......@@ -71,6 +71,16 @@ int main()
}
" HAVE_POPPLER_0_73)
check_cxx_source_compiles("
#include <poppler-qt5.h>
int main()
{
Poppler::Document *document = nullptr;
(void)document->outline();
return 0;
}
" HAVE_POPPLER_0_74)
check_cxx_source_compiles("
#include <poppler-form.h>
#include <poppler-qt5.h>
......
......@@ -16,6 +16,9 @@
/* Defined if we have the 0.73 version of the Poppler library */
#cmakedefine HAVE_POPPLER_0_73 1
/* Defined if we have the 0.74 version of the Poppler library */
#cmakedefine HAVE_POPPLER_0_74 1
/* Defined if we have the 0.79 version of the Poppler library */
#cmakedefine HAVE_POPPLER_0_79 1
......
......@@ -54,8 +54,6 @@
#include "pdfsettings.h"
#include "ui_pdfsettingswidget.h"
#include <config-okular-poppler.h>
#include <poppler-media.h>
#ifdef HAVE_POPPLER_0_73
#include <poppler-version.h>
......@@ -859,6 +857,16 @@ const Okular::DocumentSynopsis *PDFGenerator::generateDocumentSynopsis()
if (!pdfdoc)
return nullptr;
#ifdef HAVE_POPPLER_0_74
userMutex()->lock();
const QVector<Poppler::OutlineItem> outline = pdfdoc->outline();
userMutex()->unlock();
if (outline.isEmpty())
return nullptr;
addSynopsisChildren(outline, &docSyn);
#else
userMutex()->lock();
QDomDocument *toc = pdfdoc->toc();
userMutex()->unlock();
......@@ -867,6 +875,7 @@ const Okular::DocumentSynopsis *PDFGenerator::generateDocumentSynopsis()
addSynopsisChildren(toc, &docSyn);
delete toc;
#endif
docSynopsisDirty = false;
return &docSyn;
......@@ -1653,6 +1662,36 @@ Okular::TextPage *PDFGenerator::abstractTextPage(const QList<Poppler::TextBox *>
return ktp;
}
#ifdef HAVE_POPPLER_0_74
void PDFGenerator::addSynopsisChildren(const QVector<Poppler::OutlineItem> &outlineItems, QDomNode *parentDestination)
{
for (const Poppler::OutlineItem &outlineItem : outlineItems) {
QDomElement item = docSyn.createElement(outlineItem.name());
parentDestination->appendChild(item);
item.setAttribute(QStringLiteral("ExternalFileName"), outlineItem.externalFileName());
const QSharedPointer<const Poppler::LinkDestination> outlineDestination = outlineItem.destination();
if (outlineDestination) {
const QString destinationName = outlineDestination->destinationName();
if (!destinationName.isEmpty()) {
item.setAttribute(QStringLiteral("ViewportName"), destinationName);
} else {
Okular::DocumentViewport vp;
fillViewportFromLinkDestination(vp, *outlineDestination);
item.setAttribute(QStringLiteral("Viewport"), vp.toString());
}
}
item.setAttribute(QStringLiteral("Open"), outlineItem.isOpen());
item.setAttribute(QStringLiteral("URL"), outlineItem.uri());
if (outlineItem.hasChildren())
addSynopsisChildren(outlineItem.children(), &item);
}
}
#else
void PDFGenerator::addSynopsisChildren(QDomNode *parent, QDomNode *parentDestination)
{
// keep track of the current listViewItem
......@@ -1686,6 +1725,8 @@ void PDFGenerator::addSynopsisChildren(QDomNode *parent, QDomNode *parentDestina
}
}
#endif
void PDFGenerator::addAnnotations(Poppler::Page *popplerPage, Okular::Page *page)
{
QSet<Poppler::Annotation::SubType> subtypes;
......
......@@ -15,6 +15,7 @@
#define _OKULAR_GENERATOR_PDF_H_
//#include "synctex/synctex_parser.h"
#include <config-okular-poppler.h>
#include <poppler-qt5.h>
......@@ -112,7 +113,11 @@ private:
Okular::Document::OpenResult init(QVector<Okular::Page *> &pagesVector, const QString &password);
// create the document synopsis hierarchy
#ifdef HAVE_POPPLER_0_74
void addSynopsisChildren(const QVector<Poppler::OutlineItem> &outlineItems, QDomNode *parentDestination);
#else
void addSynopsisChildren(QDomNode *parentSource, QDomNode *parentDestination);
#endif
// fetch annotations from the pdf file and add they to the page
void addAnnotations(Poppler::Page *popplerPage, Okular::Page *page);
// fetch the transition information and add it to the page
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment