Having an absolutely wild Saturday evening investigating Unicode combining characters. Lagrange currently utterly fails to render these. A special layout algorithm that adapts to any number of combined extra glyphs is needed.
I haven't thrown in the towel yet, but falling back to using an existing library is always an option...
Looks like FriBidi is doing its thing!
(i.e., applying the Unicode Bidirectional Algorithm)
Still need to optimize the text handling a bit to avoid repeated processing of static strings, e.g., UI labels. Text selection is also a bit wonky over RTL runs...
HarfBuzz & FriBidi mean a big step forward in supporting complex scripts. The final big issue remaining is expanding the collection of available fonts.
It's a bit of a challenge to call FriBidi at the right time. I'll need to refactor the document layout somewhat so the text renderer has visibility to the full paragraph and can process it in one go. At the moment it's more of a line-based operation, which makes it more challenging to apply alignment (and justification).
The BiDi quest continues.
I now have the ability to wrap an entire paragraph in one go while also having FriBidi tell me the directions.
My initial attempt is going badly. Wrapping the entire paragraph in visual order means that the first wrapped line covers the end of the paragraph.
Back to the drawing board… Seems like wrapping needs to be done in logical order and only the drawing in visual order.
Support for bidi text and complex scripts has landed in the #Lagrange dev branch.
I had to make a few more fixes for actual bidi typesetting (direction changes inside the paragraph), but it's starting to look acceptable now.
There was a final wrinkle where HarfBuzz wasn't detecting the script correctly, leading to some Arabic glyphs being wrong. It remains to be seen whether this is a problem with other complex scripts as well.
@jk congrats on working on this hard problem, it's really important and often overlooked. I'm glad it's not in my domain with Amfora ;)
skyjake's personal Mastodon instance