diff --git a/src/calibre/gui2/tweak_book/file_list.py b/src/calibre/gui2/tweak_book/file_list.py index 9d46c7ee6a..126f482678 100644 --- a/src/calibre/gui2/tweak_book/file_list.py +++ b/src/calibre/gui2/tweak_book/file_list.py @@ -13,9 +13,9 @@ from functools import partial from PyQt5.Qt import ( QApplication, QCheckBox, QDialog, QDialogButtonBox, QFont, QFormLayout, QGridLayout, QIcon, QInputDialog, QLabel, QLineEdit, QListWidget, - QListWidgetItem, QMenu, QPainter, QPixmap, QRadioButton, QRawFont, QScrollArea, - QSize, QSpinBox, QStyle, QStyledItemDelegate, Qt, QTimer, QTreeWidget, - QTreeWidgetItem, QVBoxLayout, QWidget, pyqtSignal + QListWidgetItem, QMenu, QPainter, QPixmap, QRadioButton, QScrollArea, QSize, + QSpinBox, QStyle, QStyledItemDelegate, Qt, QTimer, QTreeWidget, QTreeWidgetItem, + QVBoxLayout, QWidget, pyqtSignal ) from calibre import human_readable, plugins, sanitize_file_name @@ -37,6 +37,7 @@ from calibre.gui2.tweak_book import ( ) from calibre.gui2.tweak_book.editor import syntax_from_mime from calibre.gui2.tweak_book.templates import template_for +from calibre.utils.fonts.utils import get_font_names from calibre.utils.icu import numeric_sort_key from polyglot.binary import as_hex_unicode from polyglot.builtins import filter, iteritems, itervalues, map, range, unicode_type @@ -468,7 +469,7 @@ class FileList(QTreeWidget): # Duplicate entry in spine emblems.append('dialog_error.png') tooltips.append(_('This file occurs more than once in the spine')) - if category == 'fonts': + if category == 'fonts' and name.rpartition('.')[-1].lower() in ('ttf', 'otf'): fname = self.get_font_family_name(name) if fname: tooltips.append(fname) @@ -512,10 +513,9 @@ class FileList(QTreeWidget): key = name, sz if key not in self.font_name_cache: raw = current_container().raw_data(name, decode=False) - f = QRawFont(raw, 12) - if f.isValid(): - ans = f.familyName() + ' ' + f.styleName() - else: + try: + ans = get_font_names(raw)[-1] + except Exception: ans = None self.font_name_cache[key] = ans return self.font_name_cache[key]