Normalize font names when changing fonts and the font is available on the local machine

This commit is contained in:
Kovid Goyal 2014-06-12 21:04:25 +05:30
parent 673c28f8aa
commit b5d40b4aff

View File

@ -19,7 +19,7 @@ from calibre.gui2 import error_dialog
from calibre.gui2.tweak_book import current_container, set_current_container from calibre.gui2.tweak_book import current_container, set_current_container
from calibre.gui2.tweak_book.widgets import Dialog, BusyCursor from calibre.gui2.tweak_book.widgets import Dialog, BusyCursor
from calibre.utils.icu import primary_sort_key as sort_key from calibre.utils.icu import primary_sort_key as sort_key
from calibre.utils.fonts.scanner import font_scanner from calibre.utils.fonts.scanner import font_scanner, NoFonts
class AllFonts(QAbstractTableModel): class AllFonts(QAbstractTableModel):
@ -115,6 +115,17 @@ class ChangeFontFamily(Dialog):
def family(self): def family(self):
return unicode(self._family.text()) return unicode(self._family.text())
@property
def normalized_family(self):
ans = self.family
try:
ans = font_scanner.fonts_for_family(ans)[0]['font-family']
except (NoFonts, IndexError, KeyError):
pass
if icu_lower(ans) == 'sansserif':
ans = 'sans-serif'
return ans
def updated_family(self): def updated_family(self):
family = self.family family = self.family
found = icu_lower(family) in self.local_families found = icu_lower(family) in self.local_families
@ -209,7 +220,7 @@ class ManageFonts(Dialog):
if d.exec_() != d.Accepted: if d.exec_() != d.Accepted:
return return
changed = False changed = False
new_family = d.family new_family = d.normalized_family
for font in fonts: for font in fonts:
changed |= change_font(current_container(), font, new_family) changed |= change_font(current_container(), font, new_family)
if changed: if changed: