This commit is contained in:
Kovid Goyal 2015-04-15 10:30:19 +05:30
parent 218de802ba
commit 1dacfc5709

View File

@ -21,10 +21,17 @@ from calibre.utils.magick.draw import identify_data
Image = namedtuple('Image', 'rid fname width height fmt item') Image = namedtuple('Image', 'rid fname width height fmt item')
def as_num(x):
try:
return float(x)
except Exception:
pass
return 0
def get_image_margins(style): def get_image_margins(style):
ans = {} ans = {}
for edge in 'Left Right Top Bottom'.split(): for edge in 'Left Right Top Bottom'.split():
val = getattr(style, 'padding' + edge) + getattr(style, 'margin' + edge) val = as_num(getattr(style, 'padding' + edge)) + as_num(getattr(style, 'margin' + edge))
ans['dist' + edge[0]] = str(pt_to_emu(val)) ans['dist' + edge[0]] = str(pt_to_emu(val))
return ans return ans