From e83dc0e8003bb39ab45630330a52d89969db0927 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 26 Oct 2010 16:39:17 -0600 Subject: [PATCH] Fix #7241 ('Generate Cover' cannot support Asian characters) --- resources/default_tweaks.py | 8 ++++++++ src/calibre/utils/magick/draw.py | 10 ++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/resources/default_tweaks.py b/resources/default_tweaks.py index 270b7e0b06..0f570bab40 100644 --- a/resources/default_tweaks.py +++ b/resources/default_tweaks.py @@ -203,3 +203,11 @@ content_server_wont_display = [''] # level sorts, and if you are seeing a slowdown, reduce the value of this tweak. maximum_resort_levels = 5 +# Absolute path to a TTF font file to use as the font for the title and author +# when generating a default cover. Useful if the default font (Liberation +# Serif) does not contain glyphs for the language of the books in your library. +generate_cover_title_font = None + +# Absolute path to a TTF font file to use as the font for the footer in the +# default cover +generate_cover_foot_font = None diff --git a/src/calibre/utils/magick/draw.py b/src/calibre/utils/magick/draw.py index 5c978a27e0..d3cbd58c7d 100644 --- a/src/calibre/utils/magick/draw.py +++ b/src/calibre/utils/magick/draw.py @@ -9,6 +9,7 @@ import os from calibre.utils.magick import Image, DrawingWand, create_canvas from calibre.constants import __appname__, __version__ +from calibre.utils.config import tweaks from calibre import fit_image def normalize_format_name(fmt): @@ -113,7 +114,9 @@ def add_borders_to_image(img_data, left=0, top=0, right=0, bottom=0, def create_text_wand(font_size, font_path=None): if font_path is None: - font_path = P('fonts/liberation/LiberationSerif-Bold.ttf') + font_path = tweaks['generate_cover_title_font'] + if font_path is None: + font_path = P('fonts/liberation/LiberationSerif-Bold.ttf') ans = DrawingWand() ans.font = font_path ans.font_size = font_size @@ -203,8 +206,11 @@ def create_cover_page(top_lines, logo_path, width=590, height=750, bottom += line.bottom_margin bottom -= top_lines[-1].bottom_margin + foot_font = tweaks['generate_cover_foot_font'] + if not foot_font: + foot_font = P('fonts/liberation/LiberationMono-Regular.ttf') vanity = create_text_arc(__appname__ + ' ' + __version__, 24, - font=P('fonts/liberation/LiberationMono-Regular.ttf')) + font=foot_font) lwidth, lheight = vanity.size left = int(max(0, (width - lwidth)/2.)) top = height - lheight - 10