mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-09-14 16:18:05 -04:00
ODT Input: Ensure that images are always contained in their frames. Fixes #860272 (floating images overlap text in epubs)
This commit is contained in:
parent
061ed389ca
commit
3c3f10dbee
@ -44,15 +44,19 @@ class Extract(ODF2XHTML):
|
|||||||
# Remove the position:relative as it causes problems with some epub
|
# Remove the position:relative as it causes problems with some epub
|
||||||
# renderers. Remove display: block on an image inside a div as it is
|
# renderers. Remove display: block on an image inside a div as it is
|
||||||
# redundant and prevents text-align:center from working in ADE
|
# redundant and prevents text-align:center from working in ADE
|
||||||
|
# Also ensure that the img is contained in its containing div
|
||||||
imgpath = XPath('//h:div/h:img[@style]')
|
imgpath = XPath('//h:div/h:img[@style]')
|
||||||
for img in imgpath(root):
|
for img in imgpath(root):
|
||||||
div = img.getparent()
|
div = img.getparent()
|
||||||
if len(div) == 1:
|
if len(div) == 1:
|
||||||
style = div.attrib['style'].replace('position:relative', '')
|
style = div.attrib.get('style', '')
|
||||||
if style.startswith(';'): style = style[1:]
|
if style and not style.endswith(';'):
|
||||||
|
style = style + ';'
|
||||||
|
style += 'position:static' # Ensures position of containing
|
||||||
|
# div is static
|
||||||
|
# Ensure that the img is always contained in its frame
|
||||||
div.attrib['style'] = style
|
div.attrib['style'] = style
|
||||||
if img.attrib.get('style', '') == 'display: block;':
|
img.attrib['style'] = 'max-width: 100%; max-height: 100%'
|
||||||
del img.attrib['style']
|
|
||||||
|
|
||||||
# A div/div/img construct causes text-align:center to not work in ADE
|
# A div/div/img construct causes text-align:center to not work in ADE
|
||||||
# so set the display of the second div to inline. This should have no
|
# so set the display of the second div to inline. This should have no
|
||||||
@ -65,7 +69,7 @@ class Extract(ODF2XHTML):
|
|||||||
div1 = div2.getparent()
|
div1 = div2.getparent()
|
||||||
if len(div1) == len(div2) == 1:
|
if len(div1) == len(div2) == 1:
|
||||||
style = div2.attrib['style']
|
style = div2.attrib['style']
|
||||||
div2.attrib['style'] = 'position:static;display:inline;'+style
|
div2.attrib['style'] = 'display:inline;'+style
|
||||||
|
|
||||||
|
|
||||||
def filter_css(self, root, log):
|
def filter_css(self, root, log):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user