From 24d84289ff97c24e03474d93a0255d53e8285a87 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 22 Jun 2012 10:06:07 +0530 Subject: [PATCH] Paged mode: Better handling of cover pages --- resources/compiled_coffeescript.zip | Bin 39253 -> 40626 bytes src/calibre/ebooks/oeb/display/paged.coffee | 21 +++++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/resources/compiled_coffeescript.zip b/resources/compiled_coffeescript.zip index 094c46a3729060edbfcf7b6b55308e5abaa0b0f4..c9fac5fa81c1bdb2cd348b7e5f0d4b552d536e3d 100644 GIT binary patch delta 1337 zcmbVM&r2IY6gH_9)F%FjKdRCA^q?CP7gs8Zy0!?GLTQO0NGWCAx|7YoW;g6ijG?9; zJ@n>WETxn}Z-s&`lwJgT>mSheUV1D&6nbxG%*G@XTkXKY?A!N!@0<6%oll3s!=qp{ zb^B6dSA$qbsn0i9^7WUz($FBDDAQ(p4wSa$WrCO6{E z0(pWApbl7i(aBSwXo~{2d4|d3S;s)$RP(by0yqv6851p?w=9ipxCq&r4^knmTLjIw z0AD4x(m%+)wd@6zdA5>>czdls19BR>g!=hO$mm2Pn`RQSx@%%vqfRafb`l)hDrz`u zvfU6|!M153zY=>Dy3gLWEkF$o)RhImX^@85i;)=n6`Ek<;iWLt@Po=ec1V3?jY21> z<>z0O#%^}p-xOVd0=5mOAYQnL4v zsMp(h^DK$=bzWzG9Qf2C3 zd%Mz@xTsb?A!Yl;i1aR2wF~>?4GZ(Ot+CWVm-nFeYe2Mq?(CYiM)iA64o zIjQw{DEc3`B~}<{XHR0+ysN`&g>e1F$4dM6f^QVIKHJT{?@tF`s(c$|*PpgG9X}WM FqSQY&P=> zZD(XvPb@9TpR6w?!&Q`?nWtNlU!bltc|E_zlDnHz_KB7}k>mlrMq>W~fLrZvLivt(*_lxsz|rjbsYc0l9eceM9ca Tq4TtuTr7ZGZMNhYAm0H1Cg4z@ diff --git a/src/calibre/ebooks/oeb/display/paged.coffee b/src/calibre/ebooks/oeb/display/paged.coffee index 634c1d6142..142fb5f887 100644 --- a/src/calibre/ebooks/oeb/display/paged.coffee +++ b/src/calibre/ebooks/oeb/display/paged.coffee @@ -69,7 +69,7 @@ class PagedDisplay this.current_margin_side = 0 this.is_full_screen_layout = false - set_geometry: (cols_per_screen=2, margin_top=20, margin_side=40, margin_bottom=20) -> + set_geometry: (cols_per_screen=1, margin_top=20, margin_side=40, margin_bottom=20) -> this.margin_top = margin_top this.margin_side = margin_side this.margin_bottom = margin_bottom @@ -82,13 +82,15 @@ class PagedDisplay # margin for the page. We compensate for that here. Computing the # boundingrect of body is very expensive with column layout, so we do # it before the column layout is applied. + first_layout = false if not this.in_paged_mode document.body.style.marginTop = '0px' extra_margin = document.body.getBoundingClientRect().top margin_top = (this.margin_top - extra_margin) + 'px' - # Check if the current document is a full screen layout like an - # epub cover, if so we treat it specially. - this.is_full_screen_layout = (document.body.scrollWidth < window.innerWidth + 25 and document.body.scrollHeight < window.innerHeight + 25) + # Check if the current document is a full screen layout like + # cover, if so we treat it specially. + single_screen = (document.body.scrollWidth < window.innerWidth + 25 and document.body.scrollHeight < window.innerHeight + 25) + first_layout = true else # resize event margin_top = body_style.marginTop @@ -119,7 +121,7 @@ class PagedDisplay bs.setProperty('-webkit-column-rule-color', fgcolor) bs.setProperty('overflow', 'visible') bs.setProperty('height', (window.innerHeight - this.margin_top - this.margin_bottom) + 'px') - bs.setProperty('width', 'auto') + bs.setProperty('width', (window.innerWidth - 2*sm)+'px') bs.setProperty('margin-top', margin_top) bs.setProperty('margin-bottom', this.margin_bottom+'px') bs.setProperty('margin-left', sm+'px') @@ -143,6 +145,15 @@ class PagedDisplay priority = rule.style.getPropertyPriority(prop) rule.style.setProperty(cprop, val, priority) + if first_layout + # Because of a bug in webkit column mode, svg elements defined with + # width 100% are wider than body and lead to a blank page after the + # current page (when cols_per_screen == 1). Similarly img elements + # with height=100% overflow the first column + has_svg = document.getElementsByTagName('svg').length > 0 + only_img = document.getElementsByTagName('img').length == 1 and document.getElementsByTagName('div').length < 2 and document.getElementsByTagName('p').length < 2 + this.is_full_screen_layout = (only_img or has_svg) and single_screen and document.body.scrollWidth > document.body.clientWidth + this.in_paged_mode = true this.current_margin_side = sm return sm