Bug 2179854 - Qt 5 render the Bold style CJK character very thick with Noto CJK variable fonts
Summary: Qt 5 render the Bold style CJK character very thick with Noto CJK variable fonts
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: qt5-qtbase
Version: 38
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Than Ngo
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard: AcceptedFreezeException
Depends On:
Blocks: F38FinalFreezeException
TreeView+ depends on / blocked
 
Reported: 2023-03-20 09:38 UTC by Peng Wu
Modified: 2023-03-31 01:34 UTC (History)
13 users (show)

Fixed In Version: qt5-qtbase-5.15.8-10.fc38
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2023-03-31 01:34:05 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)
Draft patch to fix the bold style issue (1.22 KB, patch)
2023-03-21 04:21 UTC, Peng Wu
no flags Details | Diff
Screenshot of the bold style Chinese text (64.25 KB, image/png)
2023-03-22 05:31 UTC, Peng Wu
no flags Details
Yet another proposed patch (5.55 KB, patch)
2023-03-25 08:22 UTC, Akira TAGOH
no flags Details | Diff
v2 (5.56 KB, patch)
2023-03-27 05:21 UTC, Akira TAGOH
no flags Details | Diff
Draft patch for the bold style issue v2 (3.40 KB, patch)
2023-03-28 08:55 UTC, Peng Wu
no flags Details | Diff
v3 (5.59 KB, patch)
2023-03-29 10:47 UTC, Akira TAGOH
no flags Details | Diff
v4 (5.60 KB, patch)
2023-03-29 10:53 UTC, Akira TAGOH
no flags Details | Diff


Links
System ID Private Priority Status Summary Last Updated
Qt Bug Tracker QTBUG-112136 0 Not Evaluated Reported Unable to pick up styles properly from Variable fonts 2023-03-20 09:46:12 UTC

Description Peng Wu 2023-03-20 09:38:35 UTC
Description of problem:

After switch to use Noto CJK variable fonts, the Chinese characters with Bold style become very thick in Qt 5.


Version-Release number of selected component (if applicable):
qt5-qtbase-gui-5.15.8-6.fc38.x86_64

How reproducible:
Launch dolphin file manager, the Bold text about the path becomes very thick, and hard to read.

Steps to Reproduce:
1. Upgrade Fedora Kinoite to latest version to install Noto CJK VF fonts
2. Switch desktop to use Chinese locale or set LANG and LC_ALL to use Chinese locale
3. Launch dolphin and change to Desktop directory, and the "桌面" text becomes very thick

Actual results:
The rendering result is thicker than the normal Noto CJK fonts, and hard to read.

Expected results:
The rendering result is the same as the normal Noto CJK fonts.

Additional info:

Comment 1 Akira TAGOH 2023-03-20 09:46:13 UTC
I investigated this too.  This is because Qt renders texts with the synthetic emboldening when they choose a variable font.

I've opened an issue on upstream issue tracker here: https://bugreports.qt.io/browse/QTBUG-112136

See more details there.

Comment 2 Peng Wu 2023-03-20 10:08:17 UTC
It seems the following environment variable works around this issue.

$export QT_NO_SYNTHESIZED_BOLD=1
$dolphin

Comment 3 Than Ngo 2023-03-20 10:42:33 UTC
Akia, thanks for reporting this issue by upstream.

Comment 4 Peng Wu 2023-03-21 04:21:13 UTC
Created attachment 1952248 [details]
Draft patch to fix the bold style issue

The named instance comes from a GX or OpenType variation font, assume that the font contains the bold style.

This draft patch disables embolden with the GX or OpenType variation font.

Comment 5 Than Ngo 2023-03-21 07:56:03 UTC
(In reply to Peng Wu from comment #4)
> Created attachment 1952248 [details]
> Draft patch to fix the bold style issue
> 
> The named instance comes from a GX or OpenType variation font, assume that
> the font contains the bold style.
> 
> This draft patch disables embolden with the GX or OpenType variation font.

Peng, could you please forward your draft patch to upstream for review (https://bugreports.qt.io/browse/QTBUG-112136)?

Thanks!

Comment 6 Peng Wu 2023-03-21 10:01:43 UTC
Okay, I just uploaded the patch and added some comment.

Comment 7 Peng Wu 2023-03-22 05:31:17 UTC
Created attachment 1952660 [details]
Screenshot of the bold style Chinese text

The Chinese text in the red frame is very thick and hard to read.

Comment 8 Akira TAGOH 2023-03-22 06:52:40 UTC
Apparently you are misunderstanding the problem.  They did the synthetic emboldening because they got a Regular font even though they requested a Bold font. thus, they just considered there are no Bold font available for it.

So preventing the synthetic emboldening is the wrong fix. and your patch will introduces another issue that you don't get rendering with Bold on VF.

Comment 9 Akira TAGOH 2023-03-25 08:22:55 UTC
Created attachment 1953537 [details]
Yet another proposed patch

This patch actually contains two fixes.

One is to pull in proper information from FcPattern. As I said earlier, fontconfig doesn't evaluate FC_INDEX to estimate the best font against a query on FcFontMatch(). it may just works in some case but we need to pick up a correct FcPattern corresponding to FC_FILE and FC_INDEX because only these two properties are reliable on Qt since they store them only from polulating fonts from FcFontList().

Another one is to estimate weight properly for variable fonts. they don't have FT_STYLE_FLAG_BOLD in face->style_flags for the named-instance of Bold. Peng's patch ignores the synthetic emboldening for named-instance anyway, but this could be a problem if varlable fonts doesn't have weight axis. we have to estimate proper weight value to see if they really need to do the synthetic emboldening.

Comment 10 Akira TAGOH 2023-03-27 05:21:49 UTC
Created attachment 1953864 [details]
v2

I should do the null-check for FT_MM_Var.

Comment 11 Than Ngo 2023-03-27 06:27:27 UTC
Akira, could you please forward your patch to upstream for review? 

Thanks!

Comment 12 Than Ngo 2023-03-27 12:10:44 UTC
i built qt5-qtbase/qt5-qtwayland including your patch for rawhide and f38.
 https://koji.fedoraproject.org/koji/buildinfo?buildID=2176339
 https://koji.fedoraproject.org/koji/buildinfo?buildID=2176011
 https://koji.fedoraproject.org/koji/buildinfo?buildID=2176329

I will push them into f38 update today.

Comment 13 Fedora Update System 2023-03-27 13:55:36 UTC
FEDORA-2023-de53467a12 has been submitted as an update to Fedora 38. https://bodhi.fedoraproject.org/updates/FEDORA-2023-de53467a12

Comment 14 Brian Morrison 2023-03-27 22:54:58 UTC
I tried the qt5-qtbase and qt5-qtwayland updates in the update from comment 13.

I find that it causes all of my Qt program windows to lose all of their menu text and many of the controls also shrink. This could be because the compositor seems to think that there is no font present, maybe it now doesn't find any suitable font?

I am using a standard en_GB locale and the default fonts in my GNOME Wayland desktop. I'm not using any Chinese fonts or locales.

Comment 15 Fedora Update System 2023-03-28 03:43:04 UTC
FEDORA-2023-de53467a12 has been pushed to the Fedora 38 testing repository.

You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2023-de53467a12

See also https://fedoraproject.org/wiki/QA:Updates_Testing for more information on how to test updates.

Comment 16 Geoffrey Marr 2023-03-28 05:24:48 UTC
Discussed during the 2023-03-27 blocker review meeting: [0]

The decision to classify this bug as an "AcceptedFreezeException (Final)" was made as it is a clear visual quality issue that will be encountered on live boots by CJK users.

[0] https://meetbot.fedoraproject.org/fedora-blocker-review/2023-03-27/f38-blocker-review.2023-03-27-16.00.txt

Comment 17 Jan Grulich 2023-03-28 05:29:32 UTC
I unpushed the update sin(In reply to Brian Morrison from comment #14)
> I tried the qt5-qtbase and qt5-qtwayland updates in the update from comment
> 13.
> 
> I find that it causes all of my Qt program windows to lose all of their menu
> text and many of the controls also shrink. This could be because the
> compositor seems to think that there is no font present, maybe it now
> doesn't find any suitable font?
> 
> I am using a standard en_GB locale and the default fonts in my GNOME Wayland
> desktop. I'm not using any Chinese fonts or locales.

I unpushed the update based on this comment. You should have tested a scratch build at least before pushing an unverified fix or wait until it lands upstream.

Comment 18 Than Ngo 2023-03-28 06:53:46 UTC
Created attachment 1954086 [details]
test screenshot

Comment 19 Than Ngo 2023-03-28 06:54:46 UTC
(In reply to Jan Grulich from comment #17)
> I unpushed the update sin(In reply to Brian Morrison from comment #14)
> > I tried the qt5-qtbase and qt5-qtwayland updates in the update from comment
> > 13.
> > 
> > I find that it causes all of my Qt program windows to lose all of their menu
> > text and many of the controls also shrink. This could be because the
> > compositor seems to think that there is no font present, maybe it now
> > doesn't find any suitable font?
> > 
> > I am using a standard en_GB locale and the default fonts in my GNOME Wayland
> > desktop. I'm not using any Chinese fonts or locales.
> 
> I unpushed the update based on this comment. You should have tested a
> scratch build at least before pushing an unverified fix or wait until it
> lands upstream.

I have tested it under both KDE and GNOME. It worked flawlessly for me (look at above my test screenshot). It may be that under certain conditions such problem can occur. We need to test it intensively.

@Akira, @Peng, Can you please test it?

Thanks a lot!

Comment 20 Akira TAGOH 2023-03-28 07:46:18 UTC
Yes, I can confirm this regression. This seems to happen with some variable fonts such as Cantarell and some variants of Noto Sans. I'm looking into it now.

Comment 21 Peng Wu 2023-03-28 08:08:10 UTC
I can reproduce this issue. I guess if login with CJK locale like Chinese, it will be easier to reproduce this issue.

Comment 22 Peng Wu 2023-03-28 08:55:29 UTC
Created attachment 1954106 [details]
Draft patch for the bold style issue v2

Comment 23 Peng Wu 2023-03-28 09:01:03 UTC
As Akira Tagoh said, there are two issues in the code, so I just updated my patch.

1. The usage of FcFontMatch may be not correct, as it doesn't compare the FC_INDEX when matching. In the patch, I switch to use FcFontSort, the FcFontSort code will match FC_FILE; and after the FcFontSort function return, we compare the FC_INDEX to get the correct font face.

2. Switch to use the embolden value from the fontconfig, instead of computing it in the freetype code in Linux. The freetype code will override the embolden value from fontconfig, so the patch also disables the freetype code to compute the embolden value in Qt.

Comment 24 Peng Wu 2023-03-28 09:50:50 UTC
BTW, the patch disables the freetype code about embolden value in Qt with Linux only.

And in fontconfig, the similar logic of the freetype code is implemented in the /etc/fonts/conf.d/90-synthetic.conf file.

Comment 25 Akira TAGOH 2023-03-28 10:05:13 UTC
You can't replace FcFontMatch with FcFontSort. I'm not sure if there are really any such code paths though, they set FC_FILE and FC_INDEX only when QFontEngine::FaceId has a filename.  This implies that filename and index isn't always available; maybe application specific font?

Anyway, you still need to fallback to FcFontMatch in that case as I wrote it that way in my patch. Apparently you didn't seem to read it though.

Comment 26 Akira TAGOH 2023-03-29 10:47:15 UTC
Created attachment 1954381 [details]
v3

I'm almost consluding that we need to implement full-support of variable fonts if we want to fix this in a legitimate manner.  Apparently FreeType considered applications is capable to process variable fonts if one uses some variable fonts related APIs such as FT_Get_MM_Var().  This may be the reason why we saw the fail of loading glyph error from FreeType with my patch.  We need to set coordinates with axis.  Honestly implementing complete code for variable fonts in f38 timeframe isn't realistic.  So I gave up to fix this that way.

FWIW I partly agree with Peng's code, particularly leaving the emboldening conditions to fontconfig. Actually this is the same to what cairo does. However, I wonder if it is really only used for Linux because there are MinGW package for Qt and they could use fontconfig.

I picked it up to my patch and updated a bit to get it work without ifdef. See attached.
Also, I built qt5-qtbase (only this time; so you need to try it with X11 only) on copr:
https://copr.fedorainfracloud.org/coprs/tagoh/qt5-qtbase/

You can try to test if you like. I did. that works for me.

Comment 27 Akira TAGOH 2023-03-29 10:53:05 UTC
Created attachment 1954384 [details]
v4

Oops, attached old one. this is.

Comment 28 Than Ngo 2023-03-29 12:49:51 UTC
I downloaded and tested Akira's build, confirmed that it also works for me. Thanks Akira and Peng for the fix!

@Brian and other, could you please test Akira's build and report the result before i do officical build?

Thanks!

Comment 29 Brian Morrison 2023-03-29 13:29:38 UTC
I can only see x86_64 rpms, my system has 2 .i686 rpms and I can't run the upgrade without them.

If someone can provide a scratch build with all arches present then I will try that.

Comment 30 Jens Petersen 2023-03-29 13:35:22 UTC
I tested https://download.copr.fedorainfracloud.org/results/tagoh/qt5-qtbase/fedora-38-x86_64/05725782-qt5-qtbase/ too on X11
in Fedora-KDE-Live-x86_64-38-20230328.n.0.iso and now CJK output renders again in the konsole
(eg `LANG=ja_JP.utf8 date` and `sudo dnf ...` output).

Comment 31 Than Ngo 2023-03-29 14:00:59 UTC
(In reply to Brian Morrison from comment #29)
> I can only see x86_64 rpms, my system has 2 .i686 rpms and I can't run the
> upgrade without them.
> 
> If someone can provide a scratch build with all arches present then I will
> try that.

there is scratch build with all arches https://koji.fedoraproject.org/koji/taskinfo?taskID=99281689

Please test it only on X11. Thanks!

Comment 32 Brian Morrison 2023-03-29 14:09:26 UTC
So it is not going to work on GNOME Wayland?

Comment 33 Than Ngo 2023-03-29 14:12:42 UTC
(In reply to Brian Morrison from comment #32)
> So it is not going to work on GNOME Wayland?

For GNOME Wayland we need to rebuild qt5-qtwayland against new qt5-qtbase. I will do this later. For quick test we just test it on X11.

Comment 34 Brian Morrison 2023-03-29 14:58:52 UTC
OK, I will test it once the qt5-wayland packages are available too.

Comment 35 Brian Morrison 2023-03-29 17:31:00 UTC
OK, I have tried this using the qt5-qtbase*5.15.8-10 packages and qt5-qtwayland*5.15.8-4.1 packages.

Stopping and restarting a Qt application now seems to work OK, I have menus and the controls are the correction sizes and work too.

This looks like it is good enough for updates-testing.

Comment 36 Fedora Update System 2023-03-29 18:41:10 UTC
FEDORA-2023-c7a23026f7 has been submitted as an update to Fedora 38. https://bodhi.fedoraproject.org/updates/FEDORA-2023-c7a23026f7

Comment 37 Brian Morrison 2023-03-29 22:23:13 UTC
I have tried the qt5-qtbase*5.15.8-10 and qt5-qtwayland*5.15.8-6 packages from https://bodhi.fedoraproject.org/updates/FEDORA-2023-c7a23026f7 and they also work as expected.

Comment 38 Fedora Update System 2023-03-30 02:20:23 UTC
FEDORA-2023-c7a23026f7 has been pushed to the Fedora 38 testing repository.

You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2023-c7a23026f7

See also https://fedoraproject.org/wiki/QA:Updates_Testing for more information on how to test updates.

Comment 39 Than Ngo 2023-03-30 08:49:30 UTC
Brain, thanks for testing and feedbacks!

Could you and other please grant the karma in  https://bodhi.fedoraproject.org/updates/FEDORA-2023-c7a23026f7 ?

Thanks

Comment 40 Fedora Update System 2023-03-31 01:34:05 UTC
FEDORA-2023-c7a23026f7 has been pushed to the Fedora 38 stable repository.
If problem still persists, please make note of it in this bug report.


Note You need to log in before you can comment on or make changes to this bug.