From 464a3b6649e47b5bedc35d06eca0dbf34ba30481 Mon Sep 17 00:00:00 2001 From: Felix Kauselmann <2039670+selmf@users.noreply.github.com> Date: Fri, 21 Oct 2016 22:21:32 +0200 Subject: [PATCH] Add no_pdf build option --- YACReader/YACReader.pro | 26 +++--- YACReaderLibrary/YACReaderLibrary.pro | 17 ++-- YACReaderLibrary/library_creator.cpp | 115 +++++++++++++------------- common/comic.cpp | 28 +++++-- common/comic.h | 6 +- common/pdf_comic.cpp | 2 +- common/pdf_comic.h | 2 +- 7 files changed, 112 insertions(+), 84 deletions(-) diff --git a/YACReader/YACReader.pro b/YACReader/YACReader.pro index ce134a66..fcb0530e 100644 --- a/YACReader/YACReader.pro +++ b/YACReader/YACReader.pro @@ -58,16 +58,22 @@ win32 { } unix:!macx{ -!CONFIG(pdfium){ -INCLUDEPATH += /usr/include/poppler/qt5 -LIBS += -L/usr/lib -lpoppler-qt5 -} else { - DEFINES += "USE_PDFIUM" - INCLUDEPATH += /usr/include/pdfium - LIBS += -L/usr/lib/pdfium -Wl,--start-group -lpdfium -lfpdfapi -lfxge -lfpdfdoc \ - -lfxcrt -lfx_agg -lfxcodec -lfx_lpng -lfx_libopenjpeg -lfx_lcms2 -ljpeg \ - -lfx_zlib -lfdrm -lfxedit -lformfiller -lpdfwindow -lpdfium -lbigint -ljavascript \ - -lfxedit -Wl,--end-group -lfreetype + !CONFIG(no_pdf){ + !CONFIG(pdfium){ + INCLUDEPATH += /usr/include/poppler/qt5 + LIBS += -L/usr/lib -lpoppler-qt5 + } else { + #static pdfium libraries have to be included *before* dynamic libraries + DEFINES += "USE_PDFIUM" + INCLUDEPATH += /usr/include/pdfium + LIBS += -L/usr/lib/pdfium -Wl,--start-group -lpdfium -lfpdfapi -lfxge -lfpdfdoc \ + -lfxcrt -lfx_agg -lfxcodec -lfx_lpng -lfx_libopenjpeg -lfx_lcms2 -ljpeg \ + -lfx_zlib -lfdrm -lfxedit -lformfiller -lpdfwindow -lpdfium -lbigint -ljavascript \ + -lfxedit -Wl,--end-group -lfreetype + } + } +else { + DEFINES += "NO_PDF" } !CONFIG(no_opengl) { diff --git a/YACReaderLibrary/YACReaderLibrary.pro b/YACReaderLibrary/YACReaderLibrary.pro index 81356f40..08a6e1c2 100644 --- a/YACReaderLibrary/YACReaderLibrary.pro +++ b/YACReaderLibrary/YACReaderLibrary.pro @@ -46,18 +46,23 @@ win32 { } unix:!macx{ -!CONFIG(pdfium) { +!CONFIG(no_pdf){ + !CONFIG(pdfium){ INCLUDEPATH += /usr/include/poppler/qt5 LIBS += -L/usr/lib -lpoppler-qt5 - } - else { - DEFINES += "USE_PDFIUM" - INCLUDEPATH += /usr/include/pdfium - LIBS += -L/usr/lib/pdfium -Wl,--start-group -lpdfium -lfpdfapi -lfxge -lfpdfdoc \ + } else { + #static pdfium libraries have to be included *before* dynamic libraries + DEFINES += "USE_PDFIUM" + INCLUDEPATH += /usr/include/pdfium + LIBS += -L/usr/lib/pdfium -Wl,--start-group -lpdfium -lfpdfapi -lfxge -lfpdfdoc \ -lfxcrt -lfx_agg -lfxcodec -lfx_lpng -lfx_libopenjpeg -lfx_lcms2 -ljpeg \ -lfx_zlib -lfdrm -lfxedit -lformfiller -lpdfwindow -lpdfium -lbigint -ljavascript \ -lfxedit -Wl,--end-group -lfreetype } +} +else { + DEFINES += "NO_PDF" +} !CONFIG(no_opengl) { LIBS += -lGLU diff --git a/YACReaderLibrary/library_creator.cpp b/YACReaderLibrary/library_creator.cpp index d19b3b0f..d6ce5863 100644 --- a/YACReaderLibrary/library_creator.cpp +++ b/YACReaderLibrary/library_creator.cpp @@ -579,7 +579,7 @@ void ThumbnailCreator::create() QLOG_WARN() << "Extracting cover: file not found " << _fileSource; return; } - +#ifndef NO_PDF if(fi.suffix().compare("pdf",Qt::CaseInsensitive) == 0) { #if defined Q_OS_MAC && defined USE_PDFKIT @@ -632,7 +632,7 @@ void ThumbnailCreator::create() #endif #else QImage p = pdfComic->page(_coverPage-1)->renderToImage(72,72); -#endif +#endif // _cover = p; if(_target!="") { @@ -656,78 +656,77 @@ void ThumbnailCreator::create() } delete pdfComic; } + return; + } +#endif //NO_PDF + + if(crash) + { + return; + } + + CompressedArchive archive(_fileSource); + if(!archive.toolsLoaded()) + { + QLOG_WARN() << "Extracting cover: 7z lib not loaded"; + crash = true; + return; + } + if(!archive.isValid()) + { + QLOG_WARN() << "Extracting cover: file format not supported " << _fileSource; + } + //se filtran para obtener sólo los formatos soportados + QList order = archive.getFileNames(); + QList fileNames = FileComic::filter(order); + _numPages = fileNames.size(); + if(_numPages == 0) + { + QLOG_WARN() << "Extracting cover: empty comic " << _fileSource; + _cover.load(":/images/notCover.png"); + if(_target!="") + { + _cover.save(_target); + } } else { + if(_coverPage > _numPages) + { + _coverPage = 1; + } + qSort(fileNames.begin(),fileNames.end(), naturalSortLessThanCI); + int index = order.indexOf(fileNames.at(_coverPage-1)); - if(crash) + if(_target=="") { - return; - } - - CompressedArchive archive(_fileSource); - if(!archive.toolsLoaded()) - { - QLOG_WARN() << "Extracting cover: 7z lib not loaded"; - crash = true; - return; - } - if(!archive.isValid()) - { - QLOG_WARN() << "Extracting cover: file format not supported " << _fileSource; - } - //se filtran para obtener sólo los formatos soportados - QList order = archive.getFileNames(); - QList fileNames = FileComic::filter(order); - _numPages = fileNames.size(); - if(_numPages == 0) - { - QLOG_WARN() << "Extracting cover: empty comic " << _fileSource; - _cover.load(":/images/notCover.png"); - if(_target!="") + if(!_cover.loadFromData(archive.getRawDataAtIndex(index))) { - _cover.save(_target); + QLOG_WARN() << "Extracting cover: unable to load image from extracted cover " << _fileSource; + _cover.load(":/images/notCover.png"); } } else { - if(_coverPage > _numPages) + QImage p; + if(p.loadFromData(archive.getRawDataAtIndex(index))) { - _coverPage = 1; - } - qSort(fileNames.begin(),fileNames.end(), naturalSortLessThanCI); - int index = order.indexOf(fileNames.at(_coverPage-1)); - - if(_target=="") - { - if(!_cover.loadFromData(archive.getRawDataAtIndex(index))) + QImage scaled; + if(p.width()>p.height()) //landscape?? { - QLOG_WARN() << "Extracting cover: unable to load image from extracted cover " << _fileSource; - _cover.load(":/images/notCover.png"); - } - } - else - { - QImage p; - if(p.loadFromData(archive.getRawDataAtIndex(index))) - { - QImage scaled; - if(p.width()>p.height()) //landscape?? - { - scaled = p.scaledToWidth(640,Qt::SmoothTransformation); - } - else - { - scaled = p.scaledToWidth(480,Qt::SmoothTransformation); - } - scaled.save(_target,0,75); + scaled = p.scaledToWidth(640,Qt::SmoothTransformation); } else { - QLOG_WARN() << "Extracting cover: unable to load image from extracted cover " << _fileSource; - //p.load(":/images/notCover.png"); - //p.save(_target); + scaled = p.scaledToWidth(480,Qt::SmoothTransformation); } + scaled.save(_target,0,75); + } + else + { + QLOG_WARN() << "Extracting cover: unable to load image from extracted cover " << _fileSource; + //p.load(":/images/notCover.png"); + //p.save(_target); } } } diff --git a/common/comic.cpp b/common/comic.cpp index b5867194..4ec210d3 100644 --- a/common/comic.cpp +++ b/common/comic.cpp @@ -28,12 +28,20 @@ const QStringList Comic::imageExtensions = QStringList() << "*.jpg" << "*.jpeg" const QStringList Comic::literalImageExtensions = QStringList() << "jpg" << "jpeg" << "png" << "gif" << "tiff" << "tif" << "bmp" << "webp"; #ifndef use_unarr -const QStringList Comic::comicExtensions = QStringList() << "*.cbr" << "*.cbz" << "*.rar" << "*.zip" << "*.tar" << "*.pdf" << "*.7z" << "*.cb7" << "*.arj" << "*.cbt"; -const QStringList Comic::literalComicExtensions = QStringList() << "cbr" << "cbz" << "rar" << "zip" << "tar" << "pdf" << "7z" << "cb7" << "arj" << "cbt"; +const QStringList ComicArchiveExtensions = QStringList() << "*.cbr" << "*.cbz" << "*.rar" << "*.zip" << "*.tar" << "*.pdf" << "*.7z" << "*.cb7" << "*.arj" << "*.cbt"; +const QStringList LiteralComicArchiveExtensions = QStringList() << "cbr" << "cbz" << "rar" << "zip" << "tar" << "pdf" << "7z" << "cb7" << "arj" << "cbt"; #else -const QStringList Comic::comicExtensions = QStringList() << "*.cbr" << "*.cbz" << "*.rar" << "*.zip" << "*.tar" << "*.pdf" << "*.cbt"; -const QStringList Comic::literalComicExtensions = QStringList() << "cbr" << "cbz" << "rar" << "zip" << "tar" << "pdf" << "cbt"; -#endif +const QStringList ComicArchiveExtensions = QStringList() << "*.cbr" << "*.cbz" << "*.rar" << "*.zip" << "*.tar" << "*.pdf" << "*.cbt"; +const QStringList LiteralComicArchiveExtensions = QStringList() << "cbr" << "cbz" << "rar" << "zip" << "tar" << "pdf" << "cbt"; +#endif //use_unarr +#ifndef NO_PDF +const QStringList Comic::comicExtensions = QStringList() << ComicArchiveExtensions << "*.pdf"; +const QStringList Comic::literalComicExtensions = QStringList() << LiteralComicArchiveExtensions << "pdf"; +#else +const QStringList Comic::comicExtensions = QStringList() << ComicArchiveExtensions << "*.pdf"; +const QStringList Comic::literalComicExtensions = QStringList() << LiteralComicArchiveExtensions << "pdf"; +#endif //NO_PDF + //----------------------------------------------------------------------------- Comic::Comic() :_pages(),_index(0),_path(),_loaded(false),bm(new Bookmarks()),_loadedPages(),_isPDF(false) @@ -701,6 +709,8 @@ void FolderComic::process() //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// +#ifndef NO_PDF + PDFComic::PDFComic() :Comic() { @@ -872,6 +882,8 @@ void PDFComic::renderPage(int page) } } +#endif //NO_PDF + Comic * FactoryComic::newComic(const QString & path) { @@ -879,7 +891,8 @@ Comic * FactoryComic::newComic(const QString & path) if(fi.exists()) { if(fi.isFile()) - { + { + #ifndef NO_PDF if(fi.suffix().compare("pdf",Qt::CaseInsensitive) == 0) { return new PDFComic(); @@ -888,6 +901,9 @@ Comic * FactoryComic::newComic(const QString & path) { return new FileComic(); } + #else + return new FileComic(); + #endif } else { diff --git a/common/comic.h b/common/comic.h index a9a8ef51..4dd17ce8 100644 --- a/common/comic.h +++ b/common/comic.h @@ -8,8 +8,9 @@ #include "extract_delegate.h" #include "bookmarks.h" +#ifndef NO_PDF #include "pdf_comic.h" - +#endif //NO_PDF 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() @@ -149,6 +150,7 @@ class FolderComic : public Comic void process(); }; +#ifndef NO_PDF class PDFComic : public Comic { Q_OBJECT @@ -179,7 +181,7 @@ class PDFComic : public Comic void process(); }; - +#endif //NO_PDF class FactoryComic { public: diff --git a/common/pdf_comic.cpp b/common/pdf_comic.cpp index 3ede0b8d..e943b1d7 100644 --- a/common/pdf_comic.cpp +++ b/common/pdf_comic.cpp @@ -1,6 +1,6 @@ #include "comic.h" #include "pdf_comic.h" -#ifdef USE_PDFIUM +#if defined USE_PDFIUM && !defined NO_PDF PdfiumComic::PdfiumComic() { FPDF_InitLibrary(); diff --git a/common/pdf_comic.h b/common/pdf_comic.h index 88899c3d..00537922 100644 --- a/common/pdf_comic.h +++ b/common/pdf_comic.h @@ -1,4 +1,4 @@ -#ifndef PDF_COMIC_H +#if !defined PDF_COMIC_H && !defined NO_PDF #define PDF_COMIC_H #include