mirror of
https://github.com/YACReader/yacreader
synced 2025-07-21 22:44:56 -04:00
no more poppler in MacOSX, fixed PDF crash issue
This commit is contained in:
@ -37,14 +37,20 @@ LIBS += -lGLU
|
||||
|
||||
macx{
|
||||
#INCLUDEPATH += "/Volumes/Mac OS X Lion/usr/X11/include"
|
||||
isEqual(QT_MAJOR_VERSION, 5) {
|
||||
INCLUDEPATH += /usr/local/include/poppler/qt5
|
||||
LIBS += -L/usr/local/lib -lpoppler-qt5
|
||||
}
|
||||
else {
|
||||
INCLUDEPATH += /usr/local/include/poppler/qt4
|
||||
LIBS += -L/usr/local/lib -lpoppler-qt4
|
||||
}
|
||||
#isEqual(QT_MAJOR_VERSION, 5) {
|
||||
#INCLUDEPATH += /usr/local/include/poppler/qt5
|
||||
#LIBS += -L/usr/local/lib -lpoppler-qt5
|
||||
#}
|
||||
#else {
|
||||
#INCLUDEPATH += /usr/local/include/poppler/qt4
|
||||
#LIBS += -L/usr/local/lib -lpoppler-qt4
|
||||
#}
|
||||
|
||||
LIBS += -framework Foundation -framework ApplicationServices
|
||||
|
||||
OBJECTIVE_SOURCES += $$PWD/../common/pdf_comic.mm
|
||||
HEADERS += $$PWD/../common/pdf_comic.h
|
||||
CONFIG += objective_c
|
||||
}
|
||||
|
||||
QT += network opengl
|
||||
|
@ -48,15 +48,22 @@ LIBS += -lGLU
|
||||
|
||||
macx{
|
||||
#INCLUDEPATH += "/Volumes/Mac OS X Lion/usr/X11/include"
|
||||
isEqual(QT_MAJOR_VERSION, 5) {
|
||||
INCLUDEPATH += /usr/local/include/poppler/qt5
|
||||
LIBS += -L/usr/local/lib -lpoppler-qt5
|
||||
}
|
||||
else {
|
||||
INCLUDEPATH += /usr/local/include/poppler/qt4
|
||||
LIBS += -L/usr/local/lib -lpoppler-qt4
|
||||
}
|
||||
QT += macextras
|
||||
#isEqual(QT_MAJOR_VERSION, 5) {
|
||||
#INCLUDEPATH += /usr/local/include/poppler/qt5
|
||||
#LIBS += -L/usr/local/lib -lpoppler-qt5
|
||||
#}
|
||||
#else {
|
||||
#INCLUDEPATH += /usr/local/include/poppler/qt4
|
||||
#LIBS += -L/usr/local/lib -lpoppler-qt4
|
||||
#}
|
||||
#QT += macextras
|
||||
|
||||
LIBS += -framework Foundation -framework ApplicationServices
|
||||
|
||||
OBJECTIVE_SOURCES += $$PWD/../common/pdf_comic.mm
|
||||
HEADERS += $$PWD/../common/pdf_comic.h
|
||||
CONFIG += objective_c
|
||||
|
||||
}
|
||||
|
||||
#CONFIG += release
|
||||
|
@ -22,12 +22,18 @@
|
||||
#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)
|
||||
@ -500,11 +506,24 @@ void ThumbnailCreator::create()
|
||||
|
||||
if(fi.suffix().compare("pdf",Qt::CaseInsensitive) == 0)
|
||||
{
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
MacOSXPDFComic * pdfComic = new MacOSXPDFComic();
|
||||
if(!pdfComic->openComic(_fileSource))
|
||||
{
|
||||
delete pdfComic;
|
||||
QImage p;
|
||||
p.load(":/images/notCover.png");
|
||||
p.save(_target);
|
||||
return;
|
||||
}
|
||||
#else
|
||||
Poppler::Document * pdfComic = Poppler::Document::load(_fileSource);
|
||||
if (!pdfComic)
|
||||
#endif
|
||||
if (!pdfComic)
|
||||
{
|
||||
QLOG_WARN() << "Extracting cover: unable to open PDF file " << _fileSource;
|
||||
delete pdfComic;
|
||||
//delete pdfComic; //TODO check if the delete is needed
|
||||
pdfComic = 0;
|
||||
QImage p;
|
||||
p.load(":/images/notCover.png");
|
||||
@ -514,8 +533,12 @@ void ThumbnailCreator::create()
|
||||
_numPages = pdfComic->numPages();
|
||||
if(_numPages >= _coverPage)
|
||||
{
|
||||
|
||||
QImage p = pdfComic->page(_coverPage-1)->renderToImage(72,72); //TODO check if the page is valid
|
||||
#ifdef Q_OS_MAC
|
||||
{
|
||||
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 = QPixmap::fromImage(p);
|
||||
if(_target!="")
|
||||
{
|
||||
@ -526,6 +549,10 @@ void ThumbnailCreator::create()
|
||||
scaled = p.scaledToWidth(480,Qt::SmoothTransformation);
|
||||
scaled.save(_target,0,75);
|
||||
}
|
||||
#ifdef Q_OS_MAC
|
||||
}
|
||||
pdfComic->releaseLastPageData();
|
||||
#endif
|
||||
}
|
||||
else if(_target!="")
|
||||
{
|
||||
@ -534,6 +561,8 @@ void ThumbnailCreator::create()
|
||||
p.load(":/images/notCover.png");
|
||||
p.save(_target);
|
||||
}
|
||||
|
||||
delete pdfComic;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -633,18 +633,32 @@ bool PDFComic::load(const QString & path, const ComicDB & comic)
|
||||
|
||||
void PDFComic::process()
|
||||
{
|
||||
#ifdef Q_OS_MAC
|
||||
pdfComic = new MacOSXPDFComic();
|
||||
if(!pdfComic->openComic(_path))
|
||||
{
|
||||
delete pdfComic;
|
||||
emit errorOpening();
|
||||
return;
|
||||
}
|
||||
#else
|
||||
|
||||
|
||||
pdfComic = Poppler::Document::load(_path);
|
||||
if (!pdfComic)
|
||||
{
|
||||
delete pdfComic;
|
||||
pdfComic = 0;
|
||||
//delete pdfComic;
|
||||
//pdfComic = 0;
|
||||
emit errorOpening();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//pdfComic->setRenderHint(Poppler::Document::Antialiasing, true);
|
||||
pdfComic->setRenderHint(Poppler::Document::TextAntialiasing, true);
|
||||
#endif
|
||||
|
||||
int nPages = pdfComic->numPages();
|
||||
emit pageChanged(0); // this indicates new comic, index=0
|
||||
emit numPages(nPages);
|
||||
@ -672,6 +686,21 @@ void PDFComic::process()
|
||||
|
||||
void PDFComic::renderPage(int page)
|
||||
{
|
||||
#ifdef Q_OS_MAC
|
||||
{
|
||||
QImage img = pdfComic->getPage(page);
|
||||
if(!img.isNull())
|
||||
{
|
||||
QByteArray ba;
|
||||
QBuffer buf(&ba);
|
||||
img.save(&buf, "jpg");
|
||||
_pages[page] = ba;
|
||||
emit imageLoaded(page);
|
||||
emit imageLoaded(page,_pages[page]);
|
||||
}
|
||||
}
|
||||
pdfComic->releaseLastPageData();
|
||||
#else
|
||||
Poppler::Page* pdfpage = pdfComic->page(page);
|
||||
if (pdfpage)
|
||||
{
|
||||
@ -684,6 +713,7 @@ void PDFComic::renderPage(int page)
|
||||
emit imageLoaded(page);
|
||||
emit imageLoaded(page,_pages[page]);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
Comic * FactoryComic::newComic(const QString & path)
|
||||
|
@ -10,12 +10,20 @@
|
||||
|
||||
#include "bookmarks.h"
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
|
||||
#include "pdf_comic.h"
|
||||
|
||||
#else
|
||||
|
||||
#if QT_VERSION >= 0x050000
|
||||
#include "poppler-qt5.h"
|
||||
#else
|
||||
#include "poppler-qt4.h"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
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()
|
||||
@ -138,7 +146,11 @@ class ComicDB;
|
||||
Q_OBJECT
|
||||
private:
|
||||
//pdf
|
||||
#ifdef Q_OS_MAC
|
||||
MacOSXPDFComic * pdfComic;
|
||||
#else
|
||||
Poppler::Document * pdfComic;
|
||||
#endif
|
||||
void renderPage(int page);
|
||||
|
||||
//void run();
|
||||
|
22
common/pdf_comic.h
Normal file
22
common/pdf_comic.h
Normal file
@ -0,0 +1,22 @@
|
||||
#ifndef PDF_COMIC_H
|
||||
#define PDF_COMIC_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QImage>
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
#endif // PDF_COMIC_H
|
117
common/pdf_comic.mm
Normal file
117
common/pdf_comic.mm
Normal file
@ -0,0 +1,117 @@
|
||||
#include "pdf_comic.h"
|
||||
|
||||
#import <AppKit/AppKit.h>
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <ApplicationServices/ApplicationServices.h>
|
||||
|
||||
#include "QsLog.h"
|
||||
#include "QsLogDest.h"
|
||||
|
||||
|
||||
MacOSXPDFComic::MacOSXPDFComic()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
MacOSXPDFComic::~MacOSXPDFComic()
|
||||
{
|
||||
CGPDFDocumentRelease((CGPDFDocumentRef)document);
|
||||
}
|
||||
|
||||
bool MacOSXPDFComic::openComic(const QString &path)
|
||||
{
|
||||
|
||||
CFURLRef pdfFileUrl;
|
||||
CFStringRef str;
|
||||
str=CFStringCreateWithCString( kCFAllocatorDefault,path.toUtf8().data(),kCFStringEncodingUTF8);
|
||||
pdfFileUrl=CFURLCreateWithFileSystemPath( kCFAllocatorDefault,str,kCFURLPOSIXPathStyle,true );
|
||||
|
||||
CGPDFDocumentRef pdf = CGPDFDocumentCreateWithURL((CFURLRef)pdfFileUrl);
|
||||
|
||||
document = pdf;
|
||||
|
||||
CFRelease(str);
|
||||
CFRelease(pdfFileUrl);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void MacOSXPDFComic::closeComic()
|
||||
{
|
||||
//CGPDFDocumentRelease((CGPDFDocumentRef)document);
|
||||
}
|
||||
|
||||
unsigned int MacOSXPDFComic::numPages()
|
||||
{
|
||||
return (int)CGPDFDocumentGetNumberOfPages((CGPDFDocumentRef)document);
|
||||
}
|
||||
|
||||
QImage MacOSXPDFComic::getPage(const int pageNum)
|
||||
{
|
||||
CGPDFPageRef page = CGPDFDocumentGetPage((CGPDFDocumentRef)document, pageNum+1);
|
||||
// Changed this line for the line above which is a generic line
|
||||
//CGPDFPageRef page = [self getPage:page_number];
|
||||
|
||||
|
||||
|
||||
CGRect pageRect = CGPDFPageGetBoxRect(page, kCGPDFMediaBox);
|
||||
int width = 1200;
|
||||
|
||||
//NSLog(@"-----%f",pageRect.size.width);
|
||||
CGFloat pdfScale = float(width)/pageRect.size.width;
|
||||
|
||||
pageRect.size = CGSizeMake(pageRect.size.width*pdfScale, pageRect.size.height*pdfScale);
|
||||
pageRect.origin = CGPointZero;
|
||||
|
||||
CGColorSpaceRef genericColorSpace = CGColorSpaceCreateDeviceRGB();
|
||||
CGContextRef bitmapContext = CGBitmapContextCreate(NULL,
|
||||
pageRect.size.width,
|
||||
pageRect.size.height,
|
||||
8, 0,
|
||||
genericColorSpace,
|
||||
kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little
|
||||
);
|
||||
|
||||
CGContextSetInterpolationQuality(bitmapContext, kCGInterpolationHigh);
|
||||
CGContextSetRenderingIntent(bitmapContext, kCGRenderingIntentDefault);
|
||||
CGContextSetRGBFillColor( bitmapContext, 1.0, 1.0, 1.0, 1.0 );
|
||||
CGContextFillRect( bitmapContext, CGContextGetClipBoundingBox( bitmapContext ));
|
||||
|
||||
//CGContextTranslateCTM( bitmapContext, 0, pageRect.size.height );
|
||||
//CGContextScaleCTM( bitmapContext, 1.0, -1.0 );
|
||||
|
||||
CGContextConcatCTM(bitmapContext, CGAffineTransformMakeScale(pdfScale, pdfScale));
|
||||
|
||||
|
||||
/*CGAffineTransform pdfXfm = CGPDFPageGetDrawingTransform( page, kCGPDFMediaBox, CGRectMake(pageRect.origin.x, pageRect.origin.y, pageRect.size.width, pageRect.size.height) , 0, true );
|
||||
*/
|
||||
//CGContextConcatCTM( bitmapContext, pdfXfm );
|
||||
|
||||
CGContextDrawPDFPage(bitmapContext, page);
|
||||
|
||||
CGImageRef image = CGBitmapContextCreateImage(bitmapContext);
|
||||
|
||||
QImage qtImage;
|
||||
|
||||
CFDataRef dataRef = CGDataProviderCopyData(CGImageGetDataProvider(image));
|
||||
|
||||
lastPageData = (void *)dataRef;
|
||||
|
||||
const uchar *bytes = (const uchar *)CFDataGetBytePtr(dataRef);
|
||||
|
||||
qtImage = QImage(bytes, pageRect.size.width, pageRect.size.height, QImage::Format_ARGB32);
|
||||
|
||||
CGImageRelease(image);
|
||||
//CFRelease(dataRef);
|
||||
CGContextRelease(bitmapContext);
|
||||
//CGPDFPageRelease(page);
|
||||
CGColorSpaceRelease(genericColorSpace);
|
||||
|
||||
return qtImage;
|
||||
}
|
||||
|
||||
void MacOSXPDFComic::releaseLastPageData()
|
||||
{
|
||||
CFRelease((CFDataRef)lastPageData);
|
||||
}
|
||||
|
@ -8,7 +8,7 @@
|
||||
#endif
|
||||
|
||||
|
||||
#define VERSION "7.0.1"
|
||||
#define VERSION "7.0.2"
|
||||
|
||||
#define PATH "PATH"
|
||||
#define MAG_GLASS_SIZE "MAG_GLASS_SIZE"
|
||||
|
Reference in New Issue
Block a user