1
0
Fork 0
mirror of https://github.com/futurepress/epub.js.git synced 2025-10-03 14:59:18 +02:00

adjust image that are full height to account for font size

This commit is contained in:
Fred Chasen 2014-01-22 14:29:41 -08:00
parent 70ab0e488e
commit 4ced5b9221
4 changed files with 21 additions and 12 deletions

View file

@ -17,7 +17,9 @@ 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;
@ -25,7 +27,8 @@ EPUBJS.Hooks.register("beforeChapterDisplay").smartimages = function(callback, r
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{

View file

@ -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
};
};

View file

@ -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);
};

View file

@ -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);