From d5e9c105ab1759380843bad4a6b16d40bd21cdce Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 8 Jan 2013 13:46:42 +0530 Subject: [PATCH] Use the Liberation fonts as the default fonts for generic css font specs on linux as the other fonts may result in bitmapped fonts being used --- .../ebooks/conversion/plugins/pdf_output.py | 14 ++++--- src/calibre/gui2/__init__.py | 37 +++++++++++-------- 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/src/calibre/ebooks/conversion/plugins/pdf_output.py b/src/calibre/ebooks/conversion/plugins/pdf_output.py index e4eb45fc6a..b9d016de2d 100644 --- a/src/calibre/ebooks/conversion/plugins/pdf_output.py +++ b/src/calibre/ebooks/conversion/plugins/pdf_output.py @@ -10,7 +10,7 @@ Convert OEB ebook format to PDF. import glob, os -from calibre.constants import iswindows +from calibre.constants import iswindows, islinux from calibre.customize.conversion import (OutputFormatPlugin, OptionRecommendation) from calibre.ptempfile import TemporaryDirectory @@ -73,13 +73,13 @@ class PDFOutput(OutputFormatPlugin): ' of stretching it to fill the full first page of the' ' generated pdf.')), OptionRecommendation(name='pdf_serif_family', - recommended_value='Times New Roman', help=_( + recommended_value='Liberation Serif' if islinux else 'Times New Roman', help=_( 'The font family used to render serif fonts')), OptionRecommendation(name='pdf_sans_family', - recommended_value='Helvetica', help=_( + recommended_value='Liberation Sans' if islinux else 'Helvetica', help=_( 'The font family used to render sans-serif fonts')), OptionRecommendation(name='pdf_mono_family', - recommended_value='Courier New', help=_( + recommended_value='Liberation Mono' if islinux else 'Courier New', help=_( 'The font family used to render monospaced fonts')), OptionRecommendation(name='pdf_standard_font', choices=['serif', 'sans', 'mono'], @@ -102,6 +102,10 @@ class PDFOutput(OutputFormatPlugin): ]) def convert(self, oeb_book, output_path, input_plugin, opts, log): + from calibre.gui2 import must_use_qt, load_builtin_fonts + must_use_qt() + load_builtin_fonts() + self.oeb = oeb_book self.input_plugin, self.opts, self.log = input_plugin, opts, log self.output_path = output_path @@ -135,7 +139,6 @@ class PDFOutput(OutputFormatPlugin): If you ever move to Qt WebKit 2.3+ then this will be unnecessary. ''' from calibre.ebooks.oeb.base import urlnormalize - from calibre.gui2 import must_use_qt from calibre.utils.fonts.utils import remove_embed_restriction from PyQt4.Qt import QFontDatabase, QByteArray, QRawFont, QFont @@ -165,7 +168,6 @@ class PDFOutput(OutputFormatPlugin): raw = remove_embed_restriction(raw) except: continue - must_use_qt() fid = QFontDatabase.addApplicationFontFromData(QByteArray(raw)) family_name = None if fid > -1: diff --git a/src/calibre/gui2/__init__.py b/src/calibre/gui2/__init__.py index 9dbf769511..d7a2669b0b 100644 --- a/src/calibre/gui2/__init__.py +++ b/src/calibre/gui2/__init__.py @@ -766,6 +766,26 @@ class Translator(QTranslator): gui_thread = None qt_app = None + +def load_builtin_fonts(): + global _rating_font + # Load the builtin fonts and any fonts added to calibre by the user to + # Qt + for ff in glob.glob(P('fonts/liberation/*.?tf')) + \ + [P('fonts/calibreSymbols.otf')] + \ + glob.glob(os.path.join(config_dir, 'fonts', '*.?tf')): + if ff.rpartition('.')[-1].lower() in {'ttf', 'otf'}: + with open(ff, 'rb') as s: + # Windows requires font files to be executable for them to be + # loaded successfully, so we use the in memory loader + fid = QFontDatabase.addApplicationFontFromData(s.read()) + if fid > -1: + fam = QFontDatabase.applicationFontFamilies(fid) + fam = set(map(unicode, fam)) + if u'calibre Symbols' in fam: + _rating_font = u'calibre Symbols' + + class Application(QApplication): def __init__(self, args, force_calibre_style=False, @@ -798,27 +818,12 @@ class Application(QApplication): return ret def load_builtin_fonts(self, scan_for_fonts=False): - global _rating_font if scan_for_fonts: from calibre.utils.fonts.scanner import font_scanner # Start scanning the users computer for fonts font_scanner - # Load the builtin fonts and any fonts added to calibre by the user to - # Qt - for ff in glob.glob(P('fonts/liberation/*.?tf')) + \ - [P('fonts/calibreSymbols.otf')] + \ - glob.glob(os.path.join(config_dir, 'fonts', '*.?tf')): - if ff.rpartition('.')[-1].lower() in {'ttf', 'otf'}: - with open(ff, 'rb') as s: - # Windows requires font files to be executable for them to be - # loaded successfully, so we use the in memory loader - fid = QFontDatabase.addApplicationFontFromData(s.read()) - if fid > -1: - fam = QFontDatabase.applicationFontFamilies(fid) - fam = set(map(unicode, fam)) - if u'calibre Symbols' in fam: - _rating_font = u'calibre Symbols' + load_builtin_fonts() def load_calibre_style(self): # On OS X QtCurve resets the palette, so we preserve it explicitly