Commit b15accd0 authored by Mahmoud Khalil's avatar Mahmoud Khalil Committed by Albert Astals Cid
Browse files

Checks whether the pdf is broken or not

This commit adds support for the to be added functionality in Poppler
which detects whether or not the Xref Table has been reconstructed
parent 1c349f54
Pipeline #62000 passed with stage
in 9 minutes and 13 seconds
......@@ -35,6 +35,16 @@ int main()
}
" HAVE_POPPLER_FANCY_SIGNATURE)
check_cxx_source_compiles("
#include <poppler-qt5.h>
int main()
{
Poppler::Document *doc = Poppler::Document::load(\"\", nullptr, nullptr);
doc->xrefWasReconstructed();
return 0;
}
" HAVE_POPPLER_RECONSTRUCTION_CALLBACK)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/config-okular-poppler.h.cmake
${CMAKE_CURRENT_BINARY_DIR}/config-okular-poppler.h
......
......@@ -6,3 +6,7 @@
/* Defined if we have the pdf fancy signature feature in the Poppler library */
#cmakedefine HAVE_POPPLER_FANCY_SIGNATURE 1
/* Defined if we have Poppler version that notifies for XRef Table reconstruction */
#cmakedefine HAVE_POPPLER_RECONSTRUCTION_CALLBACK 1
......@@ -66,6 +66,8 @@
#include "pdfsignatureutils.h"
#include "popplerembeddedfile.h"
#include <functional>
Q_DECLARE_METATYPE(Poppler::Annotation *)
Q_DECLARE_METATYPE(Poppler::FontInfo)
Q_DECLARE_METATYPE(const Poppler::LinkMovie *)
......@@ -546,6 +548,7 @@ PDFGenerator::PDFGenerator(QObject *parent, const QVariantList &args)
: Generator(parent, args)
, pdfdoc(nullptr)
, docSynopsisDirty(true)
, xrefReconstructed(false)
, docEmbeddedFilesDirty(true)
, nextFontPage(0)
, annotProxy(nullptr)
......@@ -624,6 +627,16 @@ Okular::Document::OpenResult PDFGenerator::init(QVector<Okular::Page *> &pagesVe
}
}
xrefReconstructed = false;
#ifdef HAVE_POPPLER_RECONSTRUCTION_CALLBACK
if (pdfdoc->xrefWasReconstructed()) {
xrefReconstructionHandler();
} else {
std::function<void()> cb = std::bind(&PDFGenerator::xrefReconstructionHandler, this);
pdfdoc->setXRefReconstructedCallback(cb);
}
#endif
// build Pages (currentPage was set -1 by deletePages)
int pageCount = pdfdoc->numPages();
if (pageCount < 0) {
......@@ -1931,6 +1944,15 @@ Okular::CertificateStore *PDFGenerator::certificateStore() const
#endif
}
void PDFGenerator::xrefReconstructionHandler()
{
if (!xrefReconstructed) {
qCDebug(OkularPdfDebug) << "XRef Table of the document has been reconstructed";
xrefReconstructed = true;
emit warning(i18n("Some errors were found in the document, Okular might not be able to show the content correctly"), 5000);
}
}
#include "generator_pdf.moc"
Q_LOGGING_CATEGORY(OkularPdfDebug, "org.kde.okular.generators.pdf", QtWarningMsg)
......
......@@ -136,8 +136,11 @@ private:
// poppler dependent stuff
Poppler::Document *pdfdoc;
void xrefReconstructionHandler();
// misc variables for document info and synopsis caching
bool docSynopsisDirty;
bool xrefReconstructed;
Okular::DocumentSynopsis docSyn;
mutable bool docEmbeddedFilesDirty;
mutable QList<Okular::EmbeddedFile *> docEmbeddedFiles;
......
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