The niqqud are not aligned properly while drawing text in Hebrew using PIL (Python Imaging Library)

安稳与你 提交于 2020-01-23 02:26:25

问题


I'm using Pillow / PIL to draw hebrew letters with nikud. I noticed that the nikudim (plural for nikud) are not properly aligned and sometimes overlap other letters.

Any suggested fix for this? I've tried a few fonts, and they all seem to have their own issues.

Here's the code that I'm using.

from bidi.algorithm import get_display
from PIL import Image, ImageDraw, ImageFont

fonts = [
    ('Tammey FranckCLM', '/PATH/TO/FONT/TaameyFrankCLM-Medium.ttf'),
    ('Times New Roman', '/PATH/TO/FONT/Times New Roman.ttf'),
    ('Arial', '/PATH/TO/FONT/Arial.ttf')
]

im = Image.new(mode='RGBA', size = (1000, 1000), color = (0, 0, 0, 255))
draw = ImageDraw.Draw(im)

height = 100
for f in fonts:
    fnt = ImageFont.truetype(f[1], 40)
    text = 'עָלֵינוּ'
    text_bidi = get_display(text, base_dir='R')
    draw.text((100, height), f[0], font=fnt, fill=(255, 255, 255))
    draw.text((500, height), text_bidi, font=fnt, fill=(255, 255, 255))
    height += 70
im.show()
im.close()

Note, that due to text direction, the text renders in the proper direction on SO, but not in the terminal. In the terminal it looks like below. I'm using the BiDi algorithm to reverse the word.

Here's an example of the output. You can see the nikud (i.e. the dots underneath and next to the letters) are not the same in every font. The fonts render properly in text editors, but not in PIL.

Any suggestions would be appreciated. Thanks!

For reference, it should look like below.

来源:https://stackoverflow.com/questions/41271620/the-niqqud-are-not-aligned-properly-while-drawing-text-in-hebrew-using-pil-pyth

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!