Textile output: Dont fail if input document has invalid padding or margin specifications. Fixes #1960686 [Private bug](https://bugs.launchpad.net/calibre/+bug/1960686)

This commit is contained in:
Kovid Goyal 2022-02-12 13:19:29 +05:30
parent 2fadaf5b19
commit 3d71e15a65
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -174,11 +174,19 @@ class TextileMLizer(OEB2HTML):
txt = '' txt = ''
left_padding_pts = 0 left_padding_pts = 0
left_margin_pts = 0 left_margin_pts = 0
def add(x, y):
if isinstance(x, str):
x = 0
if isinstance(y, str):
y = 0
return x +y
if 'padding-left' in style.cssdict() and style['padding-left'] != 'auto': if 'padding-left' in style.cssdict() and style['padding-left'] != 'auto':
left_padding_pts = unit_convert(style['padding-left'], style.width, style.fontSize, stylizer.profile.dpi) left_padding_pts = unit_convert(style['padding-left'], style.width, style.fontSize, stylizer.profile.dpi)
if 'margin-left' in style.cssdict() and style['margin-left'] != 'auto': if 'margin-left' in style.cssdict() and style['margin-left'] != 'auto':
left_margin_pts = unit_convert(style['margin-left'], style.width, style.fontSize, stylizer.profile.dpi) left_margin_pts = unit_convert(style['margin-left'], style.width, style.fontSize, stylizer.profile.dpi)
left = left_margin_pts + left_padding_pts left = add(left_margin_pts, left_padding_pts)
emleft = min(int(round(left / stylizer.profile.fbase)), self.MAX_EM) emleft = min(int(round(left / stylizer.profile.fbase)), self.MAX_EM)
if emleft >= 1: if emleft >= 1:
txt += '(' * emleft txt += '(' * emleft
@ -188,7 +196,7 @@ class TextileMLizer(OEB2HTML):
right_padding_pts = unit_convert(style['padding-right'], style.width, style.fontSize, stylizer.profile.dpi) right_padding_pts = unit_convert(style['padding-right'], style.width, style.fontSize, stylizer.profile.dpi)
if 'margin-right' in style.cssdict() and style['margin-right'] != 'auto': if 'margin-right' in style.cssdict() and style['margin-right'] != 'auto':
right_margin_pts = unit_convert(style['margin-right'], style.width, style.fontSize, stylizer.profile.dpi) right_margin_pts = unit_convert(style['margin-right'], style.width, style.fontSize, stylizer.profile.dpi)
right = right_margin_pts + right_padding_pts right = add(right_margin_pts, right_padding_pts)
emright = min(int(round(right / stylizer.profile.fbase)), self.MAX_EM) emright = min(int(round(right / stylizer.profile.fbase)), self.MAX_EM)
if emright >= 1: if emright >= 1:
txt += ')' * emright txt += ')' * emright