diff --git a/hooks/default/smartimages.js b/hooks/default/smartimages.js index 9e16682..4a66070 100644 --- a/hooks/default/smartimages.js +++ b/hooks/default/smartimages.js @@ -17,15 +17,18 @@ EPUBJS.Hooks.register("beforeChapterDisplay").smartimages = function(callback, r top = itemRect.top, oHeight = item.getAttribute('data-height'), height = oHeight || rectHeight, - newHeight; - + newHeight, + fontSize = Number(getComputedStyle(item, "").fontSize.match(/(\d*(\.\d*)?)px/)[1]), + fontAdjust = fontSize ? fontSize / 2 : 0; + iheight = renderer.contents.clientHeight; if(top < 0) top = 0; if(height + top >= iheight) { if(top < iheight/2) { - newHeight = iheight - top; + // Remove top and half font-size from height to keep container from overflowing + newHeight = iheight - top - fontAdjust; item.style.maxHeight = newHeight + "px"; item.style.width= "auto"; }else{ diff --git a/src/layout.js b/src/layout.js index 4cbc7f4..d81e4bd 100644 --- a/src/layout.js +++ b/src/layout.js @@ -27,15 +27,17 @@ EPUBJS.Layout.Reflowable = function(documentElement, _width, _height){ documentElement.style[columnGap] = gap+"px"; documentElement.style[columnWidth] = width+"px"; - totalWidth = documentElement.scrollWidth; - displayedPages = Math.ceil(totalWidth / spreadWidth); - documentElement.style.width = width + "px"; + + + totalWidth = documentElement.scrollWidth; + displayedPages = Math.round(totalWidth / spreadWidth); return { pageWidth : spreadWidth, pageHeight : _height, - displayedPages : displayedPages + displayedPages : displayedPages, + pageCount : displayedPages }; }; @@ -65,7 +67,7 @@ EPUBJS.Layout.ReflowableSpreads = function(documentElement, _width, _height){ documentElement.style.width = width + "px"; //-- Adjust height - documentElement.style.height = _height + "px"; + documentElement.style.height = _height + "px"; //-- Add columns documentElement.style[columnAxis] = "horizontal"; @@ -81,7 +83,8 @@ EPUBJS.Layout.ReflowableSpreads = function(documentElement, _width, _height){ return { pageWidth : spreadWidth, pageHeight : _height, - displayedPages : displayedPages + displayedPages : displayedPages, + pageCount : displayedPages * 2 }; }; @@ -121,7 +124,8 @@ EPUBJS.Layout.Fixed = function(documentElement, _width, _height){ return { pageWidth : width, pageHeight : height, - displayedPages : 1 + displayedPages : 1, + pageCount : 1 }; }; \ No newline at end of file diff --git a/src/render_iframe.js b/src/render_iframe.js index f0a39c9..1d062e3 100644 --- a/src/render_iframe.js +++ b/src/render_iframe.js @@ -45,8 +45,9 @@ EPUBJS.Render.Iframe.prototype.load = function(url){ render.window.addEventListener("resize", render.resized.bind(render), false); //-- Clear Margins - if(render.bodyEl) render.bodyEl.style.margin = "0"; - + if(render.bodyEl) { + render.bodyEl.style.margin = "0"; + } deferred.resolve(render.docEl); }; diff --git a/src/renderer.js b/src/renderer.js index fabb0d8..1ba1cf1 100644 --- a/src/renderer.js +++ b/src/renderer.js @@ -477,6 +477,7 @@ EPUBJS.Renderer.prototype.onResized = function(e){ this.height = this.container.clientHeight; spreads = this.determineSpreads(this.minSpreadWidth); + // Only re-layout if the spreads have switched if(spreads != this.spreads){ this.spreads = spreads; this.layoutMethod = this.determineLayout(this.settings);