DOCX Input: Fix images wider than 50% of the page width being incorrectly right aligned even when anchored to the center of the page. Fixes #1646086 [Folow up to Location of Figures on Page](https://bugs.launchpad.net/calibre/+bug/1646086)

This commit is contained in:
Kovid Goyal 2016-12-02 09:30:33 +05:30
parent 58652ae068
commit 2b562831d7

View File

@ -77,34 +77,34 @@ def get_image_margins(elem):
return ans
def get_hpos(anchor, page_width, XPath, get):
def get_hpos(anchor, page_width, XPath, get, width_frac):
for ph in XPath('./wp:positionH')(anchor):
rp = ph.get('relativeFrom', None)
if rp == 'leftMargin':
return 0
return 0 + width_frac
if rp == 'rightMargin':
return 1
return 1 + width_frac
al = None
almap = {'left':0, 'center':0.5, 'right':1}
for align in XPath('./wp:align')(ph):
al = align.text
if al == 'left':
return 0
if al == 'center':
return 0.5
if al == 'right':
return 1
al = almap.get(align.text)
if al is not None:
if rp == 'page':
return al
return al + width_frac
for po in XPath('./wp:posOffset')(ph):
try:
pos = emu_to_pt(int(po.text))
except (TypeError, ValueError):
continue
return pos/page_width
return pos/page_width + width_frac
for sp in XPath('./wp:simplePos')(anchor):
try:
x = emu_to_pt(sp.get('x', None))
except (TypeError, ValueError):
continue
return x/page_width
return x/page_width + width_frac
return 0
@ -298,7 +298,7 @@ class Images(object):
# Ignore margins
page_width = page.width
hpos = get_hpos(anchor, page_width, XPath, get) + width/(2*page_width)
hpos = get_hpos(anchor, page_width, XPath, get, width/(2*page_width))
wrap_elem = None
dofloat = False