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, top = itemRect.top,
oHeight = item.getAttribute('data-height'), oHeight = item.getAttribute('data-height'),
height = oHeight || rectHeight, height = oHeight || rectHeight,
newHeight; newHeight,
fontSize = Number(getComputedStyle(item, "").fontSize.match(/(\d*(\.\d*)?)px/)[1]),
fontAdjust = fontSize ? fontSize / 2 : 0;
iheight = renderer.contents.clientHeight; iheight = renderer.contents.clientHeight;
if(top < 0) top = 0; if(top < 0) top = 0;
@ -25,7 +27,8 @@ EPUBJS.Hooks.register("beforeChapterDisplay").smartimages = function(callback, r
if(height + top >= iheight) { if(height + top >= iheight) {
if(top < iheight/2) { 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.maxHeight = newHeight + "px";
item.style.width= "auto"; item.style.width= "auto";
}else{ }else{

View file

@ -27,15 +27,17 @@ EPUBJS.Layout.Reflowable = function(documentElement, _width, _height){
documentElement.style[columnGap] = gap+"px"; documentElement.style[columnGap] = gap+"px";
documentElement.style[columnWidth] = width+"px"; documentElement.style[columnWidth] = width+"px";
totalWidth = documentElement.scrollWidth;
displayedPages = Math.ceil(totalWidth / spreadWidth);
documentElement.style.width = width + "px"; documentElement.style.width = width + "px";
totalWidth = documentElement.scrollWidth;
displayedPages = Math.round(totalWidth / spreadWidth);
return { return {
pageWidth : spreadWidth, pageWidth : spreadWidth,
pageHeight : _height, pageHeight : _height,
displayedPages : displayedPages displayedPages : displayedPages,
pageCount : displayedPages
}; };
}; };
@ -65,7 +67,7 @@ EPUBJS.Layout.ReflowableSpreads = function(documentElement, _width, _height){
documentElement.style.width = width + "px"; documentElement.style.width = width + "px";
//-- Adjust height //-- Adjust height
documentElement.style.height = _height + "px"; documentElement.style.height = _height + "px";
//-- Add columns //-- Add columns
documentElement.style[columnAxis] = "horizontal"; documentElement.style[columnAxis] = "horizontal";
@ -81,7 +83,8 @@ EPUBJS.Layout.ReflowableSpreads = function(documentElement, _width, _height){
return { return {
pageWidth : spreadWidth, pageWidth : spreadWidth,
pageHeight : _height, pageHeight : _height,
displayedPages : displayedPages displayedPages : displayedPages,
pageCount : displayedPages * 2
}; };
}; };
@ -121,7 +124,8 @@ EPUBJS.Layout.Fixed = function(documentElement, _width, _height){
return { return {
pageWidth : width, pageWidth : width,
pageHeight : height, 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); render.window.addEventListener("resize", render.resized.bind(render), false);
//-- Clear Margins //-- Clear Margins
if(render.bodyEl) render.bodyEl.style.margin = "0"; if(render.bodyEl) {
render.bodyEl.style.margin = "0";
}
deferred.resolve(render.docEl); deferred.resolve(render.docEl);
}; };

View file

@ -477,6 +477,7 @@ EPUBJS.Renderer.prototype.onResized = function(e){
this.height = this.container.clientHeight; this.height = this.container.clientHeight;
spreads = this.determineSpreads(this.minSpreadWidth); spreads = this.determineSpreads(this.minSpreadWidth);
// Only re-layout if the spreads have switched
if(spreads != this.spreads){ if(spreads != this.spreads){
this.spreads = spreads; this.spreads = spreads;
this.layoutMethod = this.determineLayout(this.settings); this.layoutMethod = this.determineLayout(this.settings);