mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Conversion pipeline: Do not override CSS for images with the value of the img width/height attributes, unless no CSS is specified for the image
This commit is contained in:
parent
6f2a36949a
commit
26aef9cc53
@ -240,18 +240,26 @@ class Stylizer(object):
|
|||||||
else:
|
else:
|
||||||
for elem in matches:
|
for elem in matches:
|
||||||
self.style(elem)._update_cssdict(cssdict)
|
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]'):
|
for elem in xpath(tree, '//h:*[@style]'):
|
||||||
self.style(elem)._apply_style_attr()
|
self.style(elem)._apply_style_attr()
|
||||||
|
num_pat = re.compile(r'\d+$')
|
||||||
|
for elem in xpath(tree, '//h:img[@width or @height]'):
|
||||||
|
style = self.style(elem)
|
||||||
|
# Check if either height or width is not default
|
||||||
|
is_styled = style._style.get('width', 'auto') != 'auto' or \
|
||||||
|
style._style.get('height', 'auto') != 'auto'
|
||||||
|
if not is_styled:
|
||||||
|
# Update img style dimension using width and height
|
||||||
|
upd = {}
|
||||||
|
for prop in ('width', 'height'):
|
||||||
|
val = elem.get(prop, '').strip()
|
||||||
|
del elem.attrib[prop]
|
||||||
|
if val:
|
||||||
|
if num_pat.match(val) is not None:
|
||||||
|
val += 'px'
|
||||||
|
upd[prop] = val
|
||||||
|
if upd:
|
||||||
|
style._update_cssdict(upd)
|
||||||
|
|
||||||
def _fetch_css_file(self, path):
|
def _fetch_css_file(self, path):
|
||||||
hrefs = self.oeb.manifest.hrefs
|
hrefs = self.oeb.manifest.hrefs
|
||||||
|
Loading…
x
Reference in New Issue
Block a user