mirror of
https://github.com/YACReader/yacreader
synced 2025-07-18 21:14:33 -04:00
Merge - 9.0.0 release
This commit is contained in:
@ -14,7 +14,7 @@
|
||||
|
||||
#include "compressed_archive.h"
|
||||
#include "comic.h"
|
||||
|
||||
#include "pdf_comic.h"
|
||||
#include "yacreader_global.h"
|
||||
|
||||
#include "QsLog.h"
|
||||
@ -22,18 +22,6 @@
|
||||
#include <algorithm>
|
||||
using namespace std;
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
#include "pdf_comic.h"
|
||||
#else
|
||||
|
||||
#if QT_VERSION >= 0x050000
|
||||
#include "poppler-qt5.h"
|
||||
#else
|
||||
#include "poppler-qt4.h"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
LibraryCreator::LibraryCreator()
|
||||
:creation(false), partialUpdate(false)
|
||||
@ -591,11 +579,10 @@ void ThumbnailCreator::create()
|
||||
QLOG_WARN() << "Extracting cover: file not found " << _fileSource;
|
||||
return;
|
||||
}
|
||||
|
||||
#ifndef NO_PDF
|
||||
if(fi.suffix().compare("pdf",Qt::CaseInsensitive) == 0)
|
||||
{
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
#if defined Q_OS_MAC && defined USE_PDFKIT
|
||||
MacOSXPDFComic * pdfComic = new MacOSXPDFComic();
|
||||
if(!pdfComic->openComic(_fileSource))
|
||||
{
|
||||
@ -603,41 +590,123 @@ void ThumbnailCreator::create()
|
||||
//QImage p;
|
||||
//p.load(":/images/notCover.png");
|
||||
//p.save(_target);
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
#elif defined USE_PDFIUM
|
||||
PdfiumComic * pdfComic = new PdfiumComic();
|
||||
if(!pdfComic->openComic(_fileSource))
|
||||
{
|
||||
delete pdfComic;
|
||||
return;
|
||||
}
|
||||
#else
|
||||
Poppler::Document * pdfComic = Poppler::Document::load(_fileSource);
|
||||
#endif
|
||||
if (!pdfComic)
|
||||
{
|
||||
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;
|
||||
}
|
||||
#ifndef Q_OS_MAC
|
||||
//poppler only, not mac
|
||||
if (pdfComic->isLocked())
|
||||
{
|
||||
QLOG_WARN() << "Extracting cover: unable to open PDF file " << _fileSource;
|
||||
delete pdfComic;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
_numPages = pdfComic->numPages();
|
||||
if(_numPages >= _coverPage)
|
||||
|
||||
if (!pdfComic)
|
||||
{
|
||||
#ifdef Q_OS_MAC
|
||||
{ //TODO is this "{" one too much?
|
||||
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;
|
||||
}
|
||||
#if !defined USE_PDFKIT && !defined USE_PDFIUM
|
||||
//poppler only, not mac
|
||||
if (pdfComic->isLocked())
|
||||
{
|
||||
QLOG_WARN() << "Extracting cover: unable to open PDF file " << _fileSource;
|
||||
delete pdfComic;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
_numPages = pdfComic->numPages();
|
||||
if(_numPages >= _coverPage)
|
||||
{
|
||||
#if defined Q_OS_MAC || defined USE_PDFIUM
|
||||
QImage p = pdfComic->getPage(_coverPage-1); //TODO check if the page is valid
|
||||
#else
|
||||
QImage p = pdfComic->page(_coverPage-1)->renderToImage(72,72);
|
||||
#endif
|
||||
_cover = p;
|
||||
#endif //
|
||||
_cover = p;
|
||||
if(_target!="")
|
||||
{
|
||||
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);
|
||||
}
|
||||
else if(_target!="")
|
||||
{
|
||||
QLOG_WARN() << "Extracting cover: requested cover index greater than numPages " << _fileSource;
|
||||
//QImage p;
|
||||
//p.load(":/images/notCover.png");
|
||||
//p.save(_target);
|
||||
}
|
||||
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<QString> order = archive.getFileNames();
|
||||
QList<QString> 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(_target=="")
|
||||
{
|
||||
if(!_cover.loadFromData(archive.getRawDataAtIndex(index)))
|
||||
{
|
||||
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??
|
||||
@ -650,92 +719,11 @@ void ThumbnailCreator::create()
|
||||
}
|
||||
scaled.save(_target,0,75);
|
||||
}
|
||||
#ifdef Q_OS_MAC
|
||||
} //TODO is this "{" one too much?
|
||||
pdfComic->releaseLastPageData();
|
||||
#endif
|
||||
}
|
||||
else if(_target!="")
|
||||
{
|
||||
QLOG_WARN() << "Extracting cover: requested cover index greater than numPages " << _fileSource;
|
||||
//QImage p;
|
||||
//p.load(":/images/notCover.png");
|
||||
//p.save(_target);
|
||||
}
|
||||
|
||||
delete pdfComic;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
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<QString> order = archive.getFileNames();
|
||||
QList<QString> 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(_target=="")
|
||||
{
|
||||
if(!_cover.loadFromData(archive.getRawDataAtIndex(index)))
|
||||
{
|
||||
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);
|
||||
}
|
||||
else
|
||||
{
|
||||
QLOG_WARN() << "Extracting cover: unable to load image from extracted cover " << _fileSource;
|
||||
//p.load(":/images/notCover.png");
|
||||
//p.save(_target);
|
||||
}
|
||||
QLOG_WARN() << "Extracting cover: unable to load image from extracted cover " << _fileSource;
|
||||
//p.load(":/images/notCover.png");
|
||||
//p.save(_target);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user