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

@ -75,23 +75,38 @@ class XPDFRenderer : public PDFRenderer
private:
void init();
struct TypePdfZoomCacheData {
TypePdfZoomCacheData(double const a_ratio) : splashBitmap(nullptr), cachedPageNumber(-1), splash(nullptr), ratio(a_ratio) {};
~TypePdfZoomCacheData() {};
struct PdfZoomCacheData {
PdfZoomCacheData(double const a_ratio) : splashBitmap(nullptr), cachedPageNumber(-1), splash(nullptr), ratio(a_ratio) {};
~PdfZoomCacheData() {};
SplashBitmap* splashBitmap;
QImage cachedImage;
int cachedPageNumber;
SplashOutputDev* splash;
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);
// Used when 'ZoomBehavior == 1 or 2'.
// =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).
QVector<TypePdfZoomCacheData> m_pdfZoomCache;
QVector<PdfZoomCacheData> m_pdfZoomCache;
// Used when 'ZoomBehavior == 0' (no cache).
SplashBitmap* mpSplashBitmapHistorical;

Loading…
Cancel
Save