Bug 472464 - Vertical baseline is different when using inline-size
Summary: Vertical baseline is different when using inline-size
Status: RESOLVED FIXED
Alias: None
Product: krita
Classification: Applications
Component: Tool/Text (show other bugs)
Version: git master (please specify the git hash!)
Platform: Microsoft Windows Microsoft Windows
: NOR normal
Target Milestone: ---
Assignee: Krita Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-07-21 12:22 UTC by Alvin Wong
Modified: 2023-08-07 14:06 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
Test svg (782 bytes, image/svg+xml)
2023-07-21 12:22 UTC, Alvin Wong
Details
Screenshot (17.19 KB, image/png)
2023-07-21 12:22 UTC, Alvin Wong
Details
Test with step 6 disabled (12.95 KB, image/png)
2023-08-07 11:32 UTC, Alvin Wong
Details
blind patch that may fix the issue (2.51 KB, patch)
2023-08-07 11:55 UTC, wolthera
Details
Screenshot with patch attachment 160791 applied (13.36 KB, image/png)
2023-08-07 12:46 UTC, Alvin Wong
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Alvin Wong 2023-07-21 12:22:11 UTC
Created attachment 160423 [details]
Test svg

The attached SVG uses Source Han Sans. The green text is SVG 1, the black text uses inline-size. For the text using `inline-size`, Krita appears to set the baseline to the right of the glyph.

It looks like something font-specific, because I've tried a few other fonts but they don't show the same behaviour.
Comment 1 Alvin Wong 2023-07-21 12:22:37 UTC
Created attachment 160424 [details]
Screenshot
Comment 2 wolthera 2023-08-06 13:41:05 UTC
Hum, when I use "Source Han Sans HC" or "Noto Sans CJK HK" or "Noto Sans CJK JP" the difference is not as bad as the screenshot, which I suspect means there's been an improvement in  the situation after all our bugfixes. What might be going on now is that the bounding box is calculated differently, lemme check.
Comment 3 wolthera 2023-08-06 13:49:41 UTC
Inkscape seems to be having a similar problem, which might be caused by inkscape aligning inline-size incorrectly when using transforms to begin with, so that's a dead end... bounding boxes seem to be exactly the same. Gonna check the ascent and descent now...
Comment 4 wolthera 2023-08-06 15:57:09 UTC
Git commit e5764c7ef5cb0429e6901d07f752f995226f99cf by Wolthera van Hövell tot Westerflier.
Committed on 06/08/2023 at 17:56.
Pushed by woltherav into branch 'master'.

Fix incorrect baseline value by reinitializing the variable to 0.

There's a bit of a problem still that it seems the baselineOffset
was missing from the pre-formatted text while only applied to the
inline-wrapped text, but that will be a bug for another day.

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

https://invent.kde.org/graphics/krita/-/commit/e5764c7ef5cb0429e6901d07f752f995226f99cf
Comment 5 wolthera 2023-08-06 16:49:17 UTC
Git commit 1a500747693dc535bbe1d946671e3c25d628f94f by Wolthera van Hövell tot Westerflier.
Committed on 06/08/2023 at 18:45.
Pushed by woltherav into branch 'master'.

Fix text-top and text-bottom alignment baselines.

The calculation of the line was incorrect, we're now using the
ascent and descent appropriately. This now also takes into account
baseline-offsets set earlier in subnodes of the text-top or bottom
aligned node.

M  +21   -17   libs/flake/text/KoSvgTextShape.cpp

https://invent.kde.org/graphics/krita/-/commit/1a500747693dc535bbe1d946671e3c25d628f94f
Comment 6 wolthera 2023-08-06 17:53:53 UTC
ok, when using vertical-align/alignment-baseline as the css-spec expects me to (on a subchunk with different font(either by size or family)) everything works as expected. When using vertical-align:alphabetic on the root, it differs between inline-size and preformatted. Now, we shouldn't be able to set the alignment-baseline on the root, but at the same time it's weird that there would be a difference at all...
Comment 7 wolthera 2023-08-06 18:34:58 UTC
ok, the lines where we're losing our 'incorrect' vertical-align is at the resolution of the absolute X and Y post (step 6), particularly when trying to compensate for the relative dx and dy (step 4)... which would make this the cause of bug #426607 ... Guess I'll leave it at that for tonight.
Comment 8 wolthera 2023-08-06 18:48:46 UTC
Git commit efb32c8a841663113acf7c0b5e14b7862cec195a by Wolthera van Hövell, on behalf of Wolthera van Hövell tot Westerflier.
Committed on 06/08/2023 at 20:48.
Pushed by woltherav into branch 'krita/5.2'.

Fix incorrect baseline value by reinitializing the variable to 0.

There's a bit of a problem still that it seems the baselineOffset
was missing from the pre-formatted text while only applied to the
inline-wrapped text, but that will be a bug for another day.


(cherry picked from commit e5764c7ef5cb0429e6901d07f752f995226f99cf)

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

https://invent.kde.org/graphics/krita/-/commit/efb32c8a841663113acf7c0b5e14b7862cec195a
Comment 9 wolthera 2023-08-06 18:49:36 UTC
Git commit f0c0e7c45479a87f8996f0313acc427d74ef2ce9 by Wolthera van Hövell, on behalf of Wolthera van Hövell tot Westerflier.
Committed on 06/08/2023 at 20:49.
Pushed by woltherav into branch 'krita/5.2'.

Fix text-top and text-bottom alignment baselines.

The calculation of the line was incorrect, we're now using the
ascent and descent appropriately. This now also takes into account
baseline-offsets set earlier in subnodes of the text-top or bottom
aligned node.


(cherry picked from commit 1a500747693dc535bbe1d946671e3c25d628f94f)

M  +21   -17   libs/flake/text/KoSvgTextShape.cpp

https://invent.kde.org/graphics/krita/-/commit/f0c0e7c45479a87f8996f0313acc427d74ef2ce9
Comment 10 Alvin Wong 2023-08-07 08:16:42 UTC
The linked commits didn't fix the issue, did they? Here the text is still being rendered exactly the same as the screenshot.
Comment 11 wolthera 2023-08-07 11:17:18 UTC
(In reply to Alvin Wong from comment #10)
> The linked commits didn't fix the issue, did they? Here the text is still
> being rendered exactly the same as the screenshot.

Uh, they fixed the offset I saw. If you could test locally whether commenting out step 6 fixes the issue, then we know the problem is baseline-adjustment related. I wonder if we should disable adjustment baseline for vertical, given that it's currently unsure what counts as the origin: https://github.com/MicrosoftDocs/typography-issues/issues/913
Comment 12 Alvin Wong 2023-08-07 11:32:21 UTC
Created attachment 160789 [details]
Test with step 6 disabled

Disabling step 6 with base commit 5dce46d2f6 gives me this.
Comment 13 wolthera 2023-08-07 11:45:18 UTC
Ok, then the problem is caused by baseline-alignment issues... I think the fundamental issue here is that my Krita build seems to insist on system-harfbuzz instead of the locally build harfbuzz which it can obviously find, so what might be going on is that the 'with fallback' code for harfbuzz 4.0 offsets the central as if it were to the right of the font.
Comment 14 wolthera 2023-08-07 11:55:58 UTC
Created attachment 160791 [details]
blind patch that may fix the issue

Alvin, can you apply this diff and see if it helps? It's a bit of a blind implementation, but if I'm correct it should work?
Comment 15 Alvin Wong 2023-08-07 12:46:19 UTC
Created attachment 160795 [details]
Screenshot with patch attachment 160791 [details] applied

(In reply to wolthera from comment #14)
> Created attachment 160791 [details]
> blind patch that may fix the issue
> 
> Alvin, can you apply this diff and see if it helps? It's a bit of a blind
> implementation, but if I'm correct it should work?

Thanks, looks like it does the job.
Comment 16 wolthera 2023-08-07 13:54:45 UTC
Git commit 0e4119b18f32385def1c6db0608ea2e28225313d by Wolthera van Hövell tot Westerflier.
Committed on 07/08/2023 at 15:54.
Pushed by woltherav into branch 'master'.

Subtract the origin from baseline value to get appropriate baseline offset.

This alsdo simplifies the code a little and fixes the calculation of the central
baseline for vertical, only hb above 4.0 has the central baseline tag.

M  +41   -32   libs/flake/text/KoSvgTextShape.cpp

https://invent.kde.org/graphics/krita/-/commit/0e4119b18f32385def1c6db0608ea2e28225313d
Comment 17 wolthera 2023-08-07 14:06:55 UTC
Git commit d927917f2b592a46cdd8474b0f34b42d92e4b6a4 by Wolthera van Hövell, on behalf of Wolthera van Hövell tot Westerflier.
Committed on 07/08/2023 at 16:06.
Pushed by woltherav into branch 'krita/5.2'.

Subtract the origin from baseline value to get appropriate baseline offset.

This alsdo simplifies the code a little and fixes the calculation of the central
baseline for vertical, only hb above 4.0 has the central baseline tag.


(cherry picked from commit 0e4119b18f32385def1c6db0608ea2e28225313d)

M  +41   -32   libs/flake/text/KoSvgTextShape.cpp

https://invent.kde.org/graphics/krita/-/commit/d927917f2b592a46cdd8474b0f34b42d92e4b6a4