diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp index de1e555771..975ef54d6b 100644 --- a/src/gui/image/qimage.cpp +++ b/src/gui/image/qimage.cpp @@ -99,8 +99,6 @@ QImageData::QImageData() format(QImage::Format_ARGB32), bytes_per_line(0), ser_no(qimage_serial_number.fetchAndAddRelaxed(1)), detach_no(0), - ldpmx(qt_defaultDpiX() * 100 / qreal(2.54)), - ldpmy(qt_defaultDpiY() * 100 / qreal(2.54)), dpmx(qt_defaultDpiX() * 100 / qreal(2.54)), dpmy(qt_defaultDpiY() * 100 / qreal(2.54)), offset(0, 0), own_data(true), ro_data(false), has_alpha_clut(false), @@ -4984,11 +4982,11 @@ int QImage::metric(PaintDeviceMetric metric) const return d->depth; case PdmDpiX: - return qRound(d->ldpmx * 0.0254); + return qRound(d->dpmx * 0.0254); break; case PdmDpiY: - return qRound(d->ldpmy * 0.0254); + return qRound(d->dpmy * 0.0254); break; case PdmPhysicalDpiX: diff --git a/src/gui/image/qimage_p.h b/src/gui/image/qimage_p.h index e79eb9d562..18c686e917 100644 --- a/src/gui/image/qimage_p.h +++ b/src/gui/image/qimage_p.h @@ -82,10 +82,8 @@ struct Q_GUI_EXPORT QImageData { // internal image data int ser_no; // serial number int detach_no; - qreal ldpmx; // logical dots per meter X (or 0) - qreal ldpmy; // logical dots per meter Y (or 0) - qreal dpmx; // device dots per meter X (or 0) - qreal dpmy; // device dots per meter Y (or 0) + qreal dpmx; // dots per meter X (or 0) + qreal dpmy; // dots per meter Y (or 0) QPoint offset; // offset in pixels uint own_data : 1; diff --git a/tests/auto/gui/image/qimage/tst_qimage.cpp b/tests/auto/gui/image/qimage/tst_qimage.cpp index 6f372b0160..b668f57909 100644 --- a/tests/auto/gui/image/qimage/tst_qimage.cpp +++ b/tests/auto/gui/image/qimage/tst_qimage.cpp @@ -86,6 +86,7 @@ private slots: #endif void dotsPerMeterZero(); + void dotsPerMeterAndDpi(); void convertToFormatPreserveDotsPrMeter(); void convertToFormatPreserveText(); @@ -899,6 +900,27 @@ void tst_QImage::dotsPerMeterZero() QCOMPARE(img.dotsPerMeterX(), defaultDpmX); QCOMPARE(img.dotsPerMeterY(), defaultDpmY); + +} + +// verify that setting dotsPerMeter has an effect on the dpi. +void tst_QImage::dotsPerMeterAndDpi() +{ + QImage img(100, 100, QImage::Format_RGB32); + QVERIFY(!img.isNull()); + + QPoint defaultLogicalDpi(img.logicalDpiX(), img.logicalDpiY()); + QPoint defaultPhysicalDpi(img.physicalDpiX(), img.physicalDpiY()); + + img.setDotsPerMeterX(100); // set x + QCOMPARE(img.logicalDpiY(), defaultLogicalDpi.y()); // no effect on y + QCOMPARE(img.physicalDpiY(), defaultPhysicalDpi.y()); + QVERIFY(img.logicalDpiX() != defaultLogicalDpi.x()); // x changed + QVERIFY(img.physicalDpiX() != defaultPhysicalDpi.x()); + + img.setDotsPerMeterY(200); // set y + QVERIFY(img.logicalDpiY() != defaultLogicalDpi.y()); // y changed + QVERIFY(img.physicalDpiY() != defaultPhysicalDpi.y()); } void tst_QImage::rotate_data()