mirror of
https://github.com/YACReader/yacreader
synced 2025-07-19 05:24:57 -04:00
Add support for pdfium
This commit is contained in:
@ -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)
|
||||
@ -1080,4 +1090,4 @@ void comic_pages_sort(QList<QString> & pageNames, YACReaderPageSortingMode sorti
|
||||
std::sort(pageNames.begin(), pageNames.end());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -154,14 +154,16 @@ class PDFComic : public Comic
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
|
||||
//pdf
|
||||
#ifdef Q_OS_MAC
|
||||
MacOSXPDFComic * pdfComic;
|
||||
#else
|
||||
#if defined Q_OS_MAC && defined USE_PDFKIT
|
||||
MacOSXPDFComic * pdfComic;
|
||||
#elif defined USE_PDFIUM
|
||||
PdfiumComic * pdfComic;
|
||||
#else
|
||||
Poppler::Document * pdfComic;
|
||||
#endif
|
||||
#endif
|
||||
void renderPage(int page);
|
||||
|
||||
//void run();
|
||||
|
||||
public:
|
||||
@ -183,4 +185,4 @@ class FactoryComic
|
||||
public:
|
||||
static Comic * newComic(const QString & path);
|
||||
};
|
||||
#endif
|
||||
#endif
|
||||
|
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,24 +4,41 @@
|
||||
#include <QObject>
|
||||
#include <QImage>
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
#if defined Q_OS_MAC && defined USE_PDFKIT
|
||||
class MacOSXPDFComic
|
||||
{
|
||||
public:
|
||||
MacOSXPDFComic();
|
||||
~MacOSXPDFComic();
|
||||
bool openComic(const QString & path);
|
||||
void closeComic();
|
||||
unsigned int numPages();
|
||||
QImage getPage(const int page);
|
||||
void releaseLastPageData();
|
||||
private:
|
||||
void * document;
|
||||
void * lastPageData;
|
||||
};
|
||||
public:
|
||||
MacOSXPDFComic();
|
||||
~MacOSXPDFComic();
|
||||
bool openComic(const QString & path);
|
||||
void closeComic();
|
||||
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
|
||||
|
Reference in New Issue
Block a user