mpcabd / python-arabic-reshaper

Reconstruct Arabic sentences to be used in applications that don't support Arabic
MIT License
401 stars 80 forks source link

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

Open ahmed4end opened 4 years ago

ahmed4end commented 4 years ago

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")
mpcabd commented 4 years ago

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.

ahmed4end commented 3 years ago

is there any updates ? wojak mis

mpcabd commented 3 years ago

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.