Closed ahmed4end closed 4 years ago
Can you show me how you're using the config mentioned? I suspect it's not being used or utilised correctly.
This image show the text you provided while enabling use_unshaped_instead_of_isolated
here is a snippet of how i used the "use_unshaped_instead_of_isolated" option and i wish i'm wrong at using it. and this is the result of me code :
I can't seem to reproduce it, maybe the font file you're using is not properly configured, have you tried using a TrueType® (.ttf) file?
import arabic_reshaper
import os
from PIL import Image, ImageDraw, ImageFont
from bidi.algorithm import get_display
directory = os.path.abspath(os.path.dirname(__file__))
def f(p): return os.path.join(directory, p)
text_to_be_reshaped = 'امتحان الرياضيات النهائي'
reshaper = arabic_reshaper.ArabicReshaper({
'use_unshaped_instead_of_isolated': True
})
reshaped_text = reshaper.reshape(text_to_be_reshaped)
bidi_text = get_display(reshaped_text)
font = ImageFont.truetype(f('arabic-typesetting.ttf'), 120)
image = Image.new('RGBA', (800, 600), (255, 255, 255, 255))
image_draw = ImageDraw.Draw(image)
image_draw.text((10, 10), bidi_text, fill=(0, 0, 0, 255), font=font)
image.save(f('text-manual-config.png'))
config_from_font = arabic_reshaper.config_for_true_type_font(
f('arabic-typesetting.ttf'))
reshaper = arabic_reshaper.ArabicReshaper(config_from_font)
reshaped_text = reshaper.reshape(text_to_be_reshaped)
bidi_text = get_display(reshaped_text)
image_draw.rectangle([0, 0, 800, 600], fill=(255, 255, 255, 255))
image_draw.text((10, 10), bidi_text, fill=(0, 0, 0, 255), font=font)
image.save(f('text-auto-config.png'))
Manual Config:
Auto Config:
The code is using my latest release 2.1.0
which has a new method to read a .ttf
file and configure the reshaper accordingly. See this new section in the README for more info.
@mpcabd i did upgrade the library and tried your code and amazingly solved my problems and worked smoothly, i'm very grateful, thanks.
the font "Arabic typesetting" does work with the arabic reshaper library as expected it shows instead [a question mark] replacing many letters that ruins the afterall result and here is an example of drawing random Arabic words like "أمتحان رياضيات". and if i used the option "use_unshaped_instead_of_isolated " it corrects some letters and damage another letters i wonder if there is a way to get around this issue cuz this font if really famous one in the arabic fonts ! https://ibb.co/m6Y1VRh