[KFontChooser] Make styleIdentifier() more precise by adding font styleName
ClosedPublic

Authored by ahmadsamir on Apr 19 2020, 8:48 AM.

Details

Summary

styleIdentifier() tries to get the correct font style based on weight,
style, and stretch; this "styleID" could be the same for different font
styles in the same family, and it worked in most cases because "Regular"-like
styles usually are ordered first in the family styles list from QFontDatabase.
However this breaks for font families that provide many font styles, e.g.
Noto Sans, where "SemiCondensed" comes first in the list.

Make it more precise by adding the font "styleName" property to the
"styleID" we concatenate, this makes it more precise. Also handle empty
styleName font prop. (we strip it on purpose, see KConfigGroupGui::writeEntryGui()
for more details), try to pick the correct one so that we highlight
it in the font style list view.

Test Plan

kfontchooserdialogtest app, with the initial font set to "Noto Sans",
before this change it'd select "SemiCondensed"; now it selects "Regular"
as expected.

BUG: 420287
FIXED-IN: 5.70

Diff Detail

Repository
R236 KWidgetsAddons
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
ahmadsamir created this revision.Apr 19 2020, 8:48 AM
Restricted Application added a project: Frameworks. · View Herald TranscriptApr 19 2020, 8:48 AM
ahmadsamir requested review of this revision.Apr 19 2020, 8:48 AM
dfaure accepted this revision.Apr 19 2020, 9:26 AM

You're like a bugfixing machine, very impressive :-)

This revision is now accepted and ready to land.Apr 19 2020, 9:26 AM

This particular one is the same bug, we've been fixing it for a couple of months now; in KConfig, in the Fonts KCM/KFontChooser*, we even had to bring KFontDialog back from the deprecation pile in KDELibs4Support (for this and for decimal font sizes which QFontDialog doesn't allow) all that because upstream most likely won't take a patch that clears a font styleName property when it's weight is Normal and the style name is Regular|Normal|Book|Roman... I don't claim to understand their reasons (I keep finding new reasons as I look at it more) but sometimes technical-correctness isn't that "correct".

This revision was automatically updated to reflect the committed changes.