Bug 465886

Summary: Text tool font options are broken in Krita Next after the merging of the new text part
Product: [Applications] krita Reporter: Tyson Tan <tysontanx>
Component: Tool/TextAssignee: Krita Bugs <krita-bugs-null>
Status: RESOLVED FIXED    
Severity: normal CC: alvin, griffinvalley
Priority: NOR Keywords: regression
Version: nightly build (please specify the git hash!)   
Target Milestone: ---   
Platform: Other   
OS: All   
Latest Commit: Version Fixed In:
Sentry Crash Report:
Attachments: Noto Sans CJK SC, Black, 24, 66%
Krita 5.2.0, settings: Noto Sans CJK SC, Black, 24, 66%
Krita 5.1.5, settings: Noto Sans CJK SC, Black, 24, 66%
Krita 5.1.5 KRA, settings: Noto Sans CJK SC, Black, 24, 66%
Krita 5.2.0 KRA, settings: Noto Sans CJK SC, Black, 24, 66%

Description Tyson Tan 2023-02-17 01:47:16 UTC
The text tool's font options in Krita Next 5.2.0 nighties has been broken since the merging of the new text part in Feb 15.

As far as I can tell, Font size and Italic are of no use. The SVG codes generated by 5.1.5 and 5.2.0 for the same font settings look different. font-size-adjust is smaller, font-stretch is missing.

I will attach sample files below.
Comment 1 Tyson Tan 2023-02-17 01:55:55 UTC
Created attachment 156338 [details]
Noto Sans CJK SC, Black, 24, 66%
Comment 2 Tyson Tan 2023-02-17 01:56:20 UTC
Created attachment 156339 [details]
Krita 5.2.0, settings: Noto Sans CJK SC, Black, 24, 66%
Comment 3 Tyson Tan 2023-02-17 01:56:54 UTC
Created attachment 156340 [details]
Krita 5.1.5, settings: Noto Sans CJK SC, Black, 24, 66%
Comment 4 Tyson Tan 2023-02-17 01:57:56 UTC
Created attachment 156341 [details]
Krita 5.1.5 KRA, settings: Noto Sans CJK SC, Black, 24, 66%

Krita 5.1.5, settings: Noto Sans CJK SC, Black, 24, 66%

Note that in 5.1.5, some font settings are dropped from SVG code after reopening the editor. But the appearance on Krita's canvas remains the same.

Before:
<text style="fill:#000000; letter-spacing:0; word-spacing:0; kerning:auto; font-family:Noto Sans CJK SC; font-size:24; font-size-adjust:0.361979; font-weight:900; font-style:normal; stroke-width:0; font-stretch:normal"><tspan x="0">Krita is a professional FREE and </tspan><tspan x="0" dy="23.76pt">open source painting program. </tspan><tspan x="0" dy="47.52pt">It is made by artists that want to </tspan><tspan x="0" dy="23.76pt">see affordable art tools for everyone.</tspan></text>

After:
<text fill="#000000" stroke-opacity="0" stroke="#000000" stroke-width="0" stroke-linecap="square" stroke-linejoin="bevel" font-size="24" font-size-adjust="0.361979" font-stretch="normal" font-weight="900" letter-spacing="0" word-spacing="0"><tspan x="0">Krita is a professional FREE and </tspan><tspan x="0" dy="23.76">open source painting program. </tspan><tspan x="0" dy="47.52">It is made by artists that want to </tspan><tspan x="0" dy="23.76">see affordable art tools for everyone.</tspan></text>
Comment 5 Tyson Tan 2023-02-17 02:04:03 UTC
Created attachment 156342 [details]
Krita 5.2.0 KRA, settings: Noto Sans CJK SC, Black, 24, 66%

Krita 5.2.0 seems to generate different SVG codes than 5.1.5, after the editor reopens.

For the same settings: Noto Sans CJK SC, Black, 24, 66%

Krita 5.1.5 generates this before closing the editor:
<text style="fill:#000000; letter-spacing:0; word-spacing:0; kerning:auto; font-family:Noto Sans CJK SC; font-size:24; font-size-adjust:0.361979; font-weight:900; font-style:normal; stroke-width:0; font-stretch:normal"><tspan x="0">Krita is a professional FREE and </tspan><tspan x="0" dy="23.76pt">open source painting program. </tspan><tspan x="0" dy="47.52pt">It is made by artists that want to </tspan><tspan x="0" dy="23.76pt">see affordable art tools for everyone.</tspan></text>

Krita 5.2.0 generates this before closing the editor:
<text style="fill:#000000; letter-spacing:0; word-spacing:0; kerning:auto; font-family:Noto Sans CJK SC; font-size:24; font-size-adjust:0.361979; font-weight:900; font-style:normal; stroke-width:0; font-stretch:normal"><tspan x="0">Krita is a professional FREE and </tspan><tspan x="0" dy="23.76pt">open source painting program. </tspan><tspan x="0" dy="47.52pt">It is made by artists that want to </tspan><tspan x="0" dy="23.76pt">see affordable art tools for everyone.</tspan></text>

After reopening the editor:

Krita 5.1.5 has this:
<text style="fill:#000000; letter-spacing:0; word-spacing:0; font-size:24; font-size-adjust:0.436678; font-weight:900; stroke-width:0; font-stretch:100"><tspan x="0">Krita is a professional FREE and </tspan><tspan x="0" dy="23.76pt">open source painting program. </tspan><tspan x="0" dy="47.52pt">It is made by artists that want to </tspan><tspan x="0" dy="23.76pt">see affordable art tools for everyone.</tspan></text>

Krita 5.2.0 has this:
<text text-rendering="auto" fill="#000000" stroke-opacity="0" stroke="#000000" stroke-width="0" stroke-linecap="square" stroke-linejoin="bevel" letter-spacing="0" word-spacing="0" style="font-size: 24;font-size-adjust: 0.361979;font-weight: 900;"><tspan x="0">Krita is a professional FREE and </tspan><tspan x="0" dy="23.76">open source painting program. </tspan><tspan x="0" dy="47.52">It is made by artists that want to </tspan><tspan x="0" dy="23.76">see affordable art tools for everyone.</tspan></text>
Comment 6 Tyson Tan 2023-02-17 02:07:06 UTC
I tried to copy 5.1.5's SVG code to 5.2.0, but it didn't work. I could not get the Font size and Italic to work properly.
Comment 7 Alvin Wong 2023-07-22 08:06:20 UTC
Font size setting is the same as bug 470782 and already fixed.

I can confirm that italics does not work for fonts that _does not have an italic variant_, i.e. the new text engine is lacking support for synthesized italic. The same probably applies to bold. In CSS this would be controlled by the `font-synthesis` family of properties. [1]

[1]: https://drafts.csswg.org/css-fonts/#font-synthesis-intro
Comment 8 Bug Janitor Service 2023-07-22 09:44:43 UTC
A possibly relevant merge request was started @ https://invent.kde.org/graphics/krita/-/merge_requests/1862
Comment 9 Alvin Wong 2023-07-31 10:48:58 UTC
Git commit e95f6d439a39a6c739e66b36d70687604915fd7a by Alvin Wong.
Committed on 31/07/2023 at 12:33.
Pushed by alvinwong into branch 'master'.

text: Add synthesizing bold glyphs

If the user requested bold but the font does not have native bold
variant, 5.1 and earlier will synthesize bold by making the glyph
thicker.

Implement the same thing for the new text engine. This emboldens the
glyph outline by a bit using `FT_Outline_Embolden`, and adjust the glyph
advance to accommodate for the wider glyph. This implementation is
heavily inspired by Firefox.

For bitmap glyphs, use `FT_Bitmap_Embolden` like `FT_GlyphSlot_Embolden`
does, but we use a lighter strength, and for small fonts size we only
embolden the glyph horizontally. This is similar to what Windows does.
If we embolden both horizontally and vertically, especially for CJK the
glyphs often lose the details and become completely unrecognizable black
blobs.

This commit does not provide an option for disabling it, but we should
implement the `font-synthesis-weight` CSS property to do so in the
future.

M  +59   -1    libs/flake/text/KoSvgTextShape.cpp

https://invent.kde.org/graphics/krita/-/commit/e95f6d439a39a6c739e66b36d70687604915fd7a
Comment 10 Alvin Wong 2023-07-31 10:49:06 UTC
Git commit 51518e4e83111bf174c0151628461a8af2eb9565 by Alvin Wong.
Committed on 31/07/2023 at 12:32.
Pushed by alvinwong into branch 'master'.

text: Add synthesizing italic glyphs

If the user requested italics but the font does not have native italics
variant, 5.1 and earlier will synthesize oblique by shearing the glyphs.
It is unclear what amount of shear Qt used.

Implement the same thing for the new text engine. A shear angle of 14
degrees is chosen to coincide with CSS's defaults. [1] This commit does
not provide an option for disabling this behaviour. If such a switch is
to be implemented in the future, it should probably use the CSS
`font-synthesis-style` property to do so. [2]

[1]: https://drafts.csswg.org/css-fonts/#font-style-prop
[2]: https://drafts.csswg.org/css-fonts/#font-synthesis-style

M  +62   -13   libs/flake/text/KoSvgTextShape.cpp

https://invent.kde.org/graphics/krita/-/commit/51518e4e83111bf174c0151628461a8af2eb9565
Comment 11 Alvin Wong 2023-07-31 11:03:27 UTC
Git commit c489badcc2266502ba0162793114a08f5cd99ba4 by Alvin Wong.
Committed on 31/07/2023 at 13:03.
Pushed by alvinwong into branch 'krita/5.2'.

text: Add synthesizing italic glyphs

If the user requested italics but the font does not have native italics
variant, 5.1 and earlier will synthesize oblique by shearing the glyphs.
It is unclear what amount of shear Qt used.

Implement the same thing for the new text engine. A shear angle of 14
degrees is chosen to coincide with CSS's defaults. [1] This commit does
not provide an option for disabling this behaviour. If such a switch is
to be implemented in the future, it should probably use the CSS
`font-synthesis-style` property to do so. [2]

[1]: https://drafts.csswg.org/css-fonts/#font-style-prop
[2]: https://drafts.csswg.org/css-fonts/#font-synthesis-style

(cherry picked from commit 51518e4e83111bf174c0151628461a8af2eb9565)

M  +62   -13   libs/flake/text/KoSvgTextShape.cpp

https://invent.kde.org/graphics/krita/-/commit/c489badcc2266502ba0162793114a08f5cd99ba4
Comment 12 Alvin Wong 2023-07-31 11:03:36 UTC
Git commit 22dc42a537afdf11a5ca48aea617c6b71569ffed by Alvin Wong.
Committed on 31/07/2023 at 13:03.
Pushed by alvinwong into branch 'krita/5.2'.

text: Add synthesizing bold glyphs

If the user requested bold but the font does not have native bold
variant, 5.1 and earlier will synthesize bold by making the glyph
thicker.

Implement the same thing for the new text engine. This emboldens the
glyph outline by a bit using `FT_Outline_Embolden`, and adjust the glyph
advance to accommodate for the wider glyph. This implementation is
heavily inspired by Firefox.

For bitmap glyphs, use `FT_Bitmap_Embolden` like `FT_GlyphSlot_Embolden`
does, but we use a lighter strength, and for small fonts size we only
embolden the glyph horizontally. This is similar to what Windows does.
If we embolden both horizontally and vertically, especially for CJK the
glyphs often lose the details and become completely unrecognizable black
blobs.

This commit does not provide an option for disabling it, but we should
implement the `font-synthesis-weight` CSS property to do so in the
future.
(cherry picked from commit e95f6d439a39a6c739e66b36d70687604915fd7a)

M  +59   -1    libs/flake/text/KoSvgTextShape.cpp

https://invent.kde.org/graphics/krita/-/commit/22dc42a537afdf11a5ca48aea617c6b71569ffed
Comment 13 Tyson Tan 2023-08-01 04:43:19 UTC
Thank you, Alvin. I need this function in my job. Now I can finally use the Nighties again! :D