mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix images longer than a page being rendered on multiple pages instead of being rescaled
Apparently in newer blink engines bounding rect height is set to viewport height for images even if they stretch over multiple columns.
This commit is contained in:
parent
599d3dbddc
commit
2ca39a8066
@ -75,8 +75,8 @@ def fit_images():
|
|||||||
# Ensure no images are wider than the available width in a column. Note
|
# Ensure no images are wider than the available width in a column. Note
|
||||||
# that this method use getBoundingClientRect() which means it will
|
# that this method use getBoundingClientRect() which means it will
|
||||||
# force a relayout if the render tree is dirty.
|
# force a relayout if the render tree is dirty.
|
||||||
images = []
|
images = v'[]'
|
||||||
vimages = []
|
vimages = v'[]'
|
||||||
img_tags = document.getElementsByTagName('img')
|
img_tags = document.getElementsByTagName('img')
|
||||||
bounding_rects = v'[]'
|
bounding_rects = v'[]'
|
||||||
for img_tag in img_tags:
|
for img_tag in img_tags:
|
||||||
@ -96,9 +96,9 @@ def fit_images():
|
|||||||
width = br.right - br.left
|
width = br.right - br.left
|
||||||
rright = rleft + width
|
rright = rleft + width
|
||||||
if previously_limited or rright > col_width:
|
if previously_limited or rright > col_width:
|
||||||
images.push([img, col_width - rleft])
|
images.push(v'[img, col_width - rleft]')
|
||||||
previously_limited = get_elem_data(img, 'height-limited', False)
|
previously_limited = get_elem_data(img, 'height-limited', False)
|
||||||
if previously_limited or br.height > maxh:
|
if previously_limited or br.height > maxh or (br.height is maxh and br.width > col_width):
|
||||||
vimages.push(img)
|
vimages.push(img)
|
||||||
if previously_limited:
|
if previously_limited:
|
||||||
set_css(img, break_before='auto', display=data.display)
|
set_css(img, break_before='auto', display=data.display)
|
||||||
@ -110,12 +110,7 @@ def fit_images():
|
|||||||
|
|
||||||
for img_tag in vimages:
|
for img_tag in vimages:
|
||||||
data = get_elem_data(img_tag, 'img-data', None)
|
data = get_elem_data(img_tag, 'img-data', None)
|
||||||
set_css(img_tag, break_before='always', max_height=maxh+'px')
|
set_css(img_tag, break_before='always', max_height='100vh')
|
||||||
if data.height > maxh:
|
|
||||||
# This is needed to force the image onto a new page, without
|
|
||||||
# it, the webkit algorithm may still decide to split the image
|
|
||||||
# by keeping it part of its parent block
|
|
||||||
img.style.setProperty('display', 'block')
|
|
||||||
set_elem_data(img, 'height-limited', True)
|
set_elem_data(img, 'height-limited', True)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user