mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix liberation fonts not loading on windows
This commit is contained in:
parent
7c18f4f0d2
commit
80fc2c7c68
@ -691,19 +691,27 @@ def remove_bracketed_text(src,
|
||||
return u''.join(buf)
|
||||
|
||||
def load_builtin_fonts():
|
||||
# On linux these are loaded by fontconfig which means that
|
||||
# they are available to Qt as well, since Qt uses fontconfig
|
||||
from calibre.utils.fonts import fontconfig
|
||||
fontconfig
|
||||
|
||||
families = {u'Liberation Serif', u'Liberation Sans', u'Liberation Mono'}
|
||||
|
||||
if iswindows or isosx:
|
||||
import glob
|
||||
from PyQt4.Qt import QFontDatabase
|
||||
families = set()
|
||||
for f in glob.glob(P('fonts/liberation/*.ttf')):
|
||||
QFontDatabase.addApplicationFont(f)
|
||||
else:
|
||||
# On linux these are loaded by fontconfig which means that
|
||||
# they are available to Qt as well, since Qt uses fontconfig
|
||||
from calibre.utils.fonts import fontconfig
|
||||
fontconfig
|
||||
|
||||
return 'Liberation Serif', 'Liberation Sans', 'Liberation Mono'
|
||||
with open(f, '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:
|
||||
families |= set(map(unicode,
|
||||
QFontDatabase.applicationFontFamilies(fid)))
|
||||
|
||||
return families
|
||||
|
||||
def ipython(user_ns=None):
|
||||
from calibre.utils.ipython import ipython
|
||||
|
@ -99,7 +99,6 @@ class FontFamilyDelegate(QStyledItemDelegate):
|
||||
else:
|
||||
r.setLeft(r.left() + 4)
|
||||
|
||||
old = painter.font()
|
||||
painter.setFont(font)
|
||||
painter.drawText(r, Qt.AlignVCenter|Qt.AlignLeading|Qt.TextSingleLine, text)
|
||||
|
||||
@ -113,8 +112,6 @@ class FontFamilyDelegate(QStyledItemDelegate):
|
||||
r.setLeft(r.left() + w)
|
||||
painter.drawText(r, Qt.AlignVCenter|Qt.AlignLeading|Qt.TextSingleLine, sample)
|
||||
|
||||
painter.setFont(old)
|
||||
|
||||
class FontFamilyChooser(QComboBox):
|
||||
|
||||
def __init__(self, parent=None):
|
||||
|
@ -191,10 +191,6 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, EmailMixin, # {{{
|
||||
self.content_server = None
|
||||
self.spare_servers = []
|
||||
self.must_restart_before_config = False
|
||||
# Initialize fontconfig in a separate thread as this can be a lengthy
|
||||
# process if run for the first time on this machine
|
||||
from calibre.utils.fonts import fontconfig
|
||||
self.fc = fontconfig
|
||||
self.listener = Listener(listener)
|
||||
self.check_messages_timer = QTimer()
|
||||
self.connect(self.check_messages_timer, SIGNAL('timeout()'),
|
||||
|
@ -19,8 +19,8 @@ class WinFonts(object):
|
||||
|
||||
def __init__(self, winfonts):
|
||||
self.w = winfonts
|
||||
# Windows thinks the Liberation font files are not valid, so we use
|
||||
# this hack to make them available
|
||||
# Windows requires font files to be executable for them to be loaded,
|
||||
# so instead we use this hack.
|
||||
self.app_font_families = {}
|
||||
|
||||
for f in ('Serif', 'Sans', 'Mono'):
|
||||
@ -121,6 +121,10 @@ class WinFonts(object):
|
||||
return ans
|
||||
|
||||
def add_system_font(self, path):
|
||||
'''
|
||||
WARNING: The file you are adding must have execute permissions or
|
||||
windows will fail to add it. (ls -l in cygwin to check)
|
||||
'''
|
||||
if isbytestring(path):
|
||||
path = path.decode(filesystem_encoding)
|
||||
path = os.path.abspath(path)
|
||||
|
Loading…
x
Reference in New Issue
Block a user