summaryrefslogtreecommitdiffstats
path: root/src/gui/image
diff options
context:
space:
mode:
authorTrond Kjernåsen <trond@trolltech.com>2009-11-13 16:38:02 (GMT)
committerTrond Kjernåsen <trond@trolltech.com>2009-11-13 16:38:02 (GMT)
commitd0fb8557f3fc3e7c9305662d118228ceca9df72b (patch)
tree48a577a1e45b4c4ebb6648edf533e4ec76efdbdd /src/gui/image
parentf1aeeb025c5042f6684855006f963e2203d9c153 (diff)
downloadQt-d0fb8557f3fc3e7c9305662d118228ceca9df72b.zip
Qt-d0fb8557f3fc3e7c9305662d118228ceca9df72b.tar.gz
Qt-d0fb8557f3fc3e7c9305662d118228ceca9df72b.tar.bz2
Character spacing when drawing a QPicture to a high DPI device.
Drawing some text into a QPicture, and then drawing that QPicture to e.g. a QPrinter, would make the character spacing all wrong. The old approach that tried to fix this adjusted the DPI of the font that was used, so that the text size would be correct. It seems this is not enough, since it will lay out the text in the default resolution, and then scale that up, which may/may not introduce errors. Task-number: QTBUG-4974, 256481 Reviewed-by: Kim
Diffstat (limited to 'src/gui/image')
-rw-r--r--src/gui/image/qpicture.cpp49
1 files changed, 9 insertions, 40 deletions
diff --git a/src/gui/image/qpicture.cpp b/src/gui/image/qpicture.cpp
index f502827..6c5fb02 100644
--- a/src/gui/image/qpicture.cpp
+++ b/src/gui/image/qpicture.cpp
@@ -440,36 +440,6 @@ 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
@@ -679,30 +649,29 @@ bool QPicture::exec(QPainter *painter, QDataStream &s, int nrecords)
if (d->formatMajor >= 9) {
s >> dbl;
- 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);
- }
+ QFont fnt(font, painter->device());
+
+ qreal scale = painter->device()->logicalDpiY() / (dbl*qt_defaultDpiY());
+ painter->save();
+ painter->scale(1/scale, 1/scale);
qreal justificationWidth;
s >> justificationWidth;
int flags = Qt::TextSingleLine | Qt::TextDontClip | Qt::TextForceLeftToRight;
- QSizeF size(1, 1);
+ QSizeF size(scale, scale);
if (justificationWidth > 0) {
- size.setWidth(justificationWidth);
+ size.setWidth(justificationWidth*scale);
flags |= Qt::TextJustificationForced;
flags |= Qt::AlignJustify;
}
QFontMetrics fm(fnt);
- QPointF pt(p.x(), p.y() - fm.ascent());
+ QPointF pt(p.x()*scale, p.y()*scale - 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);