Merge pull request #356 from selmf/std_unique

Add support for poppler-qt6 pdf backend
This commit is contained in:
Luis Ángel San Martín 2022-11-20 10:53:10 +01:00 committed by GitHub
commit 6f358e4ea3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 52 additions and 45 deletions

View File

@ -12,6 +12,7 @@ Version counting is based on semantic versioning (Major.Feature.Patch)
### All apps ### All apps
* Run logger in a dedicated thread to avoid segfaults at application shutdown * Run logger in a dedicated thread to avoid segfaults at application shutdown
* Add support for poppler-qt6 pdf backend
## 9.10 ## 9.10

View File

@ -27,38 +27,31 @@ void InitialComicInfoExtractor::extract()
#ifndef NO_PDF #ifndef NO_PDF
if (fi.suffix().compare("pdf", Qt::CaseInsensitive) == 0) { if (fi.suffix().compare("pdf", Qt::CaseInsensitive) == 0) {
#if defined Q_OS_MAC && defined USE_PDFKIT #if defined Q_OS_MAC && defined USE_PDFKIT
MacOSXPDFComic *pdfComic = new MacOSXPDFComic(); auto pdfComic = std::make_unique<MacOSXPDFComic>();
if (!pdfComic->openComic(_fileSource)) { if (!pdfComic->openComic(_fileSource)) {
delete pdfComic;
// QImage p;
// p.load(":/images/notCover.png");
// p.save(_target);
return; return;
} }
#elif defined USE_PDFIUM #elif defined USE_PDFIUM
auto pdfComic = new PdfiumComic(); auto pdfComic = std::make_unique<PdfiumComic>();
if (!pdfComic->openComic(_fileSource)) { if (!pdfComic->openComic(_fileSource)) {
delete pdfComic;
return; return;
} }
#else #else
Poppler::Document *pdfComic = Poppler::Document::load(_fileSource); #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
auto pdfComic = Poppler::Document::load(_fileSource);
#else
auto _pdfComic = Poppler::Document::load(_fileSource);
auto pdfComic = std::unique_ptr<Poppler::Document>(_pdfComic);
#endif
#endif #endif
if (!pdfComic) { if (!pdfComic) {
QLOG_WARN() << "Extracting cover: unable to open PDF file " << _fileSource; QLOG_WARN() << "Extracting cover: unable to open PDF file " << _fileSource;
// delete pdfComic; //TODO check if the delete is needed
pdfComic = 0;
// QImage p;
// p.load(":/images/notCover.png");
// p.save(_target);
return; return;
} }
#if !defined USE_PDFKIT && !defined USE_PDFIUM #if !defined USE_PDFKIT && !defined USE_PDFIUM
// poppler only, not mac // poppler only, not mac
if (pdfComic->isLocked()) { if (pdfComic->isLocked()) {
QLOG_WARN() << "Extracting cover: unable to open PDF file " << _fileSource; QLOG_WARN() << "Extracting cover: unable to open PDF file " << _fileSource;
delete pdfComic;
return; return;
} }
#endif #endif
@ -75,11 +68,7 @@ void InitialComicInfoExtractor::extract()
saveCover(_target, p); saveCover(_target, p);
} else if (_target != "") { } else if (_target != "") {
QLOG_WARN() << "Extracting cover: requested cover index greater than numPages " << _fileSource; QLOG_WARN() << "Extracting cover: requested cover index greater than numPages " << _fileSource;
// QImage p;
// p.load(":/images/notCover.png");
// p.save(_target);
} }
delete pdfComic;
} }
return; return;
} }

View File

@ -796,24 +796,27 @@ bool PDFComic::load(const QString &path, const ComicDB &comic)
void PDFComic::process() void PDFComic::process()
{ {
#if defined Q_OS_MAC && defined USE_PDFKIT #if defined Q_OS_MAC && defined USE_PDFKIT
pdfComic = new MacOSXPDFComic(); pdfComic = std::make_unique<MacOSXPDFComic>();
if (!pdfComic->openComic(_path)) { if (!pdfComic->openComic(_path)) {
delete pdfComic;
emit errorOpening(); emit errorOpening();
return; return;
} }
#elif defined USE_PDFIUM #elif defined USE_PDFIUM
pdfComic = new PdfiumComic(); pdfComic = std::make_unique<PdfiumComic>();
if (!pdfComic->openComic(_path)) { if (!pdfComic->openComic(_path)) {
delete pdfComic;
emit errorOpening(); emit errorOpening();
return; return;
} }
#else #else
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
pdfComic = Poppler::Document::load(_path); pdfComic = Poppler::Document::load(_path);
#else
auto _pdfComic = Poppler::Document::load(_path);
pdfComic = std::unique_ptr<Poppler::Document>(_pdfComic);
#endif
if (!pdfComic) { if (!pdfComic) {
// delete pdfComic;
// pdfComic = 0;
moveToThread(QCoreApplication::instance()->thread()); moveToThread(QCoreApplication::instance()->thread());
emit errorOpening(); emit errorOpening();
return; return;
@ -824,7 +827,6 @@ void PDFComic::process()
return; return;
} }
// pdfComic->setRenderHint(Poppler::Document::Antialiasing, true);
pdfComic->setRenderHint(Poppler::Document::TextAntialiasing, true); pdfComic->setRenderHint(Poppler::Document::TextAntialiasing, true);
#endif #endif
@ -853,7 +855,6 @@ void PDFComic::process()
int buffered_index = _index; int buffered_index = _index;
for (int i = buffered_index; i < nPages; i++) { for (int i = buffered_index; i < nPages; i++) {
if (_invalidated) { if (_invalidated) {
delete pdfComic;
moveToThread(QCoreApplication::instance()->thread()); moveToThread(QCoreApplication::instance()->thread());
return; return;
} }
@ -862,14 +863,12 @@ void PDFComic::process()
} }
for (int i = 0; i < buffered_index; i++) { for (int i = 0; i < buffered_index; i++) {
if (_invalidated) { if (_invalidated) {
delete pdfComic;
moveToThread(QCoreApplication::instance()->thread()); moveToThread(QCoreApplication::instance()->thread());
return; return;
} }
renderPage(i); renderPage(i);
} }
delete pdfComic;
moveToThread(QCoreApplication::instance()->thread()); moveToThread(QCoreApplication::instance()->thread());
emit imagesLoaded(); emit imagesLoaded();
} }
@ -883,10 +882,9 @@ void PDFComic::renderPage(int page)
QImage img = pdfComic->getPage(page); QImage img = pdfComic->getPage(page);
if (!img.isNull()) { if (!img.isNull()) {
#else #else
Poppler::Page *pdfpage = pdfComic->page(page); std::unique_ptr<Poppler::Page> pdfpage(pdfComic->page(page));
if (pdfpage) { if (pdfpage) {
QImage img = pdfpage->renderToImage(150, 150); QImage img = pdfpage->renderToImage(150, 150);
delete pdfpage;
#endif #endif
QByteArray ba; QByteArray ba;
QBuffer buf(&ba); QBuffer buf(&ba);

View File

@ -12,7 +12,7 @@
#include "pdf_comic.h" #include "pdf_comic.h"
#endif // NO_PDF #endif // NO_PDF
class ComicDB; class ComicDB;
//#define EXTENSIONS << "*.jpg" << "*.jpeg" << "*.png" << "*.gif" << "*.tiff" << "*.tif" << "*.bmp" Comic::getSupportedImageFormats()
//#define EXTENSIONS_LITERAL << ".jpg" << ".jpeg" << ".png" << ".gif" << ".tiff" << ".tif" << ".bmp" //Comic::getSupportedImageLiteralFormats() //#define EXTENSIONS_LITERAL << ".jpg" << ".jpeg" << ".png" << ".gif" << ".tiff" << ".tif" << ".bmp" //Comic::getSupportedImageLiteralFormats()
class Comic : public QObject class Comic : public QObject
{ {
@ -165,13 +165,14 @@ class PDFComic : public Comic
private: private:
// pdf // pdf
#if defined Q_OS_MAC && defined USE_PDFKIT #if defined Q_OS_MAC && defined USE_PDFKIT
MacOSXPDFComic *pdfComic; std::unique_ptr<MacOSXPDFComic> pdfComic;
#elif defined USE_PDFIUM #elif defined USE_PDFIUM
PdfiumComic *pdfComic; std::unique_ptr<PdfiumComic> pdfComic;
#else #else
Poppler::Document *pdfComic; std::unique_ptr<Poppler::Document> pdfComic;
#endif #endif
void renderPage(int page); void renderPage(int page);
// void run(); // void run();
public: public:

View File

@ -5,6 +5,7 @@
#include <QImage> #include <QImage>
#include <QFile> #include <QFile>
#include <QMutex> #include <QMutex>
#include <QtGlobal>
#if defined Q_OS_MAC && defined USE_PDFKIT #if defined Q_OS_MAC && defined USE_PDFKIT
class MacOSXPDFComic class MacOSXPDFComic
@ -45,6 +46,10 @@ private:
QFile pdfFile; QFile pdfFile;
}; };
#else #else
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
#include <poppler-qt6.h>
#else
#include "poppler-qt5.h" #include "poppler-qt5.h"
#endif // QT_VERSION
#endif // Q_OS_MAC #endif // Q_OS_MAC
#endif // PDF_COMIC_H #endif // PDF_COMIC_H

View File

@ -55,18 +55,31 @@ CONFIG(poppler) {
LIBS += -L$$PWD/poppler/dependencies/bin LIBS += -L$$PWD/poppler/dependencies/bin
} }
if(unix|mingw):!macx { if(unix|mingw):!macx {
!contains(QT_CONFIG, no-pkg-config):packagesExist(poppler-qt5) { greaterThan (QT_MAJOR_VERSION, 5) {
message("Using system provided installation of poppler-qt5 found by pkg-config.") !contains(QT_CONFIG, no-pkg-config):packagesExist(poppler-qt6) {
CONFIG += link_pkgconfig message("Using system provided installation of poppler-qt6 found by pkg-config.")
PKGCONFIG += poppler-qt5 CONFIG += link_pkgconfig
} else:!macx:exists(/usr/include/poppler/qt5) { PKGCONFIG += poppler-qt6
message("Using system provided installation of poppler-qt5.") } else:!macx:exists(/usr/include/poppler/qt6) {
INCLUDEPATH += /usr/include/poppler/qt5 message("Using system provided installation of poppler-qt6.")
LIBS += -lpoppler-qt5 INCLUDEPATH += /usr/include/poppler/qt6
LIBS += -lpoppler-qt6
} else {
error("Could not find poppler-qt6")
}
} else { } else {
error("Could not find poppler-qt5") !contains(QT_CONFIG, no-pkg-config):packagesExist(poppler-qt5) {
message("Using system provided installation of poppler-qt5 found by pkg-config.")
CONFIG += link_pkgconfig
PKGCONFIG += poppler-qt5
} else:!macx:exists(/usr/include/poppler/qt5) {
message("Using system provided installation of poppler-qt5.")
INCLUDEPATH += /usr/include/poppler/qt5
LIBS += -lpoppler-qt5
} else {
error("Could not find poppler-qt5")
}
} }
} }
unix:macx { unix:macx {
error (Poppler backend is currently not supported on macOS) error (Poppler backend is currently not supported on macOS)