From 11136aab9244700f6f98ed617f5b4322290687ad Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 29 Apr 2016 20:30:35 +0530 Subject: [PATCH] Ensure WebKit sizes columns correctly --- src/pyj/read_book/paged_mode.pyj | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/pyj/read_book/paged_mode.pyj b/src/pyj/read_book/paged_mode.pyj index dc7d7b9b1d..8a019c4f07 100644 --- a/src/pyj/read_book/paged_mode.pyj +++ b/src/pyj/read_book/paged_mode.pyj @@ -178,12 +178,22 @@ def layout(is_single_page): evt.preventDefault() ) - ncols = (document.body.scrollWidth + gap) / col_and_gap - if ncols is not Math.floor(ncols): - n = Math.floor(ncols) - dw = (n*col_width + (n-1)*gap) - document.body.width = dw + 'px' - print('WARNING: column layout broken', {'col_with':col_width, 'gap':gap, 'scrollWidth':document.body.scrollWidth, 'ncols':ncols, 'delta':document.body.scrollWidth - dw}) + def check_column_widths(): + ncols = (document.body.scrollWidth + gap) / col_and_gap + if ncols is not Math.floor(ncols): + n = Math.floor(ncols) + dw = (n*col_width + (n-1)*gap) + data = {'col_with':col_width, 'gap':gap, 'scrollWidth':document.body.scrollWidth, 'ncols':ncols, 'desired_width':dw} + return data + data = check_column_widths() + if data: + dw = data.desired_width + set_css(document.body, max_width=dw + 'px', min_width=dw + 'px') + set_css(document.documentElement, max_width=dw + 'px', min_width=dw + 'px') + data = check_column_widths() + if data: + print('WARNING: column layout broken', data) + _in_paged_mode = True fit_images() return gap