From 502575375b85cba2e397acd59fa25a43656a32aa Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 28 Dec 2011 09:10:01 +0530 Subject: [PATCH] Fix rendering of non ascii characters in generated masthead images when downloading news for the Kindle --- src/calibre/ebooks/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/calibre/ebooks/__init__.py b/src/calibre/ebooks/__init__.py index 084b91430f..5af555a83f 100644 --- a/src/calibre/ebooks/__init__.py +++ b/src/calibre/ebooks/__init__.py @@ -9,7 +9,7 @@ from various formats. import traceback, os, re from cStringIO import StringIO -from calibre import CurrentDir +from calibre import CurrentDir, force_unicode class ConversionError(Exception): @@ -237,10 +237,10 @@ def generate_masthead(title, output_path=None, width=600, height=60): img = Image.new('RGB', (width, height), 'white') draw = ImageDraw.Draw(img) try: - font = ImageFont.truetype(font_path, 48) + font = ImageFont.truetype(font_path, 48, encoding='unic') except: - font = ImageFont.truetype(default_font, 48) - text = title.encode('utf-8') if isinstance(title, unicode) else title + font = ImageFont.truetype(default_font, 48, encoding='unic') + text = force_unicode(title) width, height = draw.textsize(text, font=font) left = max(int((width - width)/2.), 0) top = max(int((height - height)/2.), 0)