diff --git a/PdfForQtLib/sources/pdfdrawspacecontroller.cpp b/PdfForQtLib/sources/pdfdrawspacecontroller.cpp index d22ecf9..86ef52a 100644 --- a/PdfForQtLib/sources/pdfdrawspacecontroller.cpp +++ b/PdfForQtLib/sources/pdfdrawspacecontroller.cpp @@ -348,7 +348,7 @@ PDFDrawWidgetProxy::PDFDrawWidgetProxy(QObject* parent) : m_widget(nullptr), m_horizontalScrollbar(nullptr), m_verticalScrollbar(nullptr), - m_features(PDFRenderer::Antialiasing | PDFRenderer::TextAntialiasing) + m_features(PDFRenderer::getDefaultFeatures()) { m_controller = new PDFDrawSpaceController(this); connect(m_controller, &PDFDrawSpaceController::drawSpaceChanged, this, &PDFDrawWidgetProxy::update); diff --git a/PdfForQtLib/sources/pdfpainter.cpp b/PdfForQtLib/sources/pdfpainter.cpp index 4fef818..8c5831c 100644 --- a/PdfForQtLib/sources/pdfpainter.cpp +++ b/PdfForQtLib/sources/pdfpainter.cpp @@ -101,17 +101,46 @@ void PDFPainter::performImagePainting(const QImage& image) m_painter->save(); - // TODO: Draw smooth images - QMatrix imageTransform(1.0 / image.width(), 0, 0, 1.0 / image.height(), 0, 0); + QImage adjustedImage = image; + + if (m_features.testFlag(PDFRenderer::SmoothImages)) + { + // Test, if we can use smooth images. We can use them under following conditions: + // 1) Transformed rectangle is not skewed or deformed (so vectors (0, 1) and (1, 0) are orthogonal) + // 2) Image enlargement is not too big (so we doesn't run out of memory) + + QMatrix matrix = m_painter->worldMatrix(); + QLineF mappedWidthVector = matrix.map(QLineF(0, 0, 1, 0)); + QLineF mappedHeightVector = matrix.map(QLineF(0, 0, 0, 1)); + qreal angle = mappedWidthVector.angleTo(mappedHeightVector); + if (qFuzzyCompare(angle, 90.0)) + { + // Image is not skewed, so we test enlargement factor + const int newWidth = mappedWidthVector.length(); + const int newHeight = mappedHeightVector.length(); + + const int newPixels = newWidth * newHeight; + const int oldPixels = image.width() * image.height(); + + if (newPixels < oldPixels * 8) + { + QSize size = adjustedImage.size(); + QSize adjustedImageSize = size.scaled(newWidth, newHeight, Qt::KeepAspectRatio); + adjustedImage = adjustedImage.scaled(adjustedImageSize, Qt::KeepAspectRatio, Qt::SmoothTransformation); + } + } + } + + QMatrix imageTransform(1.0 / adjustedImage.width(), 0, 0, 1.0 / adjustedImage.height(), 0, 0); QMatrix worldMatrix = imageTransform * m_painter->worldMatrix(); // Because Qt uses opposite axis direction than PDF, then we must transform the y-axis // to the opposite (so the image is then unchanged) - worldMatrix.translate(0, image.height()); + worldMatrix.translate(0, adjustedImage.height()); worldMatrix.scale(1, -1); m_painter->setWorldMatrix(worldMatrix); - m_painter->drawImage(0, 0, image); + m_painter->drawImage(0, 0, adjustedImage); m_painter->restore(); } diff --git a/PdfForQtLib/sources/pdfrenderer.cpp b/PdfForQtLib/sources/pdfrenderer.cpp index a9b5089..9962d88 100644 --- a/PdfForQtLib/sources/pdfrenderer.cpp +++ b/PdfForQtLib/sources/pdfrenderer.cpp @@ -32,7 +32,6 @@ PDFRenderer::PDFRenderer(const PDFDocument* document, const PDFFontCache* fontCa } // TODO: Dodelat rotovani stranek -// TODO: Dodelat obrazky - SMOOTH // TODO: Clipovani na stranku QList PDFRenderer::render(QPainter* painter, const QRectF& rectangle, size_t pageIndex) const diff --git a/PdfForQtViewer/pdfviewermainwindow.h b/PdfForQtViewer/pdfviewermainwindow.h index 7105948..13e4600 100644 --- a/PdfForQtViewer/pdfviewermainwindow.h +++ b/PdfForQtViewer/pdfviewermainwindow.h @@ -49,7 +49,7 @@ class PDFViewerSettings : public QObject public: inline explicit PDFViewerSettings(QObject* parent) : QObject(parent), - m_features(pdf::PDFRenderer::Antialiasing | pdf::PDFRenderer::TextAntialiasing) + m_features(pdf::PDFRenderer::getDefaultFeatures()) { }