fixed some leaks

preferencesAboutTextFull
Claudio Valerio 13 years ago
parent a314fe8dc3
commit 2cf7ca7e22
  1. 27
      src/pdf/XPDFRenderer.cpp
  2. 4
      src/pdf/XPDFRenderer.h

@ -25,6 +25,8 @@ QAtomicInt XPDFRenderer::sInstancesCount = 0;
XPDFRenderer::XPDFRenderer(const QString &filename, bool importingFile) XPDFRenderer::XPDFRenderer(const QString &filename, bool importingFile)
: mDocument(0) : mDocument(0)
, mpSplashBitmap(0)
, mSplash(0)
{ {
if (!globalParams) if (!globalParams)
{ {
@ -48,6 +50,17 @@ XPDFRenderer::XPDFRenderer(const QString &filename, bool importingFile)
XPDFRenderer::~XPDFRenderer() XPDFRenderer::~XPDFRenderer()
{ {
qDeleteAll(mThumbs);
mThumbs.clear();
qDeleteAll(mNumPageToPageMap);
mNumPageToPageMap.clear();
if(mSplash){
delete mSplash;
mSplash = NULL;
}
if (mDocument) if (mDocument)
{ {
delete mDocument; delete mDocument;
@ -162,7 +175,7 @@ void XPDFRenderer::render(QPainter *p, int pageNumber, const QRectF &bounds)
{ {
// Generate the thumbnail // Generate the thumbnail
mThumbs << *createPDFImage(pageNumber, xscale, yscale, bounds); mThumbs << createPDFImage(pageNumber, xscale, yscale, bounds);
mThumbMap[pageNumber - 1] = true; mThumbMap[pageNumber - 1] = true;
if(pageNumber == mDocument->getNumPages()) if(pageNumber == mDocument->getNumPages())
{ {
@ -175,7 +188,7 @@ void XPDFRenderer::render(QPainter *p, int pageNumber, const QRectF &bounds)
if(!mPagesMap[pageNumber - 1] || bZoomChanged) if(!mPagesMap[pageNumber - 1] || bZoomChanged)
{ {
// Generate the page // Generate the page
mNumPageToPageMap[pageNumber] = *createPDFImage(pageNumber, xscale, yscale, bounds); mNumPageToPageMap[pageNumber] = createPDFImage(pageNumber, xscale, yscale, bounds);
mPagesMap[pageNumber - 1] = true; mPagesMap[pageNumber - 1] = true;
if(mPagesMap.size() == mDocument->getNumPages()) if(mPagesMap.size() == mDocument->getNumPages())
{ {
@ -184,7 +197,7 @@ void XPDFRenderer::render(QPainter *p, int pageNumber, const QRectF &bounds)
} }
} }
QImage pdfImage; QImage *pdfImage;
if(!bThumbGenerated || bFirstThumbnail) if(!bThumbGenerated || bFirstThumbnail)
{ {
@ -197,10 +210,7 @@ void XPDFRenderer::render(QPainter *p, int pageNumber, const QRectF &bounds)
QTransform savedTransform = p->worldTransform(); QTransform savedTransform = p->worldTransform();
p->resetTransform(); p->resetTransform();
QTime t; p->drawImage(QPointF(savedTransform.dx() + mSliceX, savedTransform.dy() + mSliceY), *pdfImage);
t.start();
p->drawImage(QPointF(savedTransform.dx() + mSliceX, savedTransform.dy() + mSliceY), pdfImage);
//qDebug() << "XPDFRenderer::render(...) execution time: " << t.elapsed() << "ms";
p->setWorldTransform(savedTransform); p->setWorldTransform(savedTransform);
} }
} }
@ -211,6 +221,8 @@ QImage* XPDFRenderer::createPDFImage(int pageNumber, const qreal xscale, const q
if (isValid()) if (isValid())
{ {
SplashColor paperColor = {0xFF, 0xFF, 0xFF}; // white SplashColor paperColor = {0xFF, 0xFF, 0xFF}; // white
if(mSplash)
delete mSplash;
mSplash = new SplashOutputDev(splashModeRGB8, 1, gFalse, paperColor); mSplash = new SplashOutputDev(splashModeRGB8, 1, gFalse, paperColor);
mSplash->startDoc(mDocument->getXRef()); mSplash->startDoc(mDocument->getXRef());
int hResolution = 72; int hResolution = 72;
@ -241,6 +253,7 @@ QImage* XPDFRenderer::createPDFImage(int pageNumber, const qreal xscale, const q
} }
mpSplashBitmap = mSplash->getBitmap(); mpSplashBitmap = mSplash->getBitmap();
delete img;
img = new QImage(mpSplashBitmap->getDataPtr(), mpSplashBitmap->getWidth(), mpSplashBitmap->getHeight(), mpSplashBitmap->getWidth() * 3, QImage::Format_RGB888); img = new QImage(mpSplashBitmap->getDataPtr(), mpSplashBitmap->getWidth(), mpSplashBitmap->getHeight(), mpSplashBitmap->getWidth() * 3, QImage::Format_RGB888);
} }
return img; return img;

@ -51,10 +51,10 @@ class XPDFRenderer : public PDFRenderer
QImage* createPDFImage(int pageNumber, const qreal xscale = 0.5, const qreal yscale = 0.5, const QRectF &bounds = QRectF()); QImage* createPDFImage(int pageNumber, const qreal xscale = 0.5, const qreal yscale = 0.5, const QRectF &bounds = QRectF());
PDFDoc *mDocument; PDFDoc *mDocument;
QList<QImage> mThumbs; QList<QImage*> mThumbs;
QMap<int, bool> mPagesMap; QMap<int, bool> mPagesMap;
QMap<int, bool> mThumbMap; QMap<int, bool> mThumbMap;
QMap<int, QImage> mNumPageToPageMap; QMap<int, QImage*> mNumPageToPageMap;
static QAtomicInt sInstancesCount; static QAtomicInt sInstancesCount;
qreal mSliceX; qreal mSliceX;
qreal mSliceY; qreal mSliceY;

Loading…
Cancel
Save