I’ve released a small open-source RTL text helper library for Defold, focused on Persian (Farsi) and Arabic UI text rendering.
Defold doesn’t provide native shaping for RTL languages, so this library handles character shaping and RTL ordering in Lua, making it possible to correctly display Persian/Arabic text in GUI nodes.
Features
Correct RTL rendering for Persian & Arabic
Proper character shaping (isolated / initial / medial / final)
Today I was able to test version 1.12.1
But it doesn’t seem to display RTL texts correctly.
In fact, I don’t see any difference
Do I need to take any special steps to enable RTL text?
I also don’t see anything about RTL support in the link you sent.
Due to the added engine size the feature comes with, we decided to not include it “by default”.
This means you will need to use an app manifest to include it.
It’s mentioned in the release notes as "Added support for text shaping" where RTL is one use case.
To enable the feature, you need to:
set the font.runtime_generation = 1 in game.project to use .ttf fonts at runtime.
use an app manifest, selecting the “Font Layout” feature.
We haven’t finished our example project yet, but in the meantime there is a test project here:
Note that I linked to the data-only branch. The main branch still uses the older version of this feature, but is deprecated and isn’t supported in 1.12.*
Also, make sure to use the 1.12.0 Beta version for now. (I noticed that the 1.12.1 alpha is not working correctly with this example for some reason, I’m working on that)
I’m now using 1.12.0 and have managed to switch over to using depth field runtime fonts. Everything’s now working fine for our roman, Chinese, Japanese, Korean etc but, adding in Arabic, I’m finding that a lot of characters aren’t displaying.
Please could you confirm - should I expect Arabic to work ‘out of the box’ with 1.12.0? Or do I need to use the library that thawri has provided here to deal with displaying it properly?
In case it sheds any light on things, this is the same piece of text in three different languages… it’s only the Arabic one that doesn’t seem to display properly. It seems like the glyphs are all being generated OK, prewarming all seems fine, just the actual display seems to mess up (for every label I have using Arabic)…
@HHH
if you don’t want to use all char you can use below chars.
this is reduce my game size by 1.5MB. (matter for web build)
using 3 RTL font size:
۰۱۲۳۴۵۶۷۸۹٠١٢٣٤٥٦٧٨٩ءآأؤإئابةتثجچحخدذرزژسشصضطظعغفقکكگلمنوهيیىﭐﭑﭒﭓﭔﭕﭖﭗﭘﭙﭚﭛﭜﭝﭞﭟﭠﭡﭢﭣﭤﭥﭦﭧﭨﭩﭪﭫﭬﭭﭮﭯﭰﭱﭲﭳﭴﭵﭶﭷﭸﭹﺀﺁﺂﺃﺄﺅﺆﺇﺈﺉﺊﺋﺌﺍﺎﺏﺐﺑﺒﺕﺖﺗﺘﺙﺚﺛﺜﺝﺞﺟﺠﭺﭻﭼﭽﺡﺢﺣﺤﺥﺦﺧﺨﺩﺪﺫﺬﺭﺮﺯﺰﮊﮋﺱﺲﺳﺴﺵﺶﺷﺸﺹﺺﺻﺼﺽﺾﺿﻀﻁﻂﻃﻄﻅﻆﻇﻈﻉﻊﻋﻌﻍﻎﻏﻐﻑﻒﻓﻔﻕﻖﻗﻘﻙﻚﻛﻜﮎﮏﻝﻞﻟﻠﻡﻢﻣﻤﻥﻦﻧﻨﻩﻪﻫﻬﻭﻮﻱﻲﻳﻴﯼﯽﯾﯿﻻﻼﻵﻶﻷﻸ
َ ً ُ ٌ ِ ٍ ْ ّ ٓ ٔ ٕ ٖ ٗ ٘ ٙ ٚ
It’s good to know that if “runtime fonts” is used, then the “All characters” is used as the “prewarm text” instead. We’ll parse that and do full text shaping on that text, in order to generate the correct glyphs for proper shaping.
This is good for showing a first text quickly when booting. After that, you can use the font.prewarm_text() to load new glyphs for showing.
I think the problem was down to my font size being too big (it was at 48). I was seeing warnings about the cache being too small and needing to be resized (even when I tried making it huge, like 16k*16x). Shrinking the font size down to 24 has got rid of those warnings and the text now seems to display OK.
My guess is that the resize of the cache (which obviously is best to avoid so I need to shrink the font down now I’m using real-time fonts) somehow messes up the drawing of the Arabic.
Thanks everyone for your help in finding this. Great work on the RTL support!
If the glyphs gets evicted from the glyph cache, then yes, it will render incorrectly, which is why it’s good to keep track of these error message about cache size.
One more question - I don’t have any knowledge of Arabic or RTL languages generally so please excuse me if this is a stupid question…
I noticed that the text appears different if line breaks are used. I can see that the same words seem to be there but the ordering has changed. Also, when on a single line, the ordering seems different from what I see in Google translate going English→Arabic. Trying to Google translate any of the lines on my screen back to English seems to result in a correct translation. So my question is - are all these versions of the same sentence valid? Or has something gone wrong here?
If anyone here reads Arabic ( thawri ?) and can confirm, that would be really helpful.