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

Loading…
Cancel
Save