Details
-
Bug
-
Resolution: Done
-
P2: Important
-
4.7.3, 5.3.0, 5.3.1, 5.3.2
-
Windows 7 x64
Update :
All Windows Platforms
-
6a3f8cbc3ad47d8585aac25d3775ed2350afe20c (qt/qtbase/dev) 9e278ec1f570fb7150cf0053727fe45d187a6bab (qt/qtbase/6.0) 99d3a65cf373bd563710ff91d9922845befa47a2 (qt/tqtc-qtbase/tqtc/lts-5.15)
Description
On Windows only, the spacing between characters is often incorrect when using QPainterPath::addText. In the test application below, the drawn strings should be more or less identical.
#include <QtGui> #include <QFont> class MyWidget : public QWidget { public: MyWidget(QWidget *parent = NULL) : QWidget(parent) { setFixedSize(100, 100); } protected: void paintEvent(QPaintEvent *) { QFont f; f.setFamily("Arial"); f.setPixelSize(11); QPainterPath path; path.addText(50, 50, f, "wiwi"); QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing, true); painter.setBrush(Qt::SolidPattern); painter.setPen(Qt::NoPen); painter.drawPath(path); painter.setFont(f); painter.setBrush(Qt::NoBrush); painter.setPen(Qt::SolidLine); painter.drawText(50, 70, "wiwi"); } }; int main(int argc, char **argv) { QApplication app(argc, argv); MyWidget w; w.show(); return app.exec(); }
A screenshot of what this looks like on my machine is attached. Some things I have noticed:
- It is fine on X11 (Ubuntu, at least) and Mac OS X.
- It only affects certain fonts at certain sizes. If, for example, you change the font in the example to pixel size 12 or point size 11, it looks fine.
In my application I have to use a QPainterPath, and the output looks horrible on Windows because of this.
Some more information. I wrote out all the points that are being used for the outline of the "w". Note that the path is drawn such that the left-most part is at 50, and the width is a little under 8.
moveTo QPointF(51.7778, 50) lineTo QPointF(50.0322, 44.2959) lineTo QPointF(51.0312, 44.2959) lineTo QPointF(51.939, 47.5884) lineTo QPointF(52.2773, 48.813) quadTo QPointF(52.2988, 48.7217) QPointF(52.5728, 47.6367) lineTo QPointF(53.4805, 44.2959) lineTo QPointF(54.4741, 44.2959) lineTo QPointF(55.3281, 47.6045) lineTo QPointF(55.6128, 48.6948) lineTo QPointF(55.9404, 47.5938) lineTo QPointF(56.918, 44.2959) lineTo QPointF(57.8579, 44.2959) lineTo QPointF(56.0747, 50) lineTo QPointF(55.0703, 50) lineTo QPointF(54.1626, 46.584) lineTo QPointF(53.9424, 45.6118) lineTo QPointF(52.7876, 50)
The problem seems to be that the "w" as drawn by addText is putting the left of the "w" at 51. There is a tiny pixel bleed that goes at x=50, but this bleed is not reflected in the path information. Thus, the "w" is shifted one pixel too far to the left on the path (or 1 pixel too far to the right on addText, one could argue.) In the screenshot below, the red line is at x=49. Notice that the first "w" (addPath) starts at 50 and is roughly 8 pixels wide. The second "w" (addText) really starts at 51 (with a pixel bleed at 50) and has a width of 10.
Attachments
Issue Links
- replaces
-
QTBUG-21377 QPainter::drawText with rotated painter has incorrect spacing on Windows only
- Closed
For Gerrit Dashboard: QTBUG-20900 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
329582,2 | Use design metrics when adding text to QPainterPath | 6.0 | qt/qtbase | Status: MERGED | +2 | 0 |
329620,2 | Use design metrics when adding text to QPainterPath | dev | qt/qtbase | Status: MERGED | +2 | 0 |
329676,2 | Use design metrics when adding text to QPainterPath | tqtc/lts-5.15 | qt/tqtc-qtbase | Status: MERGED | +2 | 0 |