mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-03 14:59:18 +02:00
Fixes for page counting
This commit is contained in:
parent
8bfed1593c
commit
03e7ca085c
5 changed files with 28 additions and 24 deletions
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "epubjs",
|
"name": "epubjs",
|
||||||
"version": "0.3.44",
|
"version": "0.3.45",
|
||||||
"description": "Parse and Render Epubs",
|
"description": "Parse and Render Epubs",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"module": "src/index.js",
|
"module": "src/index.js",
|
||||||
|
|
|
@ -105,6 +105,7 @@ class Layout {
|
||||||
|
|
||||||
var colWidth;
|
var colWidth;
|
||||||
var spreadWidth;
|
var spreadWidth;
|
||||||
|
var pageWidth;
|
||||||
var delta;
|
var delta;
|
||||||
|
|
||||||
if (this._spread && width >= this._minSpreadWidth) {
|
if (this._spread && width >= this._minSpreadWidth) {
|
||||||
|
@ -135,14 +136,15 @@ class Layout {
|
||||||
width = colWidth;
|
width = colWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
spreadWidth = colWidth * divisor;
|
spreadWidth = (colWidth * divisor) + gap;
|
||||||
|
pageWidth = colWidth + (gap / 2);
|
||||||
|
|
||||||
delta = width;
|
delta = width;
|
||||||
// console.log(delta, width);
|
|
||||||
|
|
||||||
this.width = width;
|
this.width = width;
|
||||||
this.height = _height;
|
this.height = _height;
|
||||||
this.spreadWidth = spreadWidth;
|
this.spreadWidth = spreadWidth;
|
||||||
|
this.pageWidth = pageWidth;
|
||||||
this.delta = delta;
|
this.delta = delta;
|
||||||
|
|
||||||
this.columnWidth = colWidth;
|
this.columnWidth = colWidth;
|
||||||
|
@ -152,6 +154,7 @@ class Layout {
|
||||||
this.props.width = width;
|
this.props.width = width;
|
||||||
this.props.height = _height;
|
this.props.height = _height;
|
||||||
this.props.spreadWidth = spreadWidth;
|
this.props.spreadWidth = spreadWidth;
|
||||||
|
this.props.pageWidth = pageWidth;
|
||||||
this.props.delta = delta;
|
this.props.delta = delta;
|
||||||
|
|
||||||
this.props.columnWidth = colWidth;
|
this.props.columnWidth = colWidth;
|
||||||
|
|
|
@ -547,6 +547,7 @@ class DefaultViewManager {
|
||||||
var container = this.container.getBoundingClientRect();
|
var container = this.container.getBoundingClientRect();
|
||||||
|
|
||||||
var left = 0;
|
var left = 0;
|
||||||
|
let used = 0;
|
||||||
|
|
||||||
if(this.fullsize) {
|
if(this.fullsize) {
|
||||||
left = window.scrollX;
|
left = window.scrollX;
|
||||||
|
@ -558,26 +559,30 @@ class DefaultViewManager {
|
||||||
let position = view.position().left;
|
let position = view.position().left;
|
||||||
let width = view.width();
|
let width = view.width();
|
||||||
|
|
||||||
let startPos = left + offset;
|
// Find mapping
|
||||||
let endPos = startPos + this.layout.spreadWidth + this.layout.gap;
|
let start = left + container.left - position + used;
|
||||||
if (endPos > left + offset + width) {
|
let end = start + this.layout.spreadWidth - used;
|
||||||
endPos = left + offset + width;
|
|
||||||
|
let mapping = this.mapping.page(view.contents, view.section.cfiBase, start, end);
|
||||||
|
|
||||||
|
// Find displayed pages
|
||||||
|
let startPos = left + used;
|
||||||
|
let endPos = startPos + this.layout.spreadWidth - used;
|
||||||
|
if (endPos > offset + width) {
|
||||||
|
endPos = offset + width;
|
||||||
|
used = this.layout.pageWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
let totalPages = this.layout.count(width).pages;
|
let totalPages = this.layout.count(width).pages;
|
||||||
let currPage = Math.ceil((startPos - offset) / this.layout.spreadWidth);
|
let currPage = Math.floor((startPos - offset) / this.layout.pageWidth);
|
||||||
let pages = [];
|
let pages = [];
|
||||||
let numPages = (endPos - startPos) / (this.layout.columnWidth + (this.layout.gap / 2));
|
let numPages = Math.floor((endPos - startPos) / this.layout.pageWidth);
|
||||||
|
|
||||||
for (var i = 1; i <= numPages; i++) {
|
for (var i = 1; i <= numPages; i++) {
|
||||||
let pg = currPage + i;
|
let pg = currPage + i;
|
||||||
pages.push(pg);
|
pages.push(pg);
|
||||||
}
|
}
|
||||||
|
|
||||||
let start = left + container.left - position;
|
|
||||||
let end = start + this.layout.spreadWidth + this.layout.gap;
|
|
||||||
|
|
||||||
let mapping = this.mapping.page(view.contents, view.section.cfiBase, start, end);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
index,
|
index,
|
||||||
href,
|
href,
|
||||||
|
|
|
@ -253,11 +253,12 @@ class IframeView {
|
||||||
// Get the contentWidth by resizing the iframe
|
// Get the contentWidth by resizing the iframe
|
||||||
// Check with a min reset of the textWidth
|
// Check with a min reset of the textWidth
|
||||||
|
|
||||||
// width = this.contentWidth(textWidth);
|
// Add padding back
|
||||||
|
if (width % this.layout.width > 0) {
|
||||||
|
width += this.layout.gap / 2;
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
columns = Math.ceil(width / (this.settings.layout.columnWidth));
|
columns = Math.ceil(width / this.settings.layout.delta);
|
||||||
|
|
||||||
if ( this.settings.layout.divisor > 1 &&
|
if ( this.settings.layout.divisor > 1 &&
|
||||||
this.settings.layout.name === "reflowable" &&
|
this.settings.layout.name === "reflowable" &&
|
||||||
(columns % 2 > 0)) {
|
(columns % 2 > 0)) {
|
||||||
|
@ -266,11 +267,6 @@ class IframeView {
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Add padding back
|
|
||||||
if (width % this.layout.width > 0) {
|
|
||||||
width += this.layout.gap / 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save the textWdith
|
// Save the textWdith
|
||||||
this._textWidth = textWidth;
|
this._textWidth = textWidth;
|
||||||
|
|
||||||
|
|
|
@ -620,7 +620,7 @@ class Rendition {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (end.index === this.book.spine.last().index &&
|
if (end.index === this.book.spine.last().index &&
|
||||||
located.end.displayed.page === located.end.displayed.totalPages) {
|
located.end.displayed.page >= located.end.displayed.totalPages) {
|
||||||
located.atEnd = true;
|
located.atEnd = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue