Cleanup. Fixed 'Poppler' compile error, since previous commit.

preferencesAboutTextFull
John Papale 4 years ago
parent 0cf3bdde1a
commit d5988f979c
  1. 34
      src/pdf/XPDFRenderer.cpp
  2. 25
      src/pdf/XPDFRenderer.h

@ -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);

@ -75,23 +75,38 @@ class XPDFRenderer : public PDFRenderer
private: private:
void init(); void init();
struct TypePdfZoomCacheData { struct PdfZoomCacheData {
TypePdfZoomCacheData(double const a_ratio) : splashBitmap(nullptr), cachedPageNumber(-1), splash(nullptr), ratio(a_ratio) {}; PdfZoomCacheData(double const a_ratio) : splashBitmap(nullptr), cachedPageNumber(-1), splash(nullptr), ratio(a_ratio) {};
~TypePdfZoomCacheData() {}; ~PdfZoomCacheData() {};
SplashBitmap* splashBitmap; SplashBitmap* splashBitmap;
QImage cachedImage; QImage cachedImage;
int cachedPageNumber; int cachedPageNumber;
SplashOutputDev* splash; SplashOutputDev* splash;
double const ratio; double const ratio;
bool requireUpdateImage(int const pageNumber) const {
return (pageNumber != cachedPageNumber) || (splash == nullptr);
}
void prepareNewSplash(int const pageNumber, SplashColor &paperColor)
{
if(splash != nullptr)
{
cachedImage = QImage();
delete splash;
}
splash = new SplashOutputDev(splashModeRGB8, 1, false, paperColor);
cachedPageNumber = pageNumber;
}
}; };
QImage &createPDFImageCached(int pageNumber, TypePdfZoomCacheData &cacheData); QImage &createPDFImageCached(int pageNumber, PdfZoomCacheData &cacheData);
QImage* createPDFImageHistorical(int pageNumber, qreal xscale, qreal yscale, const QRectF &bounds); QImage* createPDFImageHistorical(int pageNumber, qreal xscale, qreal yscale, const QRectF &bounds);
// Used when 'ZoomBehavior == 1 or 2'. // Used when 'ZoomBehavior == 1 or 2'.
// =1 has only x3 zoom in cache (= loss if user zoom > 3.0). // =1 has only x3 zoom in cache (= loss if user zoom > 3.0).
// =2, has 2.5, 5 and 10 (= no loss, but a bit slower). // =2, has 2.5, 5 and 10 (= no loss, but a bit slower).
QVector<TypePdfZoomCacheData> m_pdfZoomCache; QVector<PdfZoomCacheData> m_pdfZoomCache;
// Used when 'ZoomBehavior == 0' (no cache). // Used when 'ZoomBehavior == 0' (no cache).
SplashBitmap* mpSplashBitmapHistorical; SplashBitmap* mpSplashBitmapHistorical;

Loading…
Cancel
Save