python-arabic-reshaper icon indicating copy to clipboard operation
python-arabic-reshaper copied to clipboard

Figure out what ligatures to use and in what order in certain fonts

Open ahmed4end opened this issue 5 years ago • 3 comments

the image will explain what i mean: example highlighted: image 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")

ahmed4end avatar Aug 21 '20 01:08 ahmed4end

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 image

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.

mpcabd avatar Sep 03 '20 09:09 mpcabd

is there any updates ? wojak mis

ahmed4end avatar Jul 12 '21 18:07 ahmed4end

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.

mpcabd avatar Jul 13 '21 20:07 mpcabd