From ebf380530db78f557bb13b7b4ba495aed810fcbc Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 12 Jun 2014 21:20:02 +0530 Subject: [PATCH] Edit Book: Check book: When auto-changing font name to match actual name in font file, also change the font name in shorthand font declarations --- src/calibre/ebooks/oeb/polish/check/fonts.py | 23 +++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/calibre/ebooks/oeb/polish/check/fonts.py b/src/calibre/ebooks/oeb/polish/check/fonts.py index 7c12757bfb..1ca44bd8e8 100644 --- a/src/calibre/ebooks/oeb/polish/check/fonts.py +++ b/src/calibre/ebooks/oeb/polish/check/fonts.py @@ -25,15 +25,22 @@ class InvalidFont(BaseError): HELP = _('This font could not be processed. It most likely will' ' not work in an ebook reader, either') -def fix_declaration(style, css_name, font_name): - ff = style.getPropertyCSSValue('font-family') +def fix_property(prop, css_name, font_name): changed = False - if ff is not None: - for i in xrange(ff.length): - val = ff.item(i) - if hasattr(val.value, 'lower') and val.value.lower() == css_name.lower(): - change_font_family_value(val, font_name) - changed = True + ff = prop.propertyValue + for i in xrange(ff.length): + val = ff.item(i) + if hasattr(val.value, 'lower') and val.value.lower() == css_name.lower(): + change_font_family_value(val, font_name) + changed = True + return changed + +def fix_declaration(style, css_name, font_name): + changed = False + for x in ('font-family', 'font'): + prop = style.getProperty(x) + if prop is not None: + changed |= fix_property(prop, css_name, font_name) return changed def fix_sheet(sheet, css_name, font_name):