Hello everyone, i need some help
Trying to add arabic language to an "Text2Image" API I developed
as indicated in the attached image , arabic letters are rendered seperated by allegro , that's now how you expect arabic letters to look ,the renderer draws letters in their standalone form. Correct Arabic is written in a script, in which certain letters are joined, according to rules. Therefore, each letter has up to 4 forms:
Standalone
Attached only to previous letter
Attached only to next letter
Attached to both
A proper Arabic word processor automatically chooses the correct form of each letter, according to the rules. In fact, as you type you'll often see the previous letter change form as you type the next letter.
It would be great is i can use some existing allegro API calls to pick the current glyphto be rendered based on the previous and next letter a sort a a hook maybe. is such API doesnt exist , any idea of how i may be able to add it ? not assuming it doesnt exist , thanks alot
code used to produce the attached image
SDL 2 + SDL ttf seem to handle this pretty fine as indicated in the second attached image
I think (but am not sure) that Freetype on its own won't do this. See for example:
https://stackoverflow.com/questions/49110006/arabic-joined-up-text-in-freetype
so you would need a text shaping engine like HarfBuzz.
Where did you get the SDL screenshot from? - it's always worth finding out how they did it.
You are right , no other graphics library seem to do that work even for other languages , each time a seperate font engine is used.
I have done some manual tweaking and was able to render some specific arabic text in allegro properly. ( works only with CONST char * now -- const only -- ).
to automate the process an algorithm is needed , a simple symbole replacement preprocessing
This is where i got the sdl image from https://discourse.libsdl.org/t/sdl-for-farsi-or-persian-text/25292
I talked to them and they seem to simple perform that preprocessing i just mentioned , nothing fancy
I didnt want to automate the preprocessing, i found a php library that does it ( PHP same to have the exact problem as allegro, so allegro is doing good )
after some deep understanding of this whole thing , and 12 hours of investigation i found that the best choice is to use pygame , pygame uses sdl2 internally , and i then have access so a python library that does the preprocessing
If we add some glyph hooks to allegro i will be able to implement this for allegro
I think I'd follow https://github.com/lxnt/ex-sdl-freetype-harfbuzz
HarfBuzz to translate utf8 string to a list of glyphs and position
FreeType to rasterize the needed glyphs with SDF in a texture atlas
And in a custom shader, choose output alpha using the SDF distances info in the texture
Good discussion about SDF http://www.reddit.com/r/gamedev/comments/2879jd/just_found_out_about_signed_distance_field_text/
Can we just add the same sort of code in that example into Allegro? It seems the main workhorse functions are hb_buffer_get_glyph_infos and hb_buffer_get_glyph_positions, after that it's the usual FT_Load_Glyph.
I'm not sure what the glyph callback would look like, can you explain what it would do?
Anyway, I filed https://github.com/liballeg/allegro5/issues/1132 so we don't forget about this.
I'm not sure if this is what you're talking about, but it would be nice to have a glyph hook for drawing each glyph in a custom color or shading, as well as with the proper spacing for things like the suggested languages.
EDIT
Bump for attn.