I am working on a new recipe for the newspaper La Razón, Bolivia, as the old one doesn't work anymore, while the website changed. I have to new recipe working mostly, it just needs some esthetic changes. I will post it when it is finished.
The website of the paper doesn't have a suitable masthead image anymore so I used
Code:
def get_masthead_title(self):
return u'La Razón'
However the masthead image generator uses the title utf-8 encoded which gives strange characters instead of the 'ó'.
The PIL draw text method doesn't expect a utf-8 encoded byte string but it accepts a normal Unicode string. So I changed generate_masthead in calibre/ebooks/__init__.py to eliminate the conversion to utf-8 and that solved the problem. Essentially the text = title.encode('utf-8') should be eliminated and title be used instead of text.
Here is the diff:
Code:
diff -u /Applications/calibre.app/Contents/Resources/Python/site-packages/calibre/ebooks/__init__.py.\~1\~ /Applications/calibre.app/Contents/Resources/Python/site-packages/calibre/ebooks/__init__.py
--- /Applications/calibre.app/Contents/Resources/Python/site-packages/calibre/ebooks/__init__.py.~1~ 2011-12-26 18:40:30.000000000 +0100
+++ /Applications/calibre.app/Contents/Resources/Python/site-packages/calibre/ebooks/__init__.py 2011-12-26 23:03:10.000000000 +0100
@@ -240,11 +240,10 @@
font = ImageFont.truetype(font_path, 48)
except:
font = ImageFont.truetype(default_font, 48)
- text = title.encode('utf-8')
- width, height = draw.textsize(text, font=font)
+ width, height = draw.textsize(title, font=font)
left = max(int((width - width)/2.), 0)
top = max(int((height - height)/2.), 0)
- draw.text((left, top), text, fill=(0,0,0), font=font)
+ draw.text((left, top), title, fill=(0,0,0), font=font)
if output_path is None:
f = StringIO()
img.save(f, 'JPEG')