mirror of
https://github.com/YACReader/yacreader
synced 2025-05-28 03:10:27 -04:00
Add support for pdfium
This commit is contained in:
parent
f05ac77fc2
commit
c74934c822
@ -58,9 +58,17 @@ 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_opengl) {
|
||||
LIBS += -lGLU
|
||||
@ -172,6 +180,7 @@ SOURCES += ../common/comic.cpp \
|
||||
../common/library_item.cpp \
|
||||
yacreader_local_client.cpp \
|
||||
../common/http_worker.cpp \
|
||||
../common/pdf_comic.cpp \
|
||||
../common/yacreader_global.cpp \
|
||||
../common/yacreader_global_gui.cpp \
|
||||
../common/exit_check.cpp \
|
||||
|
@ -46,9 +46,18 @@ 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_opengl) {
|
||||
LIBS += -lGLU
|
||||
@ -202,6 +211,7 @@ SOURCES += comic_flow.cpp \
|
||||
../common/yacreader_global_gui.cpp \
|
||||
yacreader_libraries.cpp \
|
||||
../common/exit_check.cpp \
|
||||
../common/pdf_comic.cpp \
|
||||
comics_view.cpp \
|
||||
classic_comics_view.cpp \
|
||||
empty_folder_widget.cpp \
|
||||
|
@ -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)
|
||||
@ -594,8 +582,7 @@ void ThumbnailCreator::create()
|
||||
|
||||
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))
|
||||
{
|
||||
@ -605,9 +592,17 @@ void ThumbnailCreator::create()
|
||||
//p.save(_target);
|
||||
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;
|
||||
@ -618,7 +613,7 @@ void ThumbnailCreator::create()
|
||||
//p.save(_target);
|
||||
return;
|
||||
}
|
||||
#ifndef Q_OS_MAC
|
||||
#if !defined USE_PDFKIT && !defined USE_PDFIUM
|
||||
//poppler only, not mac
|
||||
if (pdfComic->isLocked())
|
||||
{
|
||||
@ -630,9 +625,11 @@ void ThumbnailCreator::create()
|
||||
_numPages = pdfComic->numPages();
|
||||
if(_numPages >= _coverPage)
|
||||
{
|
||||
#ifdef Q_OS_MAC
|
||||
{ //TODO is this "{" one too much?
|
||||
#if defined Q_OS_MAC || defined USE_PDFIUM
|
||||
QImage p = pdfComic->getPage(_coverPage-1); //TODO check if the page is valid
|
||||
#ifdef USE_PDFKIT
|
||||
pdfComic->releaseLastPageData();
|
||||
#endif
|
||||
#else
|
||||
QImage p = pdfComic->page(_coverPage-1)->renderToImage(72,72);
|
||||
#endif
|
||||
@ -650,11 +647,6 @@ 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;
|
||||
@ -662,9 +654,9 @@ void ThumbnailCreator::create()
|
||||
//p.load(":/images/notCover.png");
|
||||
//p.save(_target);
|
||||
}
|
||||
|
||||
delete pdfComic;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
|
@ -769,7 +769,7 @@ bool PDFComic::load(const QString & path, const ComicDB & comic)
|
||||
|
||||
void PDFComic::process()
|
||||
{
|
||||
#ifdef Q_OS_MAC
|
||||
#if defined Q_OS_MAC && defined USE_PDFKIT
|
||||
pdfComic = new MacOSXPDFComic();
|
||||
if(!pdfComic->openComic(_path))
|
||||
{
|
||||
@ -777,8 +777,15 @@ void PDFComic::process()
|
||||
emit errorOpening();
|
||||
return;
|
||||
}
|
||||
#elif defined USE_PDFIUM
|
||||
pdfComic = new PdfiumComic();
|
||||
if(!pdfComic->openComic(_path))
|
||||
{
|
||||
delete pdfComic;
|
||||
emit errorOpening();
|
||||
return;
|
||||
}
|
||||
#else
|
||||
|
||||
pdfComic = Poppler::Document::load(_path);
|
||||
if (!pdfComic)
|
||||
{
|
||||
@ -840,12 +847,15 @@ void PDFComic::process()
|
||||
|
||||
void PDFComic::renderPage(int page)
|
||||
{
|
||||
#ifdef Q_OS_MAC
|
||||
#if defined Q_OS_MAC && defined USE_PDFKIT
|
||||
QImage img = pdfComic->getPage(page);
|
||||
if(!img.isNull())
|
||||
{
|
||||
pdfComic->releaseLastPageData();
|
||||
|
||||
#elif defined USE_PDFIUM
|
||||
QImage img = pdfComic->getPage(page);
|
||||
if(!img.isNull())
|
||||
{
|
||||
#else
|
||||
Poppler::Page* pdfpage = pdfComic->page(page);
|
||||
if (pdfpage)
|
||||
|
@ -154,14 +154,16 @@ class PDFComic : public Comic
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
|
||||
//pdf
|
||||
#ifdef Q_OS_MAC
|
||||
#if defined Q_OS_MAC && defined USE_PDFKIT
|
||||
MacOSXPDFComic * pdfComic;
|
||||
#elif defined USE_PDFIUM
|
||||
PdfiumComic * pdfComic;
|
||||
#else
|
||||
Poppler::Document * pdfComic;
|
||||
#endif
|
||||
void renderPage(int page);
|
||||
|
||||
//void run();
|
||||
|
||||
public:
|
||||
|
81
common/pdf_comic.cpp
Normal file
81
common/pdf_comic.cpp
Normal file
@ -0,0 +1,81 @@
|
||||
#include "comic.h"
|
||||
#include "pdf_comic.h"
|
||||
#ifdef USE_PDFIUM
|
||||
PdfiumComic::PdfiumComic()
|
||||
{
|
||||
FPDF_InitLibrary();
|
||||
}
|
||||
|
||||
PdfiumComic::~PdfiumComic()
|
||||
{
|
||||
if (doc)
|
||||
{
|
||||
FPDF_CloseDocument(doc);
|
||||
}
|
||||
FPDF_DestroyLibrary();
|
||||
}
|
||||
|
||||
bool PdfiumComic::openComic(const QString & path)
|
||||
{
|
||||
doc = FPDF_LoadDocument(path.toStdString().c_str(), NULL);
|
||||
if (doc)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << FPDF_GetLastError();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void PdfiumComic::closeComic()
|
||||
{
|
||||
FPDF_CloseDocument(doc);
|
||||
}
|
||||
|
||||
unsigned int PdfiumComic::numPages()
|
||||
{
|
||||
if (doc)
|
||||
{
|
||||
return FPDF_GetPageCount(doc);
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0; //-1?
|
||||
}
|
||||
}
|
||||
|
||||
QImage PdfiumComic::getPage(const int page)
|
||||
{
|
||||
QTime time;
|
||||
time.start();
|
||||
QImage image;
|
||||
FPDF_PAGE pdfpage;
|
||||
FPDF_BITMAP bitmap;
|
||||
|
||||
pdfpage = FPDF_LoadPage(doc, page);
|
||||
|
||||
if (!pdfpage)
|
||||
{
|
||||
qDebug() << FPDF_GetLastError();
|
||||
return QImage();
|
||||
}
|
||||
|
||||
//TODO: make target DPI configurable
|
||||
double width = (FPDF_GetPageWidth(pdfpage)/72)*150;
|
||||
double height = (FPDF_GetPageHeight(pdfpage)/72)*150;
|
||||
|
||||
image = QImage(width, height, QImage::Format_RGB888);// QImage::Format_RGBX8888);
|
||||
image.fill(0xFFFFFFFF);
|
||||
|
||||
bitmap = FPDFBitmap_CreateEx(image.width(), image.height(), FPDFBitmap_BGR, image.scanLine(0), image.bytesPerLine());
|
||||
//TODO: make render flags costumizable
|
||||
FPDF_RenderPageBitmap(bitmap, pdfpage, 0,0, image.width(), image.height(), 0, (FPDF_REVERSE_BYTE_ORDER | FPDF_LCD_TEXT));
|
||||
FPDFBitmap_Destroy(bitmap);
|
||||
FPDF_ClosePage(pdfpage);
|
||||
|
||||
qDebug()<< "Render time:" << time.elapsed();
|
||||
return image;
|
||||
}
|
||||
#endif //USE_PDFIUM
|
@ -4,7 +4,7 @@
|
||||
#include <QObject>
|
||||
#include <QImage>
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
#if defined Q_OS_MAC && defined USE_PDFKIT
|
||||
class MacOSXPDFComic
|
||||
{
|
||||
public:
|
||||
@ -15,13 +15,30 @@ public:
|
||||
unsigned int numPages();
|
||||
QImage getPage(const int page);
|
||||
void releaseLastPageData();
|
||||
|
||||
private:
|
||||
void * document;
|
||||
void * lastPageData;
|
||||
};
|
||||
|
||||
#elif defined USE_PDFIUM
|
||||
#include <fpdfview.h>
|
||||
|
||||
class PdfiumComic
|
||||
{
|
||||
public:
|
||||
PdfiumComic();
|
||||
~PdfiumComic();
|
||||
bool openComic(const QString & path);
|
||||
void closeComic();
|
||||
unsigned int numPages();
|
||||
QImage getPage(const int page);
|
||||
|
||||
private:
|
||||
FPDF_LIBRARY_CONFIG config;
|
||||
FPDF_DOCUMENT doc;
|
||||
};
|
||||
#else
|
||||
#include "poppler-qt5.h"
|
||||
#endif // Q_OS_MAC
|
||||
|
||||
#endif // PDF_COMIC_H
|
||||
|
Loading…
Reference in New Issue
Block a user