From e70fd3a759a8ba8eb275b056c88f187fc861e145 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 24 Jul 2014 22:11:34 +0530 Subject: [PATCH] Conversion: Fix a bug processing the CSS font shorthand property when the line-height is specified in em or percentage units. Fixes #1348173 [ebook-convert doesn't handle composite font-sizes](https://bugs.launchpad.net/calibre/+bug/1348173) --- src/calibre/ebooks/oeb/normalize_css.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/calibre/ebooks/oeb/normalize_css.py b/src/calibre/ebooks/oeb/normalize_css.py index 44cc3c51b1..8d135fde1a 100644 --- a/src/calibre/ebooks/oeb/normalize_css.py +++ b/src/calibre/ebooks/oeb/normalize_css.py @@ -132,15 +132,19 @@ def normalize_font(cssvalue, font_family_as_list=False): if not families and text == 'inherit': families.append(text) continue - if cssprofiles.validate('font-size', text): - style['font-size'] = text + if cssprofiles.validate('line-height', text): + if not vals or not cssprofiles.validate('font-size', vals[-1]): + if cssprofiles.validate('font-size', text): + style['font-size'] = text + found_font_size = True + break + return {} # must have font-size here + style['line-height'] = text + style['font-size'] = vals.pop() found_font_size = True break - if cssprofiles.validate('line-height', text): - style['line-height'] = text - if not vals or not cssprofiles.validate('font-size', vals[-1]): - return {} # must have font-size here - style['font-size'] = vals.pop() + if cssprofiles.validate('font-size', text): + style['font-size'] = text found_font_size = True break if families == ['inherit']: @@ -293,6 +297,7 @@ def test_normalization(): # {{{ '1.2pt/1.4 A_Font': {'font-family':'A_Font', 'font-size':'1.2pt', 'line-height':'1.4'}, 'bad font': {}, '10% serif': {'font-family':'serif', 'font-size':'10%'}, '12px "My Font", serif': {'font-family':'"My Font", serif', 'font-size': '12px'}, + 'normal 0.6em/135% arial,sans-serif': {'font-family': 'arial, sans-serif', 'font-size': '0.6em', 'line-height':'135%', 'font-style':'normal'}, 'bold italic large serif': {'font-family':'serif', 'font-weight':'bold', 'font-style':'italic', 'font-size':'large'}, 'bold italic small-caps larger/normal serif': {'font-family':'serif', 'font-weight':'bold', 'font-style':'italic', 'font-size':'larger',