kas-gui / kas-text

Rich text processing
Apache License 2.0
59 stars 2 forks source link

Implement RTL and BIDI text support #9

Closed dhardy closed 4 years ago

dhardy commented 4 years ago

This adds support for:

As such, it can now display simple bidirectional text.

Also, text navigation will need many fixes. That will be another PR.

dhardy commented 4 years ago

The promised screenshot:

bidi-layout

Sample text is taken from r12a. There are some notable issues here, which are left for now:

Frankly, I've already put more work into supporting BIDI than I have justification for, so likely won't work further on this (besides navigation). The rationale was to test that the crate's architecture was compatible with BIDI processing, to which the answer seems to be just about. From reading Unicode TR#9, it almost seems like shaping must happen twice: first to measure the widths of unsplittable text segments, and second to draw glyphs after rearranging characters, however initial shaping on RTL text must already use the correct glyph order and any differences between initial and final shaping could generate incorrect line length, so practically speaking this would appear unnecessary.

dhardy commented 4 years ago

To conclude the above paragraph: this implementation uses a single shaping pass. There may be limitations, but is seems good enough (at least for now).