mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
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:
parent
58652ae068
commit
2b562831d7
@ -77,34 +77,34 @@ def get_image_margins(elem):
|
|||||||
return ans
|
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):
|
for ph in XPath('./wp:positionH')(anchor):
|
||||||
rp = ph.get('relativeFrom', None)
|
rp = ph.get('relativeFrom', None)
|
||||||
if rp == 'leftMargin':
|
if rp == 'leftMargin':
|
||||||
return 0
|
return 0 + width_frac
|
||||||
if rp == 'rightMargin':
|
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):
|
for align in XPath('./wp:align')(ph):
|
||||||
al = align.text
|
al = almap.get(align.text)
|
||||||
if al == 'left':
|
if al is not None:
|
||||||
return 0
|
if rp == 'page':
|
||||||
if al == 'center':
|
return al
|
||||||
return 0.5
|
return al + width_frac
|
||||||
if al == 'right':
|
|
||||||
return 1
|
|
||||||
for po in XPath('./wp:posOffset')(ph):
|
for po in XPath('./wp:posOffset')(ph):
|
||||||
try:
|
try:
|
||||||
pos = emu_to_pt(int(po.text))
|
pos = emu_to_pt(int(po.text))
|
||||||
except (TypeError, ValueError):
|
except (TypeError, ValueError):
|
||||||
continue
|
continue
|
||||||
return pos/page_width
|
return pos/page_width + width_frac
|
||||||
|
|
||||||
for sp in XPath('./wp:simplePos')(anchor):
|
for sp in XPath('./wp:simplePos')(anchor):
|
||||||
try:
|
try:
|
||||||
x = emu_to_pt(sp.get('x', None))
|
x = emu_to_pt(sp.get('x', None))
|
||||||
except (TypeError, ValueError):
|
except (TypeError, ValueError):
|
||||||
continue
|
continue
|
||||||
return x/page_width
|
return x/page_width + width_frac
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
@ -298,7 +298,7 @@ class Images(object):
|
|||||||
# Ignore margins
|
# Ignore margins
|
||||||
page_width = page.width
|
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
|
wrap_elem = None
|
||||||
dofloat = False
|
dofloat = False
|
||||||
|
Loading…
x
Reference in New Issue
Block a user