ImageFont family mojibake

Lie Ryan lie.1296 at
Sat Sep 12 07:55:14 CEST 2009

Donn wrote:
> Python 2.6
> PIL Version: 1.1.6-3ubuntu1              
> libfreetype6 Version: 2.3.9-4ubuntu0.1
> Hello,
> I have a feeling I've asked this in the distant past, but it's recently 
> emerged as a bug in my app so can anyone point me in the right direction?
> In Fonty Python, when I draw the family name of a font some* are mojibaked (is 
> that a word?) in the form: ????s??? etc. The string is drawn to a DC with 
> wxPython, but is fetched from the font via ImageFont, like so:
> f=ImageFont.truetype("FGTshgyo.TTF",1,encoding="utf-8")
> print
> '?????s????'

Are you sure that your terminal (Command Prompt/bash/IDLE/etc) supports 
utf-8 and that it is properly set up to display utf-8?


print repr(

> So, the string is plain (not unicode) and wrong from the get-go.
> *"some" being those fonts that contain family names not in western encodings. 
> The sample font that demonstrates the problem and was sent to me to test is 
> called: BGPENKB.TTF another is FGTshgyo.TTF
> These are substantial files and I can't attach them to a list. if you need them 
> for testing I can send them to another email address, or upload them 
> somewhere.
> I have been oft helped in the past on matters unicode, but this does not mean 
> I have grokked. (Alas my formative years were all spend in the fantasy of 8bit 
> ascii :) )
> I hope there's some simple encoding="voodoo" that might fix this. The problem 
> is, I guess, knowing *what* that voodoo is for arbitrary fonts (which can come 
> from any source).

If all else fails, you can simply compare the byte string representation 
of the font family name. The coincidence that two different fonts that 
have different name in different encoding to have the same byte-string 
name is extremely unlikely.

> Any assistance would not go amiss.
> \d

More information about the Python-list mailing list