Bug 472382

Summary: RTL text aligns differently from 5.1
Product: [Applications] krita Reporter: Alvin Wong <alvin>
Component: Tool/TextAssignee: Krita Bugs <krita-bugs-null>
Status: RESOLVED FIXED    
Severity: normal CC: griffinvalley
Priority: NOR Keywords: regression
Version: git master (please specify the git hash!)   
Target Milestone: ---   
Platform: Microsoft Windows   
OS: Microsoft Windows   
Latest Commit: Version Fixed In:
Sentry Crash Report:
Attachments: Test file demonstrating the issue, saved from 5.1.5
Screenshots
Fixes the bug, but unsure how appropriate

Description Alvin Wong 2023-07-19 07:52:26 UTC
Created attachment 160377 [details]
Test file demonstrating the issue, saved from 5.1.5

SUMMARY

Multiline RTL text does not align correctly in 5.2.


STEPS TO REPRODUCE
1. In rich text editor, add the text:
```
این یک متن فارسی است که در
سمت راست قرار می‌گیرد
```
2. The text should be by default "left aligned" in Qt terms, i.e. visually aligned to the right
3. Save the text

OBSERVED RESULT
The second line is positioned left of the first line.

EXPECTED RESULT
The two lines should be lined up by their right edges.

SOFTWARE/OS VERSIONS
Windows: 10
Comment 1 Alvin Wong 2023-07-19 07:52:53 UTC
Created attachment 160378 [details]
Screenshots
Comment 2 wolthera 2023-08-06 13:28:43 UTC
hum, everything starts working when I set "direction:rtl" on the parent, and both firefox, chromium and inkscape are able to sus this out without that property, so I'm wondering what the exact logic is here... I can't seem to find anything in css writing modes: https://www.w3.org/TR/css-writing-modes-3/#direction
Comment 3 wolthera 2023-08-09 12:29:50 UTC
Ok, I figured out the bug: somehow the bidi-marks are set as the anchor start. Lemme think about how to tackle this...
Comment 4 wolthera 2023-08-09 14:05:50 UTC
Created attachment 160866 [details]
Fixes the bug, but unsure how appropriate

This patch fixes the bug, and consists of two parts:
part 1 is to collapse bidi controls, as per Part 2 of the text-layout algorithm: "discarded during layout due to being a collapsed white space character, a soft hyphen character, or a bidi control character; or", however, if I do this when text-in-shape is active it break text-in-shape mixed-bidi. I don't yet understand why which is why I don't like to make a proper mr yet.
part 2 is that the line-breaking algorithm never finalized for this text because it ends with a control character.
Comment 5 wolthera 2023-08-14 14:35:08 UTC
Git commit e66763c492adfb6c8c163ae90e69fb4d7b5a7277 by Wolthera van Hövell, on behalf of Wolthera van Hövell tot Westerflier.
Committed on 14/08/2023 at 16:34.
Pushed by woltherav into branch 'master'.

Make transformationResolution happen earlier and be a bit
better aligned to the SVG 2 spec.

A bit contradictory, becuase the SVG spec wants it to happen later, but we
should have it this early to eventually apply shaping breaks.

Collapsing is now handled by the resolveTransforms function.

This also handles adressability and 'middle' glyphs a little better,
which means we have less problems with ligatures.
Related: bug 471374

M  +1    -1    libs/flake/text/KoSvgTextShape_p.h
M  +106  -74   libs/flake/text/KoSvgTextShape_p_layout.cpp

https://invent.kde.org/graphics/krita/-/commit/e66763c492adfb6c8c163ae90e69fb4d7b5a7277
Comment 6 wolthera 2023-08-14 14:38:46 UTC
Git commit 054fbd20d57a093ec4baabc5555659eb4b669a29 by Wolthera van Hövell tot Westerflier.
Committed on 14/08/2023 at 16:36.
Pushed by woltherav into branch 'krita/5.2'.

Make transformationResolution happen earlier and be a bit
better aligned to the SVG 2 spec.

A bit contradictory, becuase the SVG spec wants it to happen later, but we
should have it this early to eventually apply shaping breaks.

Collapsing is now handled by the resolveTransforms function.

This also handles adressability and 'middle' glyphs a little better,
which means we have less problems with ligatures.
Related: bug 471374

M  +1    -1    libs/flake/text/KoSvgTextShape_p.h
M  +106  -74   libs/flake/text/KoSvgTextShape_p_layout.cpp

https://invent.kde.org/graphics/krita/-/commit/054fbd20d57a093ec4baabc5555659eb4b669a29