当使用PIL(Python图像库)以希伯来语绘制文本时,niqqud没有正确对齐

2024-10-01 15:39:19 发布

您现在位置:Python中文网/ 问答频道 /正文

我用枕头/木桩画希伯来语字母。我注意到nikudi(nikudi的复数形式)没有正确对齐,有时会与其他字母重叠。在

对此有什么建议吗?我试过几种字体,它们似乎都有自己的问题。在

这是我使用的代码。在

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()

注意,由于文本方向的原因,文本在SO上的正确方向呈现,而不是在终端中呈现。在航站楼里看起来像下面。我用BiDi算法来反转单词。在

enter image description here

下面是一个输出示例。你可以看到nikud(即字母下面和旁边的圆点)不是每种字体都一样的。字体在文本编辑器中正确呈现,但在PIL中则不正确。在

如有任何建议,我们将不胜感激。谢谢!在

enter image description here

作为参考,它应该如下所示。在

enter image description here


Tags: topathtextfrom字母字体ttf建议

热门问题