Fix various small bugs that could cause conversion to DOCX to error out

This commit is contained in:
Kovid Goyal 2015-05-14 14:05:31 +05:30
parent 5ceb650f2a
commit 389d433d51
3 changed files with 13 additions and 7 deletions

View File

@ -372,11 +372,11 @@ class Blocks(object):
count[run.lang] += 1
if count:
block.block_lang = bl = count.most_common(1)[0][0]
for run in block.runs:
if run.lang == bl:
run.lang = None
if bl == default_lang:
block.block_lang = None
for run in block.runs:
if run.lang == bl:
run.lang = None
if bl == default_lang:
block.block_lang = None
def __repr__(self):
return 'Block(%r)' % self.runs

View File

@ -61,7 +61,10 @@ class ImagesManager(object):
if not src:
return
href = self.abshref(src)
rid = self.read_image(href).rid
try:
rid = self.read_image(href).rid
except AttributeError:
return
drawing = self.create_image_markup(img, stylizer, href, as_block=as_block)
block.add_image(drawing, bookmark=bookmark)
return rid

View File

@ -400,7 +400,10 @@ class BlockStyle(DOCXStyle):
else:
self.text_indent = int(css['text-indent'] * 20)
self.css_text_indent = css._get('text-indent')
self.line_height = max(0, int(css.lineHeight * 20))
try:
self.line_height = max(0, int(css.lineHeight * 20))
except (TypeError, ValueError):
self.line_height = max(0, int(1.2 * css.fontSize * 20))
self.background_color = None if is_table_cell else convert_color(css['background-color'])
self.text_align = {'start':'left', 'left':'left', 'end':'right', 'right':'right', 'center':'center', 'justify':'both', 'centre':'center'}.get(
css['text-align'].lower(), 'left')