Sankore-204 pdf loading doesn't scele scene any more

preferencesAboutTextFull
Anatoly Mihalchenko 13 years ago
parent 02a515b399
commit d966a6c9ca
  1. 4
      src/adaptors/UBImportPDF.cpp
  2. 3
      src/adaptors/UBImportPDF.h
  3. 3
      src/pdf/PDFRenderer.cpp
  4. 6
      src/pdf/PDFRenderer.h
  5. 44
      src/pdf/XPDFRenderer.cpp
  6. 2
      src/pdf/XPDFRenderer.h

@ -31,7 +31,8 @@
UBImportPDF::UBImportPDF(QObject *parent) UBImportPDF::UBImportPDF(QObject *parent)
: UBImportAdaptor(parent) : UBImportAdaptor(parent)
{ {
// NOOP QDesktopWidget* desktop = UBApplication::desktop();
this->dpi = (desktop->physicalDpiX() + desktop->physicalDpiY()) / 2;
} }
@ -68,6 +69,7 @@ bool UBImportPDF::addFileToDocument(UBDocumentProxy* pDocument, const QFile& pFi
UBApplication::showMessage(tr("PDF import failed.")); UBApplication::showMessage(tr("PDF import failed."));
return false; return false;
} }
pdfRenderer->setDPI(this->dpi);
int documentPageCount = pDocument->pageCount(); int documentPageCount = pDocument->pageCount();

@ -33,6 +33,9 @@ class UBImportPDF : public UBImportAdaptor
virtual QString importFileFilter(); virtual QString importFileFilter();
virtual bool addFileToDocument(UBDocumentProxy* pDocument, const QFile& pFile); virtual bool addFileToDocument(UBDocumentProxy* pDocument, const QFile& pFile);
private:
int dpi;
}; };
#endif /* UBIMPORTPDF_H_ */ #endif /* UBIMPORTPDF_H_ */

@ -23,6 +23,9 @@
QMap< QUuid, QPointer<PDFRenderer> > PDFRenderer::sRenderers; QMap< QUuid, QPointer<PDFRenderer> > PDFRenderer::sRenderers;
PDFRenderer::PDFRenderer() : dpiForRendering(96)
{
}
PDFRenderer::~PDFRenderer() PDFRenderer::~PDFRenderer()
{ {

@ -50,6 +50,8 @@ class PDFRenderer : public QObject
QUuid fileUuid() const { return mFileUuid; } QUuid fileUuid() const { return mFileUuid; }
QByteArray fileData() const { return mFileData; } QByteArray fileData() const { return mFileData; }
void setDPI(int desiredDPI) { this->dpiForRendering = desiredDPI; }
public slots: public slots:
virtual void render(QPainter *p, int pageNumber, const QRectF &bounds = QRectF()) = 0; virtual void render(QPainter *p, int pageNumber, const QRectF &bounds = QRectF()) = 0;
@ -63,6 +65,10 @@ class PDFRenderer : public QObject
void setFileUuid(const QUuid &fileUuid); void setFileUuid(const QUuid &fileUuid);
static QMap< QUuid, QPointer<PDFRenderer> > sRenderers; static QMap< QUuid, QPointer<PDFRenderer> > sRenderers;
protected:
int dpiForRendering;
PDFRenderer();
}; };
#endif // PDFRENDERER_H #endif // PDFRENDERER_H

@ -39,8 +39,6 @@ XPDFRenderer::XPDFRenderer(const QString &filename, bool importingFile)
mDocument = new PDFDoc(new GString(filename.toUtf8().data()), 0, 0, 0); // the filename GString is deleted on PDFDoc desctruction mDocument = new PDFDoc(new GString(filename.toUtf8().data()), 0, 0, 0); // the filename GString is deleted on PDFDoc desctruction
sInstancesCount.ref(); sInstancesCount.ref();
mScaleX = 0.0;
mScaleY = 0.0;
} }
XPDFRenderer::~XPDFRenderer() XPDFRenderer::~XPDFRenderer()
@ -114,16 +112,17 @@ QSizeF XPDFRenderer::pageSizeF(int pageNumber) const
{ {
int rotate = mDocument->getPageRotate(pageNumber); int rotate = mDocument->getPageRotate(pageNumber);
cropWidth = mDocument->getPageCropWidth(pageNumber); cropWidth = mDocument->getPageCropWidth(pageNumber) * this->dpiForRendering / 72.0;
cropHeight = mDocument->getPageCropHeight(pageNumber); cropHeight = mDocument->getPageCropHeight(pageNumber) * this->dpiForRendering / 72.0;
if ((rotate == 90) || (rotate == 270)) if (rotate == 90 || rotate == 270)
{ {
cropWidth = mDocument->getPageCropHeight(pageNumber); //switching width and height
cropHeight = mDocument->getPageCropWidth(pageNumber); qreal tmpVar = cropWidth;
cropWidth = cropHeight;
cropHeight = tmpVar;
} }
} }
return QSizeF(cropWidth, cropHeight); return QSizeF(cropWidth, cropHeight);
} }
@ -142,14 +141,6 @@ void XPDFRenderer::render(QPainter *p, int pageNumber, const QRectF &bounds)
{ {
qreal xscale = p->worldTransform().m11(); qreal xscale = p->worldTransform().m11();
qreal yscale = p->worldTransform().m22(); qreal yscale = p->worldTransform().m22();
bool bZoomChanged = false;
if(fabs(mScaleX - xscale) > 0.1 || fabs(mScaleY - yscale) > 0.1)
{
mScaleX = xscale;
mScaleY = yscale;
bZoomChanged = true;
}
QImage *pdfImage = createPDFImage(pageNumber, xscale, yscale, bounds); QImage *pdfImage = createPDFImage(pageNumber, xscale, yscale, bounds);
QTransform savedTransform = p->worldTransform(); QTransform savedTransform = p->worldTransform();
@ -162,7 +153,6 @@ void XPDFRenderer::render(QPainter *p, int pageNumber, const QRectF &bounds)
QImage* XPDFRenderer::createPDFImage(int pageNumber, const qreal xscale, const qreal yscale, const QRectF &bounds) QImage* XPDFRenderer::createPDFImage(int pageNumber, const qreal xscale, const qreal yscale, const QRectF &bounds)
{ {
QImage* img = new QImage();
if (isValid()) if (isValid())
{ {
SplashColor paperColor = {0xFF, 0xFF, 0xFF}; // white SplashColor paperColor = {0xFF, 0xFF, 0xFF}; // white
@ -170,36 +160,30 @@ QImage* XPDFRenderer::createPDFImage(int pageNumber, const qreal xscale, const q
delete 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 vResolution = 72;
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)
GBool useMediaBox = gFalse; GBool useMediaBox = gFalse;
GBool crop = gTrue; GBool crop = gTrue;
GBool printing = gFalse; GBool printing = gFalse;
const qreal xScale = xscale;
const qreal yScale = yscale;
mSliceX = 0.; mSliceX = 0.;
mSliceY = 0.; mSliceY = 0.;
if (bounds.isNull()) if (bounds.isNull())
{ {
mDocument->displayPage(mSplash, pageNumber, hResolution * xScale, vResolution * yScale, mDocument->displayPage(mSplash, pageNumber, this->dpiForRendering, this->dpiForRendering,
rotation, useMediaBox, crop, printing); rotation, useMediaBox, crop, printing);
} }
else else
{ {
mSliceX = bounds.x() * xScale; mSliceX = bounds.x() * xscale;
mSliceY = bounds.y() * yScale; mSliceY = bounds.y() * yscale;
qreal sliceW = bounds.width() * xScale; qreal sliceW = bounds.width() * xscale;
qreal sliceH = bounds.height() * yScale; qreal sliceH = bounds.height() * yscale;
mDocument->displayPageSlice(mSplash, pageNumber, hResolution * xScale, vResolution * yScale, mDocument->displayPageSlice(mSplash, pageNumber, this->dpiForRendering, this->dpiForRendering,
rotation, useMediaBox, crop, printing, mSliceX, mSliceY, sliceW, sliceH); rotation, useMediaBox, crop, printing, mSliceX, mSliceY, sliceW, sliceH);
} }
mpSplashBitmap = mSplash->getBitmap(); mpSplashBitmap = mSplash->getBitmap();
delete img;
img = new QImage(mpSplashBitmap->getDataPtr(), mpSplashBitmap->getWidth(), mpSplashBitmap->getHeight(), mpSplashBitmap->getWidth() * 3, QImage::Format_RGB888);
} }
return img; return new QImage(mpSplashBitmap->getDataPtr(), mpSplashBitmap->getWidth(), mpSplashBitmap->getHeight(), mpSplashBitmap->getWidth() * 3, QImage::Format_RGB888);
} }

@ -57,8 +57,6 @@ class XPDFRenderer : public PDFRenderer
SplashBitmap* mpSplashBitmap; SplashBitmap* mpSplashBitmap;
SplashOutputDev* mSplash; SplashOutputDev* mSplash;
qreal mScaleX;
qreal mScaleY;
}; };
#endif // XPDFRENDERER_H #endif // XPDFRENDERER_H

Loading…
Cancel
Save