首页 > 解决方案 > 如何强制阿拉伯字符分开?

问题描述

我正在尝试使用枕头在图像上键入一组没有空格的阿拉伯字符。我目前遇到的问题是,一些阿拉伯字符在彼此相邻时会出现不同的显示。((例如س,当彼此相邻时,‍<code>ل将是‍<code>سل。)我试图以某种方式强制我的字体设置始终分隔所有字符而不注入任何其他字符,我该怎么办?

这是我的代码片段:

#font is an arabic font, and font_path is pointing to that location.
        font = ImageFont.truetype(
            font=font_path, size=size,
            layout_engine=ImageFont.LAYOUT_RAQM)

        h, w = font.getsize(text, direction='rtl')
        offset = font.getoffset(text)
        H, W = int(1.5 * h), int(1.5 * w)
        imgSize = H, W
        img = Image.new(mode='1', size=imgSize, color=0)
        draw = ImageDraw.Draw(img)
        pos = ((H-h)/2, (W-w)/2)
        draw.text(pos, text, fill=255, font=font,
                  direction='rtl', align='center')

标签: pythonfontspython-imaging-libraryarabic

解决方案



推荐阅读