python-arabic-reshaper
python-arabic-reshaper copied to clipboard
Figure out what ligatures to use and in what order in certain fonts
the image will explain what i mean:
highlighted:
the issue continues with some other certain letters connect to each other this way.
the snippet code i used:
from PIL import Image , ImageDraw , ImageFont
from bidi.algorithm import get_display
import arabic_reshaper
import os
txt = "سيمبا"
fnt_path = os.path.join(os.getcwd()+ "/ar.ttf") #Arabic typesetting font.
fnt = ImageFont.truetype(fnt_path , 200)
reshaper = arabic_reshaper.ArabicReshaper(
arabic_reshaper.config_for_true_type_font(
fnt_path,
arabic_reshaper.ENABLE_ALL_LIGATURES
)
)
reshaped_text = reshaper.reshape(txt)
bidi_text = get_display(reshaped_text)
image = Image.new(mode = "RGBA" , size = (300, 200) , color="white")
draw = ImageDraw.Draw(image)
draw.text( (0, 0), text=bidi_text, fill="black", font = fnt)
image.save("example.png")
os.startfile("example.png")
I believe this has to do with the font having multiple ligatures that should be used in proper order otherwise you get this result.
The proper way of rendering "سيمبا" should be like this

I think I have to learn more about ligatures ordering in font files, and adapt the reshaper to respect that.
Thanks for reporting, I'll look into it as the time allows.
is there any updates ?
Sorry Ahmed, no update, I haven't had any time to look into it, and honestly, the issue slipped through my mind. If you have any pointers do let me know, my personal time is so tight now with WFH and the kids.