New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Right-to-left text layout support #113
Comments
Great, thanks! I'm happy to hear that it's got a decent start. It's interesting that the result for word-position substitutions varies by font. The word-position detection logic in Typr is always the same, so there must be something different in how those fonts encode their substitutions that Typr doesn't handle. I'll look into Mirza specifically to see if I can determine a difference. Since I don't know these characters, and thus can't determine correct vs. incorrect myself, it would be immensely helpful if you could give me some targeted test cases with expected results, maybe just single words, something like: Input text: xxx As for the parentheses, I think that's the Paired Brackets part of the Bidi algorithm. I'm not sure yet if that's something I'll tackle on my own, but I'll definitely look into it. |
I've pushed code with some rough bidirectional layout support. Right now it's purely manual using LRO/RLO/PDF control characters to define directional ranges. Full automatic bidi is much more complicated and I'm still getting my head wrapped around its scope, but being able to lay out the ranges (with line wrapping and selection!) is an important start. |
I'm really sorry I haven't posted a feedback yesterday. I thought about making a full test the weekend, but I think better do things in steps. In the picture below, I've used red to mean wrong form of the letter, and green is right form.
Text I used: This answer contains a picture on how letters are drawn |
Thank you so much for this marked up testcase, that's immensely helpful!!! It really helps me understand things. Typr's logic for detecting word position is definitely faulty; I've overridden it with logic adapted from opentype.js and the result now seems much better: I'll contribute that Typr fix back upstream after further testing. The "numbers are reversed" issue will be handled with the BiDi work I've started. For now that can be worked around with explicit LRO/PDF characters. Keep these kinds of testcases coming! 🤩 |
Thanks! I'm currently working on adding a full bidi algorithm implementation which I think should clear up all the other issues you described so far. The "BiDi 1" text in the example's dropdown has an example of LRO/PDF, but don't worry about that for now, it's just a stopgap and isn't really correct anyway. True bidi will be better. The boolean fill issue with that font is the same as discussed in #57 I think. |
We now have full bidi support! There are a couple bidi snippets in the example page but give it some testing with your own mixed rtl+ltr text. This turned into a classic example of me going down a rabbit hole; I didn't find a suitable JS bidi implementation and didn't want to bring in fribidi.wasm, so I decided to take a swing at a new JS implementation as a nights and weekends project. Behold https://github.com/lojjic/bidi-js! I need to add some docs there but it's fully compliant according to the official bidi tests, quite small (~10kb) and pretty speedy though it could probably be optimized more. I'm feeling really happy with this solution and how little it adds to the bundle size. I think we're very close on full RTL support now. I need to revisit the joining forms logic though, I realized that the logic I adapted from opentype.js only handles Arabic scripts but not others that also do joining. |
I've pushed a more complete implementation of joining-type detection; the logic I'd adapted from Opentype.js proved to be incomplete. The new implementation actually embeds a highly compressed version of the unicode joining type definitions so it should now handle all joinable characters in Arabic and otherwise. It also gives a decent speed bump over the Typr code. @MichaelHazani since you volunteered to test Hebrew, I think this is ready for you now. You can use this test page where I've added a couple Hebrew fonts to the "font" dropdown, and you can type in your own text. Thanks! |
I've released v0.41.0 with the work done here so far. There are undoubtedly other RTL scripts that will need additional specialized handling, but this gives a solid enough baseline that I think we can handle those on a case-by-case basis. And there's always the possibility of allowing an optional Harfbuzz plugin (#91) for some of the more advanced/obscure cases. Thank you again @boulabiar and @MichaelHazani for your invaluable help here!!! 🎉 |
In lieu of a full advanced text shaping solution (e.g. harfbuzz.wasm) I'd like some basic out-of-the-box support for RTL layout. Typr includes some level of support for Arabic glyph substitutions already, though I don't know how complete that is.
I've added some very basic RTL layout/wrapping logic already. Let's use this issue to track bugs with that and other gaps in support.
Temporary test page: https://troika-examples.netlify.app/#text-rtl
The text was updated successfully, but these errors were encountered: