[Bug 1111083] New: QMetrics::width() return wrong value on bold fonts
http://bugzilla.opensuse.org/show_bug.cgi?id=1111083 Bug ID: 1111083 Summary: QMetrics::width() return wrong value on bold fonts Classification: openSUSE Product: openSUSE Distribution Version: Leap 15.0 Hardware: x86-64 OS: Other Status: NEW Severity: Critical Priority: P5 - None Component: Other Assignee: bnc-team-screening@forge.provo.novell.com Reporter: alberto.zacchetti@tiscali.it QA Contact: qa-bugs@suse.de Found By: --- Blocker: --- QMetrics::width() return wrong value on fonts with bold weight active. On normal weight font the returned value is fine. Same results with QMetrics::boundingRect(). The error occurs on some dimensions and not on others. On the same fonts, instead, the boundingRect is returned fine with QPainter::drawText() method. There does not seem to be any workaround. -- You are receiving this mail because: You are on the CC list for the bug.
http://bugzilla.opensuse.org/show_bug.cgi?id=1111083
Alberto Zacchetti
http://bugzilla.opensuse.org/show_bug.cgi?id=1111083
Andreas Stieger
http://bugzilla.opensuse.org/show_bug.cgi?id=1111083
http://bugzilla.opensuse.org/show_bug.cgi?id=1111083#c1
--- Comment #1 from Alberto Zacchetti
http://bugzilla.opensuse.org/show_bug.cgi?id=1111083
http://bugzilla.opensuse.org/show_bug.cgi?id=1111083#c2
--- Comment #2 from Alberto Zacchetti
http://bugzilla.opensuse.org/show_bug.cgi?id=1111083
http://bugzilla.opensuse.org/show_bug.cgi?id=1111083#c3
Andreas Stieger
http://bugzilla.opensuse.org/show_bug.cgi?id=1111083
http://bugzilla.opensuse.org/show_bug.cgi?id=1111083#c4
--- Comment #4 from Alberto Zacchetti
http://bugzilla.opensuse.org/show_bug.cgi?id=1111083
http://bugzilla.opensuse.org/show_bug.cgi?id=1111083#c5
--- Comment #5 from Andreas Stieger
http://bugzilla.opensuse.org/show_bug.cgi?id=1111083
http://bugzilla.opensuse.org/show_bug.cgi?id=1111083#c6
--- Comment #6 from Alberto Zacchetti
http://bugzilla.opensuse.org/show_bug.cgi?id=1111083
http://bugzilla.opensuse.org/show_bug.cgi?id=1111083#c7
--- Comment #7 from Alberto Zacchetti
http://bugzilla.opensuse.org/show_bug.cgi?id=1111083
Alberto Zacchetti
http://bugzilla.opensuse.org/show_bug.cgi?id=1111083
http://bugzilla.opensuse.org/show_bug.cgi?id=1111083#c8
Andreas Stieger
http://bugzilla.opensuse.org/show_bug.cgi?id=1111083
http://bugzilla.opensuse.org/show_bug.cgi?id=1111083#c9
Alberto Zacchetti
http://bugzilla.opensuse.org/show_bug.cgi?id=1111083
http://bugzilla.opensuse.org/show_bug.cgi?id=1111083#c10
--- Comment #10 from Alberto Zacchetti
http://bugzilla.opensuse.org/show_bug.cgi?id=1111083
Alberto Zacchetti
http://bugzilla.opensuse.org/show_bug.cgi?id=1111083
http://bugzilla.opensuse.org/show_bug.cgi?id=1111083#c11
--- Comment #11 from Max Lin
Created attachment 785950 [details] Qt test program
This is the Qt program I use to highlight the problem.
I can not reproduce it on GNOME, will upload a screenshot later. What is your result of w_in and w_out? -- You are receiving this mail because: You are on the CC list for the bug.
http://bugzilla.opensuse.org/show_bug.cgi?id=1111083
http://bugzilla.opensuse.org/show_bug.cgi?id=1111083#c12
--- Comment #12 from Max Lin
http://bugzilla.opensuse.org/show_bug.cgi?id=1111083
http://bugzilla.opensuse.org/show_bug.cgi?id=1111083#c13
--- Comment #13 from Alberto Zacchetti
http://bugzilla.opensuse.org/show_bug.cgi?id=1111083
http://bugzilla.opensuse.org/show_bug.cgi?id=1111083#c14
--- Comment #14 from Max Lin
Thanks for your tests. I tried on gnome (installed on a new account) with different QT_QPA_PLATFORMTHEME variables and the results are as follows:
QT_QPA_PLATFORMTHEME unset -> w_in == w_out QT_QPA_PLATFORMTHEME=gnome -> w_in == w_out QT_QPA_PLATFORMTHEME=kde -> w_in > w_out
I also noticed that in Gnome the Konsole font also works very badly, just like my programs do. w_in and w_out should never be different, because they refer to the metric of the same font.
Not 100% true, QPainter::setFont() has reconstructs QFont(const QFont &font, QPaintDevice *pd) with font.resolve(). can you add this 2 lines to last in your test program and attach the complete output? qDebug() << QFontInfo(painter.font()).family() << QFontInfo(painter.font()).pixelSize() << QFontInfo(painter.font()).exactMatch() << QFontInfo(painter.font()).bold(); qDebug() << QFontInfo(*font).family() << QFontInfo(*font).pixelSize() << QFontInfo(*font).exactMatch() << QFontInfo(*font).bold(); -- You are receiving this mail because: You are on the CC list for the bug.
http://bugzilla.opensuse.org/show_bug.cgi?id=1111083
http://bugzilla.opensuse.org/show_bug.cgi?id=1111083#c16
--- Comment #16 from Alberto Zacchetti
http://bugzilla.opensuse.org/show_bug.cgi?id=1111083
http://bugzilla.opensuse.org/show_bug.cgi?id=1111083#c17
--- Comment #17 from Alberto Zacchetti
(In reply to Alberto Zacchetti from comment #13)
Thanks for your tests. I tried on gnome (installed on a new account) with different QT_QPA_PLATFORMTHEME variables and the results are as follows:
QT_QPA_PLATFORMTHEME unset -> w_in == w_out QT_QPA_PLATFORMTHEME=gnome -> w_in == w_out QT_QPA_PLATFORMTHEME=kde -> w_in > w_out
I also noticed that in Gnome the Konsole font also works very badly, just like my programs do. w_in and w_out should never be different, because they refer to the metric of the same font.
Not 100% true, QPainter::setFont() has reconstructs QFont(const QFont &font, QPaintDevice *pd) with font.resolve().
can you add this 2 lines to last in your test program and attach the complete output?
qDebug() << QFontInfo(painter.font()).family() << QFontInfo(painter.font()).pixelSize() << QFontInfo(painter.font()).exactMatch() << QFontInfo(painter.font()).bold(); qDebug() << QFontInfo(*font).family() << QFontInfo(*font).pixelSize() << QFontInfo(*font).exactMatch() << QFontInfo(*font).bold();
Have you seen the two results I posted? -- You are receiving this mail because: You are on the CC list for the bug.
http://bugzilla.opensuse.org/show_bug.cgi?id=1111083
http://bugzilla.opensuse.org/show_bug.cgi?id=1111083#c18
Max Lin
http://bugzilla.opensuse.org/show_bug.cgi?id=1111083
http://bugzilla.opensuse.org/show_bug.cgi?id=1111083#c19
--- Comment #19 from Max Lin
http://bugzilla.opensuse.org/show_bug.cgi?id=1111083
http://bugzilla.opensuse.org/show_bug.cgi?id=1111083#c20
--- Comment #20 from Alberto Zacchetti
I can recommended that you can remove ",Regular" in "font=" option in your /etc/xdg/kdeglobals (and/or ~/.config/kdeglobals), this should fixed your problem. The fact why it does this way on KDE is still under investigation.
Yes, this solution works, but every time I make a change in the "system settings->font", the file ~/.config/kdeglobals is rewritten the value "Regular" and the bug reappears. -- You are receiving this mail because: You are on the CC list for the bug.
http://bugzilla.opensuse.org/show_bug.cgi?id=1111083
http://bugzilla.opensuse.org/show_bug.cgi?id=1111083#c21
Fabian Vogt
Yes, I see the result, this seems platform regarded, I suspecting plasma platformtheme handle this different than Qt, at least "Regular" in the file is wrong. This smells like https://bugs.kde.org/show_bug.cgi?id=378523 [1], Fabian, could it be?
Yes, definitely. It's not backported as it's a behaviour change. Please install plasma5-integration-plugin from https://download.opensuse.org/repositories/home:/Vogtinator:/branches:/openS... and try again, the ",Regular" in kdeglobals should not make a difference anymore.
[1] https://cgit.kde.org/plasma-integration.git/commit/ ?id=2e971be576d24a82974eaf2397d4703fca0188d8
-- You are receiving this mail because: You are on the CC list for the bug.
http://bugzilla.opensuse.org/show_bug.cgi?id=1111083
http://bugzilla.opensuse.org/show_bug.cgi?id=1111083#c22
--- Comment #22 from Alberto Zacchetti
(In reply to Max Lin from comment #18)
Yes, I see the result, this seems platform regarded, I suspecting plasma platformtheme handle this different than Qt, at least "Regular" in the file is wrong. This smells like https://bugs.kde.org/show_bug.cgi?id=378523 [1], Fabian, could it be?
Yes, definitely. It's not backported as it's a behaviour change.
Please install plasma5-integration-plugin from https://download.opensuse.org/repositories/home:/Vogtinator:/branches:/ openSUSE:/Leap:/15.0:/Update/openSUSE_Leap_15.0_Update and try again, the ",Regular" in kdeglobals should not make a difference anymore.
[1] https://cgit.kde.org/plasma-integration.git/commit/ ?id=2e971be576d24a82974eaf2397d4703fca0188d8
I have also installed your patch (5.12.6-lp150.2.6.1-x86_64), but the bug is still there. -- You are receiving this mail because: You are on the CC list for the bug.
http://bugzilla.opensuse.org/show_bug.cgi?id=1111083
http://bugzilla.opensuse.org/show_bug.cgi?id=1111083#c23
--- Comment #23 from Max Lin
http://bugzilla.opensuse.org/show_bug.cgi?id=1111083
http://bugzilla.opensuse.org/show_bug.cgi?id=1111083#c24
--- Comment #24 from Alberto Zacchetti
Looks StyleName will be appended to kdeglobals anyway, since Qt respects platform config I think you should update your code, as I explained it at https://bugzilla.opensuse.org/show_bug.cgi?id=1111083#c14 , QPainter::setFont() has called QFont::resolve(), it will reconstructs a QFont in case a given font's family is different than the system setting's one ie. carry properties if it exists, setBold() will be ignored if styleName is set.
Add font->setStyleName(QString()); to your code that reset styleName property should fix your problem. PS. I think many qt-based apps should did similar change in their code against this side-effect already.
I tried the two suggestions (QFont::resolve() and QFont::setStyleName()), but neither of them solves the problem completely. QFont::setStyleName(QString()) resets the styles, but if I set a "bold" font from the system settings and inside the program I use it without bold, the metric is still different. The best result seems to be with QFont::resolve(), because the metrics always match, but now the results differ between the kde platform and the others. Look at these results: QT_QPA_PLATFORMTHEME=gnome inside 186, font: Liberation Sans,-1,20,5,75,0,0,0,0,0 outside 186, font: Liberation Sans,-1,20,5,75,0,0,0,0,0 "Liberation Sans" 20 true true "Bold" "Liberation Sans" 20 true true "Bold" QT_QPA_PLATFORMTHEME=kde inside 195, font: Liberation Sans,-1,20,5,75,0,0,0,0,0,Regular outside 195, font: Liberation Sans,-1,20,5,75,0,0,0,0,0,Regular "Liberation Sans" 20 true true "Regular" "Liberation Sans" 20 true true "Regular" -- You are receiving this mail because: You are on the CC list for the bug.
participants (1)
-
bugzilla_noreply@novell.com