mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
On X11 initialize fontconfig in the GUI thread as Qt also uses fontconfig internally and fontconfig is not thread safe
This commit is contained in:
parent
f595ff2dfc
commit
6e3d2db96c
@ -11,7 +11,6 @@ from PyQt4.Qt import Qt
|
||||
from calibre.gui2.convert.mobi_output_ui import Ui_Form
|
||||
from calibre.gui2.convert import Widget
|
||||
from calibre.gui2.widgets import FontFamilyModel
|
||||
from calibre.utils.fonts import fontconfig
|
||||
|
||||
font_family_model = None
|
||||
|
||||
@ -28,6 +27,7 @@ class PluginWidget(Widget, Ui_Form):
|
||||
'mobi_ignore_margins',
|
||||
'dont_compress', 'no_inline_toc', 'masthead_font','personal_doc']
|
||||
)
|
||||
from calibre.utils.fonts import fontconfig
|
||||
self.db, self.book_id = db, book_id
|
||||
|
||||
global font_family_model
|
||||
|
@ -19,7 +19,6 @@ from calibre.gui2 import NONE, error_dialog, pixmap_to_data, gprefs
|
||||
from calibre.constants import isosx
|
||||
from calibre.gui2.filename_pattern_ui import Ui_Form
|
||||
from calibre import fit_image
|
||||
from calibre.utils.fonts import fontconfig
|
||||
from calibre.ebooks import BOOK_EXTENSIONS
|
||||
from calibre.ebooks.metadata.meta import metadata_from_filename
|
||||
from calibre.utils.config import prefs, XMLConfig
|
||||
@ -283,6 +282,7 @@ class FontFamilyModel(QAbstractListModel):
|
||||
|
||||
def __init__(self, *args):
|
||||
QAbstractListModel.__init__(self, *args)
|
||||
from calibre.utils.fonts import fontconfig
|
||||
try:
|
||||
self.families = fontconfig.find_font_families()
|
||||
except:
|
||||
|
@ -7,15 +7,19 @@ __copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
import os, sys
|
||||
from threading import Thread
|
||||
|
||||
from calibre.constants import plugins, iswindows
|
||||
from calibre.constants import plugins, iswindows, islinux, isfreebsd
|
||||
|
||||
_fc, _fc_err = plugins['fontconfig']
|
||||
|
||||
if _fc is None:
|
||||
raise RuntimeError('Failed to load fontconfig with error:'+_fc_err)
|
||||
|
||||
if islinux or isfreebsd:
|
||||
Thread = object
|
||||
else:
|
||||
from threading import Thread
|
||||
|
||||
class FontConfig(Thread):
|
||||
|
||||
def __init__(self):
|
||||
@ -45,7 +49,8 @@ class FontConfig(Thread):
|
||||
self.failed = True
|
||||
|
||||
def wait(self):
|
||||
self.join()
|
||||
if not (islinux or isfreebsd):
|
||||
self.join()
|
||||
if self.failed:
|
||||
raise RuntimeError('Failed to initialize fontconfig')
|
||||
|
||||
@ -144,7 +149,13 @@ class FontConfig(Thread):
|
||||
return fonts if all else (fonts[0] if fonts else None)
|
||||
|
||||
fontconfig = FontConfig()
|
||||
fontconfig.start()
|
||||
if islinux or isfreebsd:
|
||||
# On X11 Qt also uses fontconfig, so initialization must happen in the
|
||||
# main thread. In any case on X11 initializing fontconfig should be very
|
||||
# fast
|
||||
fontconfig.run()
|
||||
else:
|
||||
fontconfig.start()
|
||||
|
||||
def test():
|
||||
from pprint import pprint;
|
||||
|
Loading…
x
Reference in New Issue
Block a user