Nicer error message if the user tries to embed a font family that does not have a regular typeface

This commit is contained in:
Kovid Goyal 2012-10-26 19:34:46 +05:30
parent 39716497b4
commit 529a32360f
2 changed files with 20 additions and 0 deletions

View File

@ -184,6 +184,11 @@ class CSSFlattener(object):
faces = fontconfig.fonts_for_family(family) faces = fontconfig.fonts_for_family(family)
if not faces or not u'normal' in faces: if not faces or not u'normal' in faces:
msg = (u'No embeddable fonts found for family: %r'%self.opts.embed_font_family) 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: if failure_critical:
raise ValueError(msg) raise ValueError(msg)
self.oeb.log.warn(msg) self.oeb.log.warn(msg)

View File

@ -13,6 +13,7 @@ from PyQt4.Qt import (QFontInfo, QFontMetrics, Qt, QFont, QFontDatabase, QPen,
QToolButton, QGridLayout, QListView, QWidget, QDialogButtonBox, QIcon, QToolButton, QGridLayout, QListView, QWidget, QDialogButtonBox, QIcon,
QHBoxLayout, QLabel, QModelIndex) QHBoxLayout, QLabel, QModelIndex)
from calibre.gui2 import error_dialog
from calibre.utils.icu import sort_key from calibre.utils.icu import sort_key
def writing_system_for_font(font): def writing_system_for_font(font):
@ -173,6 +174,20 @@ class FontFamilyDialog(QDialog):
if idx == 0: return None if idx == 0: return None
return self.families[idx] 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): class FontFamilyChooser(QWidget):
family_changed = pyqtSignal(object) family_changed = pyqtSignal(object)