|
|
@ -42,6 +42,13 @@ |
|
|
|
|
|
|
|
|
|
|
|
QAtomicInt XPDFRenderer::sInstancesCount = 0; |
|
|
|
QAtomicInt XPDFRenderer::sInstancesCount = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace constants{ |
|
|
|
|
|
|
|
const double mode1_zoomFactor = 3.0; |
|
|
|
|
|
|
|
const double mode2_zoomFactorStage1 = 2.5; |
|
|
|
|
|
|
|
const double mode2_zoomFactorStage2 = 5.0; |
|
|
|
|
|
|
|
const double mode2_zoomFactorStage3 = 10.0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
XPDFRenderer::XPDFRenderer(const QString &filename, bool importingFile) : |
|
|
|
XPDFRenderer::XPDFRenderer(const QString &filename, bool importingFile) : |
|
|
|
mpSplashBitmapHistorical(nullptr), mSplashHistorical(nullptr), mDocument(nullptr) |
|
|
|
mpSplashBitmapHistorical(nullptr), mSplashHistorical(nullptr), mDocument(nullptr) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -50,12 +57,12 @@ XPDFRenderer::XPDFRenderer(const QString &filename, bool importingFile) : |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 1: // Render a single image, degradated quality when zoomed big.
|
|
|
|
case 1: // Render a single image, degradated quality when zoomed big.
|
|
|
|
default: |
|
|
|
default: |
|
|
|
m_pdfZoomCache.push_back(3.0); |
|
|
|
m_pdfZoomCache.push_back(constants::mode1_zoomFactor); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 2: // Render three images, optimal quality all the time.
|
|
|
|
case 2: // Render three images, optimal quality all the time.
|
|
|
|
m_pdfZoomCache.push_back(2.5); |
|
|
|
m_pdfZoomCache.push_back(constants::mode2_zoomFactorStage1); |
|
|
|
m_pdfZoomCache.push_back(5.0); |
|
|
|
m_pdfZoomCache.push_back(constants::mode2_zoomFactorStage2); |
|
|
|
m_pdfZoomCache.push_back(10.0); |
|
|
|
m_pdfZoomCache.push_back(constants::mode2_zoomFactorStage3); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -83,7 +90,7 @@ XPDFRenderer::~XPDFRenderer() |
|
|
|
{ |
|
|
|
{ |
|
|
|
for(int i = 0; i < m_pdfZoomCache.size(); i++) |
|
|
|
for(int i = 0; i < m_pdfZoomCache.size(); i++) |
|
|
|
{ |
|
|
|
{ |
|
|
|
TypePdfZoomCacheData &cacheData = m_pdfZoomCache[i]; |
|
|
|
PdfZoomCacheData &cacheData = m_pdfZoomCache[i]; |
|
|
|
if(cacheData.splash != nullptr){ |
|
|
|
if(cacheData.splash != nullptr){ |
|
|
|
cacheData.cachedImage = QImage(); // The 'cachedImage' uses a buffer from 'splash'.
|
|
|
|
cacheData.cachedImage = QImage(); // The 'cachedImage' uses a buffer from 'splash'.
|
|
|
|
delete cacheData.splash; |
|
|
|
delete cacheData.splash; |
|
|
@ -209,7 +216,7 @@ QImage* XPDFRenderer::createPDFImageHistorical(int pageNumber, qreal xscale, qre |
|
|
|
#ifdef USE_XPDF |
|
|
|
#ifdef USE_XPDF |
|
|
|
mSplashHistorical->startDoc(mDocument->getXRef()); |
|
|
|
mSplashHistorical->startDoc(mDocument->getXRef()); |
|
|
|
#else |
|
|
|
#else |
|
|
|
mSplash->startDoc(mDocument); |
|
|
|
mSplashHistorical->startDoc(mDocument); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
int rotation = 0; // in degrees (get it from the worldTransform if we want to support rotation)
|
|
|
|
int rotation = 0; // in degrees (get it from the worldTransform if we want to support rotation)
|
|
|
|
bool useMediaBox = false; |
|
|
|
bool useMediaBox = false; |
|
|
@ -291,21 +298,14 @@ void XPDFRenderer::render(QPainter *p, int pageNumber, const QRectF &bounds) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
QImage& XPDFRenderer::createPDFImageCached(int pageNumber, TypePdfZoomCacheData &cacheData) |
|
|
|
QImage& XPDFRenderer::createPDFImageCached(int pageNumber, PdfZoomCacheData &cacheData) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (isValid()) |
|
|
|
if (isValid()) |
|
|
|
{
|
|
|
|
{
|
|
|
|
SplashColor paperColor = {0xFF, 0xFF, 0xFF}; // white
|
|
|
|
SplashColor paperColor = {0xFF, 0xFF, 0xFF}; // white
|
|
|
|
bool const requireUpdateImage = (pageNumber != cacheData.cachedPageNumber) || (cacheData.splash == nullptr); |
|
|
|
if (cacheData.requireUpdateImage(pageNumber)) |
|
|
|
if (requireUpdateImage) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if(cacheData.splash != nullptr) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
cacheData.cachedImage = QImage(); |
|
|
|
cacheData.prepareNewSplash(pageNumber, paperColor); |
|
|
|
delete cacheData.splash; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
cacheData.splash = new SplashOutputDev(splashModeRGB8, 1, false, paperColor); |
|
|
|
|
|
|
|
cacheData.cachedPageNumber = pageNumber; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef USE_XPDF |
|
|
|
#ifdef USE_XPDF |
|
|
|
cacheData.splash->startDoc(mDocument->getXRef()); |
|
|
|
cacheData.splash->startDoc(mDocument->getXRef()); |
|
|
@ -324,7 +324,7 @@ QImage& XPDFRenderer::createPDFImageCached(int pageNumber, TypePdfZoomCacheData |
|
|
|
cacheData.splashBitmap = cacheData.splash->getBitmap(); |
|
|
|
cacheData.splashBitmap = cacheData.splash->getBitmap(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Note this uses the 'mSplash->getBitmap()->getDataPtr()' as data buffer.
|
|
|
|
// Note this uses the 'cacheData.splash->getBitmap()->getDataPtr()' as data buffer.
|
|
|
|
cacheData.cachedImage = QImage(cacheData.splashBitmap->getDataPtr(), cacheData.splashBitmap->getWidth(), cacheData.splashBitmap->getHeight(), |
|
|
|
cacheData.cachedImage = QImage(cacheData.splashBitmap->getDataPtr(), cacheData.splashBitmap->getWidth(), cacheData.splashBitmap->getHeight(), |
|
|
|
cacheData.splashBitmap->getWidth() * 3 /* bytesPerLine, 24 bits for RGB888, = 3 bytes */, |
|
|
|
cacheData.splashBitmap->getWidth() * 3 /* bytesPerLine, 24 bits for RGB888, = 3 bytes */, |
|
|
|
QImage::Format_RGB888); |
|
|
|
QImage::Format_RGB888); |
|
|
|