mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-31 14:33:54 -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)
|
return u''.join(buf)
|
||||||
|
|
||||||
def load_builtin_fonts():
|
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:
|
if iswindows or isosx:
|
||||||
import glob
|
import glob
|
||||||
from PyQt4.Qt import QFontDatabase
|
from PyQt4.Qt import QFontDatabase
|
||||||
|
families = set()
|
||||||
for f in glob.glob(P('fonts/liberation/*.ttf')):
|
for f in glob.glob(P('fonts/liberation/*.ttf')):
|
||||||
QFontDatabase.addApplicationFont(f)
|
with open(f, 'rb') as s:
|
||||||
else:
|
# Windows requires font files to be executable for them to be
|
||||||
# On linux these are loaded by fontconfig which means that
|
# loaded successfully, so we use the in memory loader
|
||||||
# they are available to Qt as well, since Qt uses fontconfig
|
fid = QFontDatabase.addApplicationFontFromData(s.read())
|
||||||
from calibre.utils.fonts import fontconfig
|
if fid > -1:
|
||||||
fontconfig
|
families |= set(map(unicode,
|
||||||
|
QFontDatabase.applicationFontFamilies(fid)))
|
||||||
return 'Liberation Serif', 'Liberation Sans', 'Liberation Mono'
|
|
||||||
|
|
||||||
|
return families
|
||||||
|
|
||||||
def ipython(user_ns=None):
|
def ipython(user_ns=None):
|
||||||
from calibre.utils.ipython import ipython
|
from calibre.utils.ipython import ipython
|
||||||
|
@ -99,7 +99,6 @@ class FontFamilyDelegate(QStyledItemDelegate):
|
|||||||
else:
|
else:
|
||||||
r.setLeft(r.left() + 4)
|
r.setLeft(r.left() + 4)
|
||||||
|
|
||||||
old = painter.font()
|
|
||||||
painter.setFont(font)
|
painter.setFont(font)
|
||||||
painter.drawText(r, Qt.AlignVCenter|Qt.AlignLeading|Qt.TextSingleLine, text)
|
painter.drawText(r, Qt.AlignVCenter|Qt.AlignLeading|Qt.TextSingleLine, text)
|
||||||
|
|
||||||
@ -113,8 +112,6 @@ class FontFamilyDelegate(QStyledItemDelegate):
|
|||||||
r.setLeft(r.left() + w)
|
r.setLeft(r.left() + w)
|
||||||
painter.drawText(r, Qt.AlignVCenter|Qt.AlignLeading|Qt.TextSingleLine, sample)
|
painter.drawText(r, Qt.AlignVCenter|Qt.AlignLeading|Qt.TextSingleLine, sample)
|
||||||
|
|
||||||
painter.setFont(old)
|
|
||||||
|
|
||||||
class FontFamilyChooser(QComboBox):
|
class FontFamilyChooser(QComboBox):
|
||||||
|
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
|
@ -191,10 +191,6 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, EmailMixin, # {{{
|
|||||||
self.content_server = None
|
self.content_server = None
|
||||||
self.spare_servers = []
|
self.spare_servers = []
|
||||||
self.must_restart_before_config = False
|
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.listener = Listener(listener)
|
||||||
self.check_messages_timer = QTimer()
|
self.check_messages_timer = QTimer()
|
||||||
self.connect(self.check_messages_timer, SIGNAL('timeout()'),
|
self.connect(self.check_messages_timer, SIGNAL('timeout()'),
|
||||||
|
@ -19,8 +19,8 @@ class WinFonts(object):
|
|||||||
|
|
||||||
def __init__(self, winfonts):
|
def __init__(self, winfonts):
|
||||||
self.w = winfonts
|
self.w = winfonts
|
||||||
# Windows thinks the Liberation font files are not valid, so we use
|
# Windows requires font files to be executable for them to be loaded,
|
||||||
# this hack to make them available
|
# so instead we use this hack.
|
||||||
self.app_font_families = {}
|
self.app_font_families = {}
|
||||||
|
|
||||||
for f in ('Serif', 'Sans', 'Mono'):
|
for f in ('Serif', 'Sans', 'Mono'):
|
||||||
@ -121,6 +121,10 @@ class WinFonts(object):
|
|||||||
return ans
|
return ans
|
||||||
|
|
||||||
def add_system_font(self, path):
|
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):
|
if isbytestring(path):
|
||||||
path = path.decode(filesystem_encoding)
|
path = path.decode(filesystem_encoding)
|
||||||
path = os.path.abspath(path)
|
path = os.path.abspath(path)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user