mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Nicer error message if the user tries to embed a font family that does not have a regular typeface
This commit is contained in:
parent
39716497b4
commit
529a32360f
@ -184,6 +184,11 @@ class CSSFlattener(object):
|
||||
faces = fontconfig.fonts_for_family(family)
|
||||
if not faces or not u'normal' in faces:
|
||||
msg = (u'No embeddable fonts found for family: %r'%self.opts.embed_font_family)
|
||||
if faces:
|
||||
msg = (u'The selected font %s has no Regular typeface, only'
|
||||
' %s faces, it cannot be used.')%(
|
||||
self.opts.embed_font_family,
|
||||
', '.join(faces.iterkeys()))
|
||||
if failure_critical:
|
||||
raise ValueError(msg)
|
||||
self.oeb.log.warn(msg)
|
||||
|
@ -13,6 +13,7 @@ from PyQt4.Qt import (QFontInfo, QFontMetrics, Qt, QFont, QFontDatabase, QPen,
|
||||
QToolButton, QGridLayout, QListView, QWidget, QDialogButtonBox, QIcon,
|
||||
QHBoxLayout, QLabel, QModelIndex)
|
||||
|
||||
from calibre.gui2 import error_dialog
|
||||
from calibre.utils.icu import sort_key
|
||||
|
||||
def writing_system_for_font(font):
|
||||
@ -173,6 +174,20 @@ class FontFamilyDialog(QDialog):
|
||||
if idx == 0: return None
|
||||
return self.families[idx]
|
||||
|
||||
def accept(self):
|
||||
ff = self.font_family
|
||||
if ff:
|
||||
from calibre.utils.fonts import fontconfig
|
||||
faces = fontconfig.fonts_for_family(ff) or {}
|
||||
faces = frozenset(faces.iterkeys())
|
||||
if 'normal' not in faces:
|
||||
error_dialog(self, _('Not a useable font'),
|
||||
_('The %s font family does not have a Regular typeface, so it'
|
||||
' cannot be used. It has only the "%s" face(s).')%(
|
||||
ff, ', '.join(faces)), show=True)
|
||||
return
|
||||
QDialog.accept(self)
|
||||
|
||||
class FontFamilyChooser(QWidget):
|
||||
|
||||
family_changed = pyqtSignal(object)
|
||||
|
Loading…
x
Reference in New Issue
Block a user