mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
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:
parent
317a2b9a14
commit
ddd5b0315e
@ -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]
|
||||
|
Loading…
x
Reference in New Issue
Block a user