summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTrond Kjernåsen <trond.kjernasen@nokia.com>2010-07-05 08:48:29 (GMT)
committerTrond Kjernåsen <trond.kjernasen@nokia.com>2010-07-05 08:52:41 (GMT)
commita0a61fed0f0879282489b111a059e192ef89fc60 (patch)
treec8fd914b1c5294fc7e9f92da4f7cc3406b988968
parent76aad35bd9f699c966295738095d245a5e7a6457 (diff)
downloadQt-a0a61fed0f0879282489b111a059e192ef89fc60.zip
Qt-a0a61fed0f0879282489b111a059e192ef89fc60.tar.gz
Qt-a0a61fed0f0879282489b111a059e192ef89fc60.tar.bz2
Revert "Character spacing when drawing a QPicture to a high DPI device."
This reverts commit d0fb8557f3fc3e7c9305662d118228ceca9df72b. This change breaks justified text drawing in QPrintPreview, so it's reverted for now.
-rw-r--r--src/gui/image/qpicture.cpp52
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);