From ace64ded2121bb8890ca2c235a6470079e525328 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 19 Oct 2009 17:36:33 -0600 Subject: [PATCH] Conversion pipeline: Convert width and height attributes of th e tag to CSS. Fixes #3536 (HTML image size attributes) --- src/calibre/ebooks/mobi/mobiml.py | 2 +- src/calibre/ebooks/oeb/stylizer.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/calibre/ebooks/mobi/mobiml.py b/src/calibre/ebooks/mobi/mobiml.py index 0d5acf38ea..5597555225 100644 --- a/src/calibre/ebooks/mobi/mobiml.py +++ b/src/calibre/ebooks/mobi/mobiml.py @@ -188,7 +188,7 @@ class MobiMLizer(object): bstate.vpadding = bstate.vmargin = 0 if tag not in TABLE_TAGS: wrapper.attrib['height'] = self.mobimlize_measure(vspace) - para.attrib['width'] = self.mobimlize_measure(indent) + para.attrib['width'] = self.mobimlize_measure(indent) elif tag == 'table' and vspace > 0: vspace = int(round(vspace / self.profile.fbase)) while vspace > 0: diff --git a/src/calibre/ebooks/oeb/stylizer.py b/src/calibre/ebooks/oeb/stylizer.py index a282b0c2fc..1434aca3c2 100644 --- a/src/calibre/ebooks/oeb/stylizer.py +++ b/src/calibre/ebooks/oeb/stylizer.py @@ -188,6 +188,16 @@ class Stylizer(object): %(text, item.href)) for elem in matches: self.style(elem)._update_cssdict(cssdict) + for elem in xpath(tree, '//h:img[@width or @height]'): + base = elem.get('style', '').strip() + if base: + base += ';' + for prop in ('width', 'height'): + val = elem.get(prop, False) + if val: + base += '%s: %s;'%(prop, val) + del elem.attrib[prop] + elem.set('style', base) for elem in xpath(tree, '//h:*[@style]'): self.style(elem)._apply_style_attr()