From 46a379116eda299eaf240805322d3d506dbf46e8 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 27 Jul 2012 15:24:43 +0530 Subject: [PATCH] Paged display: Resize images that are longer than the page to fit onto a single page --- resources/compiled_coffeescript.zip | Bin 52157 -> 53566 bytes src/calibre/ebooks/oeb/display/paged.coffee | 26 ++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/resources/compiled_coffeescript.zip b/resources/compiled_coffeescript.zip index 2cfe5cfebf8a9ab77ae1a64078e28cff5c7b62bd..1b8af62d52c2a54dcd62436c6808c019b3cb580e 100644 GIT binary patch delta 939 zcmdlxoq69PW{CiAW)=|!5YVpr?NA=*+1u;Rz|iYHIo3&XqhTwPOmb;aQEFaEd_iJ* zYJ5g&W_m`6f~`VcX-)AlR}ss}cX>HB?-!oW$(&e{ zI5}EYl{q)DVsfpl8edsvF3{j&9fk7Dl#-0e*~~_h&&w(pLxq7hMaNomDS!b`O9oH? zmsOLW%RXdD0h!++r@)_?o30DusOx~;I(e_0DMx0Sf(BT@0cO#91qBcjXkIncc!(wH zIjLzS>Q)L#MS38X4yt4k$omjkFcVE05HCc7yJu|bqh_EMCe%qqe!l~k0Pn5~>&a^rv?kA#;Ae+AaPnFS)yZ*kY?4rZbbK~EH9+DI6xRZ1ajiMoLs1cA zvjm3QbIKDdi`792R3|?W=QIK*DQyMyf(nFt6ck|T1X~b-JS~Xuw0crbesZ=t*uQ;> zTF_|NyjQVl1s__5@;w#Fbj*EnqLb|8qo=f(N<$}qJmtl7AQdPgI=LW$ZF0nEEvEZN T!QB1>e3O@-7GT?Q9+WcyxP&T2 delta 208 zcmdnDh}5|Od!qz;+)hx2x&MuLC$FMS-G2&pU7)XzGbVm*;;Wr<7EBA z+>;wsB_^L`<)1u7W%XnMb&bi9s-m0y)QeW|q1k%wd?b^r)8vVvqLb||7%_eE2Qn2V iPr9JRWS;;Qy?nudDeeH6DR7K$vc^RLHsezu=K}yHaYx$# diff --git a/src/calibre/ebooks/oeb/display/paged.coffee b/src/calibre/ebooks/oeb/display/paged.coffee index c2a09b5587..3b9682b590 100644 --- a/src/calibre/ebooks/oeb/display/paged.coffee +++ b/src/calibre/ebooks/oeb/display/paged.coffee @@ -26,6 +26,7 @@ class PagedDisplay this.current_margin_side = 0 this.is_full_screen_layout = false this.max_col_width = -1 + this.current_page_height = null this.document_margins = null this.use_document_margins = false @@ -116,6 +117,7 @@ class PagedDisplay col_width = Math.max(100, ((ww - adjust)/n) - 2*sm) this.page_width = col_width + 2*sm this.screen_width = this.page_width * this.cols_per_screen + this.current_page_height = window.innerHeight - this.margin_top - this.margin_bottom fgcolor = body_style.getPropertyValue('color') @@ -167,9 +169,15 @@ class PagedDisplay # that this method use getBoundingClientRect() which means it will # force a relayout if the render tree is dirty. images = [] + vimages = [] + maxh = this.current_page_height for img in document.getElementsByTagName('img') previously_limited = calibre_utils.retrieve(img, 'width-limited', false) + data = calibre_utils.retrieve(img, 'img-data', null) br = img.getBoundingClientRect() + if data == null + data = {'left':br.left, 'right':br.right, 'height':br.height, 'display': img.style.display} + calibre_utils.store(img, 'img-data', data) left = calibre_utils.viewport_to_document(br.left, 0, doc=img.ownerDocument)[0] col = this.column_at(left) * this.page_width rleft = left - col - this.current_margin_side @@ -178,11 +186,29 @@ class PagedDisplay col_width = this.page_width - 2*this.current_margin_side if previously_limited or rright > col_width images.push([img, col_width - rleft]) + previously_limited = calibre_utils.retrieve(img, 'height-limited', false) + if previously_limited or br.height > maxh + vimages.push(img) + if previously_limited + img.style.setProperty('-webkit-column-break-before', 'auto') + img.style.setProperty('display', data.display) + img.style.setProperty('-webkit-column-break-inside', 'avoid') for [img, max_width] in images img.style.setProperty('max-width', max_width+'px') calibre_utils.store(img, 'width-limited', true) + for img in vimages + data = calibre_utils.retrieve(img, 'img-data', null) + img.style.setProperty('-webkit-column-break-before', 'always') + img.style.setProperty('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 + # by keeping it part of its parent block + img.style.setProperty('display', 'block') + calibre_utils.store(img, 'height-limited', true) + check_top_margin: () -> # This is needed to handle the case when a descendant of body specifies # a top margin as a percentage, which messes up the top margin