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

Tabify src

This commit is contained in:
Fred Chasen 2016-10-24 15:15:16 +02:00
parent f6247e5612
commit 32993dc58c
31 changed files with 7759 additions and 7758 deletions

View file

@ -2,120 +2,120 @@ var core = require('./core');
var RSVP = require('rsvp');
function Layout(settings){
this.name = settings.layout || "reflowable";
this._spread = (settings.spread === "none") ? false : true;
this._minSpreadWidth = settings.spread || 800;
this._evenSpreads = settings.evenSpreads || false;
this.name = settings.layout || "reflowable";
this._spread = (settings.spread === "none") ? false : true;
this._minSpreadWidth = settings.spread || 800;
this._evenSpreads = settings.evenSpreads || false;
if (settings.flow === "scrolled-continuous" ||
settings.flow === "scrolled-doc") {
this._flow = "scrolled";
} else {
this._flow = "paginated";
}
if (settings.flow === "scrolled-continuous" ||
settings.flow === "scrolled-doc") {
this._flow = "scrolled";
} else {
this._flow = "paginated";
}
this.width = 0;
this.height = 0;
this.spreadWidth = 0;
this.delta = 0;
this.width = 0;
this.height = 0;
this.spreadWidth = 0;
this.delta = 0;
this.columnWidth = 0;
this.gap = 0;
this.divisor = 1;
this.columnWidth = 0;
this.gap = 0;
this.divisor = 1;
};
// paginated | scrolled
Layout.prototype.flow = function(flow) {
this._flow = (flow === "paginated") ? "paginated" : "scrolled";
this._flow = (flow === "paginated") ? "paginated" : "scrolled";
}
// true | false
Layout.prototype.spread = function(spread, min) {
this._spread = (spread === "none") ? false : true;
this._spread = (spread === "none") ? false : true;
if (min >= 0) {
this._minSpreadWidth = min;
}
if (min >= 0) {
this._minSpreadWidth = min;
}
}
Layout.prototype.calculate = function(_width, _height, _gap){
var divisor = 1;
var gap = _gap || 0;
var divisor = 1;
var gap = _gap || 0;
//-- Check the width and create even width columns
var fullWidth = Math.floor(_width);
var width = _width;
//-- Check the width and create even width columns
var fullWidth = Math.floor(_width);
var width = _width;
var section = Math.floor(width / 8);
var section = Math.floor(width / 8);
var colWidth;
var spreadWidth;
var delta;
var colWidth;
var spreadWidth;
var delta;
if (this._spread && width >= this._minSpreadWidth) {
divisor = 2;
} else {
divisor = 1;
}
if (this._spread && width >= this._minSpreadWidth) {
divisor = 2;
} else {
divisor = 1;
}
if (this.name === "reflowable" && this._flow === "paginated" && !(_gap >= 0)) {
gap = ((section % 2 === 0) ? section : section - 1);
}
if (this.name === "reflowable" && this._flow === "paginated" && !(_gap >= 0)) {
gap = ((section % 2 === 0) ? section : section - 1);
}
if (this.name === "pre-paginated" ) {
gap = 0;
}
if (this.name === "pre-paginated" ) {
gap = 0;
}
//-- Double Page
if(divisor > 1) {
colWidth = Math.floor((width - gap) / divisor);
} else {
colWidth = width;
}
//-- Double Page
if(divisor > 1) {
colWidth = Math.floor((width - gap) / divisor);
} else {
colWidth = width;
}
if (this.name === "pre-paginated" && divisor > 1) {
width = colWidth;
}
if (this.name === "pre-paginated" && divisor > 1) {
width = colWidth;
}
spreadWidth = colWidth * divisor;
spreadWidth = colWidth * divisor;
delta = (colWidth + gap) * divisor;
delta = (colWidth + gap) * divisor;
this.width = width;
this.height = _height;
this.spreadWidth = spreadWidth;
this.delta = delta;
this.width = width;
this.height = _height;
this.spreadWidth = spreadWidth;
this.delta = delta;
this.columnWidth = colWidth;
this.gap = gap;
this.divisor = divisor;
this.columnWidth = colWidth;
this.gap = gap;
this.divisor = divisor;
};
Layout.prototype.format = function(contents){
var formating;
var formating;
if (this.name === "pre-paginated") {
formating = contents.fit(this.columnWidth, this.height);
} else if (this._flow === "paginated") {
formating = contents.columns(this.width, this.height, this.columnWidth, this.gap);
} else { // scrolled
formating = contents.size(this.width, null);
}
if (this.name === "pre-paginated") {
formating = contents.fit(this.columnWidth, this.height);
} else if (this._flow === "paginated") {
formating = contents.columns(this.width, this.height, this.columnWidth, this.gap);
} else { // scrolled
formating = contents.size(this.width, null);
}
return formating; // might be a promise in some View Managers
return formating; // might be a promise in some View Managers
};
Layout.prototype.count = function(totalWidth) {
// var totalWidth = contents.scrollWidth();
var spreads = Math.ceil( totalWidth / this.spreadWidth);
// var totalWidth = contents.scrollWidth();
var spreads = Math.ceil( totalWidth / this.spreadWidth);
return {
spreads : spreads,
pages : spreads * this.divisor
};
return {
spreads : spreads,
pages : spreads * this.divisor
};
};
module.exports = Layout;