I don't know the reason the code is there. Maybe there used to be a reason which is no longer valid.
And u'La Raz\xc3\xb3n' is a double encoding, it is an not an ascii representation of u'La Razón'. That would be u'La Raz\xf3n', which is probably what you meant. What you have written is a utf-8 encoding of ó, and that put in an ascii representation in a Unicode string. Putting utf-8 bytes in a Unicode string is most of the times wrong. I I print that string it outputs La Razón, which is exactly the text I got in the masthead image, showing that the utf-8 encoding that the code does should not be done. And the parser didn't parse it incorrectly because I had a # -*- coding: utf-8 -*- line and saved the file in utf-8. To safeguard against source code problems indeed \x3f could be used but then the title.encode('utf-8') would still cause the wrong rendering.
Fredrik Lundh, the author of PIL also says that the text can be a Unicode string if the font you use supports Unicode. Here is an example the you can try to see that it works.
Quote:
# -*- coding: utf-8 -*-
import ImageFont, Image, ImageDraw
s = u'La Razón € ñ'
font = ImageFont.truetype('/System/Library/Fonts/LucidaGrande.ttc', 18, encoding='unic')
print font.getsize(s)
im = Image.new('RGB', (200,200))
draw = ImageDraw.Draw(im)
draw.text((40,40), s, font=font)
im.show()
|