在PIL中使用Webdings绘图

时间:2009-01-07 23:05:59

标签: python fonts python-imaging-library

我有一个使用PIL渲染文本的Python程序,它适用于各种字体。但它只画出了“缺少字形”的长方形带有翅膀或织带。

这是一个试图绘制每个unicode字符的示例:

# Run this with .ttf file path as an argument, and also an encoding if you like.
# It will make 16 PNGs with all the characters drawn.
import sys
import Image, ImageDraw, ImageFont

size = 20
per = 64

chars = 0x10000
perpage = per*per

fontfile = sys.argv[1]
encoding = sys.argv[2] if len(sys.argv) > 2 else ''

font = ImageFont.truetype(sys.argv[1], size, encoding=encoding)

for page in range(0, chars//perpage):

    im = Image.new("RGB", (size*per+30, size*per+30), '#ffffc0')
    draw = ImageDraw.Draw(im)

    for line in range(0, per):
        for col in range(0, per):
            c = page*perpage + line*per + col
            draw.text((col*size, line*size), unichr(c), font=font, fill='black')

    im.save('allchars_%03d.png' % page)

使用Arial.ttf(甚至更好的ArialUni.ttf),我得到了16个有趣的PNG。使用PIL搜索问题时,某些符号字体需要指定其编码。如果我使用Symbol.ttf,我会得到所有缺少的字形,直到我指定“symb”作为编码。

如何让翅膀上班?

2 个答案:

答案 0 :(得分:1)

我以前一定做错了。 “symb”作为编码也适用于wingdings!对不起,噪音......

答案 1 :(得分:1)

并非所有的侧翼都映射到unicode:请参阅http://www.alanwood.net/demos/wingdings.html

此外,您只需报道Basic Multilingual Planewikipedia