|Summary:||Text-in-shape layout is different from Inkscape|
|Product:||[Applications] krita||Reporter:||Alvin Wong <alvin>|
|Component:||Tool/Text||Assignee:||Krita Bugs <krita-bugs-null>|
|Version:||git master (please specify the git hash!)|
|Latest Commit:||https://invent.kde.org/graphics/krita/-/commit/6be3971efc90e3f8245a96753b7daec0e417e9ae||Version Fixed In:|
Render from Inkscape
Render from Krita
Description Alvin Wong 2023-08-19 09:07:30 UTC
Created attachment 161055 [details] Test file Here is a test file created in Inkscape 1.2.2 (with `white-space` manually changed to `pre-wrap`) containing two text nodes, placed so that the text should be approximately at the same y position. The left one is flowed in shape, while the right one uses inline-size. Both uses `line-height:1.25`. When opened in Krita, the text in shape is laid out differently with a y-offset on the first line and slightly larger line leading.
Comment 1 Alvin Wong 2023-08-19 09:07:50 UTC
Created attachment 161056 [details] Render from Inkscape
Comment 3 wolthera 2023-08-19 11:27:24 UTC
Probably caused by this line in specific: https://invent.kde.org/graphics/krita/-/blob/master/libs/flake/text/KoSvgTextShapeLayoutFunc_inShape.cpp#L104 I haven't had the energy to figure out the ideal value for that.
Comment 4 Alvin Wong 2023-08-19 14:20:34 UTC
Changing that to 1e-6 only makes a very minor difference (the whole text block is shifted up by 1px).
Comment 5 Alvin Wong 2023-08-19 16:59:16 UTC
It looks like maybe Inkscape is laying out the first line using the calculated line-height, but Krita is using the actual bounding boxes (or maybe ascent/descent). No clue what's going on with the leading. It looks like the actual line height stops scaling correctly once it's below a certain value.
Comment 6 Alvin Wong 2023-08-20 07:11:09 UTC
Actually, it seems Inkscape places the first line way too high it looks like they are not using the proper ascent/descent. This is more obvious with line-height 0. I have recreated this in HTML using floating elements for reference. I also have a rough fix for Krita, so I'll open a draft MR with it.
Comment 8 Bug Janitor Service 2023-08-20 07:50:20 UTC
A possibly relevant merge request was started @ https://invent.kde.org/graphics/krita/-/merge_requests/1908
Comment 9 Alvin Wong 2023-08-30 18:43:04 UTC
Git commit 091bc5682063f76bb3e9d8f67d9467337a47aa3f by Alvin Wong. Committed on 30/08/2023 at 20:24. Pushed by alvinwong into branch 'master'. text: Use line-height when flowing text in shape Don't use the actual char bounding box, instead use (ascent - halfLeading, descent + halfLeading) which takes line-height into account. M +3 -3 libs/flake/text/KoSvgTextShapeLayoutFunc_inShape.cpp M +1 -0 libs/flake/text/KoSvgTextShape_p.h M +5 -0 libs/flake/text/KoSvgTextShape_p_glyphs.cpp https://invent.kde.org/graphics/krita/-/commit/091bc5682063f76bb3e9d8f67d9467337a47aa3f
Comment 10 Alvin Wong 2023-08-30 18:43:55 UTC
Git commit 6be3971efc90e3f8245a96753b7daec0e417e9ae by Alvin Wong. Committed on 30/08/2023 at 20:43. Pushed by alvinwong into branch 'krita/5.2'. text: Use line-height when flowing text in shape Don't use the actual char bounding box, instead use (ascent - halfLeading, descent + halfLeading) which takes line-height into account. (cherry picked from commit 091bc5682063f76bb3e9d8f67d9467337a47aa3f) M +3 -3 libs/flake/text/KoSvgTextShapeLayoutFunc_inShape.cpp M +1 -0 libs/flake/text/KoSvgTextShape_p.h M +5 -0 libs/flake/text/KoSvgTextShape_p_glyphs.cpp https://invent.kde.org/graphics/krita/-/commit/6be3971efc90e3f8245a96753b7daec0e417e9ae