我正在开发一款显示阿拉伯语文字的Android游戏 . 游戏平台/引擎本身并不支持阿拉伯语文本,所以我打算将我需要的几个单词(~60)转换成带有某种脚本的图像 .

经过一番挖掘,我找到了this question and answer,其中包含足够的代码来生成非ASCII文本作为带有PIL /枕头的图像 .

为了使它适应我的情况,我确保下载一个包含阿拉伯语glpyhs /字符的字体文件(它是this font) .

当我生成图像时,它生成从左到右而不是从右到左 . 字母也被打破而不是被连接 .

这是它的样子:

screenshot

它应该像这样呈现:

screenshot 2

这是我在我的代码/字体/等中做错了,还是Pillow不支持渲染阿拉伯语?

代码如下 . 我在GitHub的Pillow存储库上打开了一个关于这个here的问题 .

# https://stackoverflow.com/questions/18942605/how-to-use-unicode-characters-with-pil
#!/usr/bin/python
# -*- coding: utf-8 -*-
from PIL import Image, ImageDraw, ImageFont, ImageFilter

#configuration
font_size=36
width=200
height=100
back_ground_color=(255,255,255)
font_size=36
font_color=(0,0,0)
unicode_text = u"بِسمللَه"

im  =  Image.new ( "RGB", (width,height), back_ground_color )
draw  =  ImageDraw.Draw ( im )
unicode_font = ImageFont.truetype("A_Nefel_Sereke.ttf", font_size)
draw.text ( (10,10), unicode_text, font=unicode_font, fill=font_color )

im.save("text.png")