mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
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
This commit is contained in:
parent
56c161ec63
commit
d5e9c105ab
@ -10,7 +10,7 @@ Convert OEB ebook format to PDF.
|
|||||||
|
|
||||||
import glob, os
|
import glob, os
|
||||||
|
|
||||||
from calibre.constants import iswindows
|
from calibre.constants import iswindows, islinux
|
||||||
from calibre.customize.conversion import (OutputFormatPlugin,
|
from calibre.customize.conversion import (OutputFormatPlugin,
|
||||||
OptionRecommendation)
|
OptionRecommendation)
|
||||||
from calibre.ptempfile import TemporaryDirectory
|
from calibre.ptempfile import TemporaryDirectory
|
||||||
@ -73,13 +73,13 @@ class PDFOutput(OutputFormatPlugin):
|
|||||||
' of stretching it to fill the full first page of the'
|
' of stretching it to fill the full first page of the'
|
||||||
' generated pdf.')),
|
' generated pdf.')),
|
||||||
OptionRecommendation(name='pdf_serif_family',
|
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')),
|
'The font family used to render serif fonts')),
|
||||||
OptionRecommendation(name='pdf_sans_family',
|
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')),
|
'The font family used to render sans-serif fonts')),
|
||||||
OptionRecommendation(name='pdf_mono_family',
|
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')),
|
'The font family used to render monospaced fonts')),
|
||||||
OptionRecommendation(name='pdf_standard_font', choices=['serif',
|
OptionRecommendation(name='pdf_standard_font', choices=['serif',
|
||||||
'sans', 'mono'],
|
'sans', 'mono'],
|
||||||
@ -102,6 +102,10 @@ class PDFOutput(OutputFormatPlugin):
|
|||||||
])
|
])
|
||||||
|
|
||||||
def convert(self, oeb_book, output_path, input_plugin, opts, log):
|
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.oeb = oeb_book
|
||||||
self.input_plugin, self.opts, self.log = input_plugin, opts, log
|
self.input_plugin, self.opts, self.log = input_plugin, opts, log
|
||||||
self.output_path = output_path
|
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.
|
If you ever move to Qt WebKit 2.3+ then this will be unnecessary.
|
||||||
'''
|
'''
|
||||||
from calibre.ebooks.oeb.base import urlnormalize
|
from calibre.ebooks.oeb.base import urlnormalize
|
||||||
from calibre.gui2 import must_use_qt
|
|
||||||
from calibre.utils.fonts.utils import remove_embed_restriction
|
from calibre.utils.fonts.utils import remove_embed_restriction
|
||||||
from PyQt4.Qt import QFontDatabase, QByteArray, QRawFont, QFont
|
from PyQt4.Qt import QFontDatabase, QByteArray, QRawFont, QFont
|
||||||
|
|
||||||
@ -165,7 +168,6 @@ class PDFOutput(OutputFormatPlugin):
|
|||||||
raw = remove_embed_restriction(raw)
|
raw = remove_embed_restriction(raw)
|
||||||
except:
|
except:
|
||||||
continue
|
continue
|
||||||
must_use_qt()
|
|
||||||
fid = QFontDatabase.addApplicationFontFromData(QByteArray(raw))
|
fid = QFontDatabase.addApplicationFontFromData(QByteArray(raw))
|
||||||
family_name = None
|
family_name = None
|
||||||
if fid > -1:
|
if fid > -1:
|
||||||
|
@ -766,6 +766,26 @@ class Translator(QTranslator):
|
|||||||
gui_thread = None
|
gui_thread = None
|
||||||
|
|
||||||
qt_app = 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):
|
class Application(QApplication):
|
||||||
|
|
||||||
def __init__(self, args, force_calibre_style=False,
|
def __init__(self, args, force_calibre_style=False,
|
||||||
@ -798,27 +818,12 @@ class Application(QApplication):
|
|||||||
return ret
|
return ret
|
||||||
|
|
||||||
def load_builtin_fonts(self, scan_for_fonts=False):
|
def load_builtin_fonts(self, scan_for_fonts=False):
|
||||||
global _rating_font
|
|
||||||
if scan_for_fonts:
|
if scan_for_fonts:
|
||||||
from calibre.utils.fonts.scanner import font_scanner
|
from calibre.utils.fonts.scanner import font_scanner
|
||||||
# Start scanning the users computer for fonts
|
# Start scanning the users computer for fonts
|
||||||
font_scanner
|
font_scanner
|
||||||
|
|
||||||
# Load the builtin fonts and any fonts added to calibre by the user to
|
load_builtin_fonts()
|
||||||
# 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'
|
|
||||||
|
|
||||||
def load_calibre_style(self):
|
def load_calibre_style(self):
|
||||||
# On OS X QtCurve resets the palette, so we preserve it explicitly
|
# On OS X QtCurve resets the palette, so we preserve it explicitly
|
||||||
|
Loading…
x
Reference in New Issue
Block a user