Drawing with Webdings in PIL

I've got a Python program using PIL to render text, and it works great with all kinds of fonts. But it only draws "missing glyph" rectangles with wingdings or webdings.

Here's a sample that tries to draw every unicode character:

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

With Arial.ttf (or even better, ArialUni.ttf), I get 16 interesting PNGs. Searching for issues with PIL, some symbol fonts need to have their encoding specified. If I use Symbol.ttf, I get all missing glyphs until I specify "symb" as the encoding.

How do I get wingdings to work?


Asked by: Dainton929 | Posted: 05-10-2021






Answer 1

I must have done something wrong before. "symb" as the encoding works for wingdings too! Sorry for the noise...

Answered by: Kellan372 | Posted: 06-11-2021



Answer 2

Not all of wingdings is mapped to unicode: see http://www.alanwood.net/demos/wingdings.html

Also you're only covering the Basic Multilingual Plane (wikipedia)

Answered by: Max405 | Posted: 06-11-2021



Similar questions





Still can't find your answer? Check out these communities...



PySlackers | Full Stack Python | NHS Python | Pythonist Cafe | Hacker Earth | Discord Python



top