From dc922e5a33275e75437bf6034ed3b83df8ef3764 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 6 Jun 2018 18:13:39 +0530 Subject: [PATCH] Port many images fix to browser viewer as well --- src/pyj/read_book/paged_mode.pyj | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/pyj/read_book/paged_mode.pyj b/src/pyj/read_book/paged_mode.pyj index f024816b2f..8fc81a075d 100644 --- a/src/pyj/read_book/paged_mode.pyj +++ b/src/pyj/read_book/paged_mode.pyj @@ -78,11 +78,16 @@ def fit_images(): # force a relayout if the render tree is dirty. images = [] vimages = [] + img_tags = document.getElementsByTagName('img') + bounding_rects = v'[]' + for img_tag in img_tags: + bounding_rects.push(img_tag.getBoundingClientRect()) maxh = screen_height - for img in document.getElementsByTagName('img'): + for i in range(img_tags.length): + img = img_tags[i] + br = bounding_rects[i] previously_limited = get_elem_data(img, 'width-limited', False) data = get_elem_data(img, 'img-data', None) - br = img.getBoundingClientRect() if data is None: data = {'left':br.left, 'right':br.right, 'height':br.height, 'display': img.style.display} set_elem_data(img, 'img-data', data) @@ -100,13 +105,13 @@ def fit_images(): set_css(img, break_before='auto', display=data.display) set_css(img, break_inside='avoid') - for img, max_width in images: - img.style.setProperty('max-width', max_width+'px') - set_elem_data(img, 'width-limited', True) + for img_tag, max_width in images: + img_tag.style.setProperty('max-width', max_width+'px') + set_elem_data(img_tag, 'width-limited', True) - for img in vimages: - data = get_elem_data(img, 'img-data', None) - set_css(img, break_before='always', max_height=maxh+'px') + for img_tag in vimages: + data = get_elem_data(img_tag, 'img-data', None) + set_css(img_tag, break_before='always', max_height=maxh+'px') 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