diff options
author | Qt Continuous Integration System <qt-info@nokia.com> | 2010-07-05 13:19:21 (GMT) |
---|---|---|
committer | Qt Continuous Integration System <qt-info@nokia.com> | 2010-07-05 13:19:21 (GMT) |
commit | a67882cd976830bcd955a66ee06aadec97f4e53a (patch) | |
tree | a5630d29d964b32900c77f139d7ee98792c21a03 /src | |
parent | 4e349cbea021bd504eb8c1575463fd8ee9ba937b (diff) | |
parent | a0a61fed0f0879282489b111a059e192ef89fc60 (diff) | |
download | Qt-a67882cd976830bcd955a66ee06aadec97f4e53a.zip Qt-a67882cd976830bcd955a66ee06aadec97f4e53a.tar.gz Qt-a67882cd976830bcd955a66ee06aadec97f4e53a.tar.bz2 |
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/oslo-staging-2 into 4.7-integration
* '4.7' of scm.dev.nokia.troll.no:qt/oslo-staging-2:
Revert "Character spacing when drawing a QPicture to a high DPI device."
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/image/qpicture.cpp | 52 |
1 files changed, 39 insertions, 13 deletions
diff --git a/src/gui/image/qpicture.cpp b/src/gui/image/qpicture.cpp index 20a1dce..48d2de3 100644 --- a/src/gui/image/qpicture.cpp +++ b/src/gui/image/qpicture.cpp @@ -440,6 +440,36 @@ bool QPicture::play(QPainter *painter) return true; // no end-command } + +// +// QFakeDevice is used to create fonts with a custom DPI +// +class QFakeDevice : public QPaintDevice +{ +public: + QFakeDevice() { dpi_x = qt_defaultDpiX(); dpi_y = qt_defaultDpiY(); } + void setDpiX(int dpi) { dpi_x = dpi; } + void setDpiY(int dpi) { dpi_y = dpi; } + QPaintEngine *paintEngine() const { return 0; } + int metric(PaintDeviceMetric m) const + { + switch(m) { + case PdmPhysicalDpiX: + case PdmDpiX: + return dpi_x; + case PdmPhysicalDpiY: + case PdmDpiY: + return dpi_y; + default: + return QPaintDevice::metric(m); + } + } + +private: + int dpi_x; + int dpi_y; +}; + /*! \internal Iterates over the internal picture data and draws the picture using @@ -649,16 +679,13 @@ bool QPicture::exec(QPainter *painter, QDataStream &s, int nrecords) if (d->formatMajor >= 9) { s >> dbl; - QFont fnt(font, painter->device()); - - // Fonts that specify a pixel size should not be scaled - QPicture already - // have a matrix set to compensate for the DPI differences between the - // default Qt DPI and the actual target device DPI, and we have to take that - // into consideration in the case where the font has a pixel size set. - - qreal scale = fnt.pointSize() == -1 ? 1 : painter->device()->logicalDpiY() / (dbl*qt_defaultDpiY()); - painter->save(); - painter->scale(1/scale, 1/scale); + QFont fnt(font); + if (dbl != 1.0) { + QFakeDevice fake; + fake.setDpiX(qRound(dbl*qt_defaultDpiX())); + fake.setDpiY(qRound(dbl*qt_defaultDpiY())); + fnt = QFont(font, &fake); + } qreal justificationWidth; s >> justificationWidth; @@ -667,16 +694,15 @@ bool QPicture::exec(QPainter *painter, QDataStream &s, int nrecords) QSizeF size(1, 1); if (justificationWidth > 0) { - size.setWidth(justificationWidth*scale); + size.setWidth(justificationWidth); flags |= Qt::TextJustificationForced; flags |= Qt::AlignJustify; } QFontMetrics fm(fnt); - QPointF pt(p.x()*scale, p.y()*scale - fm.ascent()); + QPointF pt(p.x(), p.y() - fm.ascent()); qt_format_text(fnt, QRectF(pt, size), flags, /*opt*/0, str, /*brect=*/0, /*tabstops=*/0, /*...*/0, /*tabarraylen=*/0, painter); - painter->restore(); } else { qt_format_text(font, QRectF(p, QSizeF(1, 1)), Qt::TextSingleLine | Qt::TextDontClip, /*opt*/0, str, /*brect=*/0, /*tabstops=*/0, /*...*/0, /*tabarraylen=*/0, painter); |