Use calibre code rather than Qt to get font names. More robust. Appears

that on windows QRawFont chokes on OTF fonts with CFF outlines
This commit is contained in:
Kovid Goyal 2019-09-25 14:21:28 +05:30
parent 317a2b9a14
commit ddd5b0315e
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

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