Pillow - detect if font contains glyph for a character

Viewed 50

I'm drawing text into an image using a specific font, with Pillow for Python.

If the font I am using doesn't contain a glyph for a specific character, Pillow draws a ?. I'd like to get notified if the font is missing that specific item. Then I can either skip it or use a different font.

from PIL import Image, ImageDraw, ImageFont

image = Image.new("RGB", (100, 100), "white")
draw = ImageDraw.Draw(image)
font = ImageFont.truetype("unifont_upper-14.0.04.ttf", size=16)
draw.text((1, 1), "", font=font, fill="black")
image.save("cuneiform.png")

The specific font I'm using, doesn't contain "Cuneiform Sign A" so Pillow writes a ? - how can I get Pillow (or something else) to alert me that the character won't be drawn properly?

0 Answers
Related