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

Add RTL support

This commit is contained in:
Fred Chasen 2017-10-16 17:24:45 -07:00
parent 8999feb613
commit 9b6e864ae4
10 changed files with 380 additions and 111 deletions

View file

@ -4,7 +4,7 @@ import Hook from "./utils/hook";
import EpubCFI from "./epubcfi";
import Queue from "./utils/queue";
import Layout from "./layout";
import Mapping from "./mapping";
// import Mapping from "./mapping";
import Themes from "./themes";
import Contents from "./contents";
import Annotations from "./annotations";
@ -164,6 +164,8 @@ class Rendition {
});
}
this.direction(this.book.package.metadata.direction);
// Parse metadata to get layout props
this.settings.globalLayoutProperties = this.determineLayoutProperties(this.book.package.metadata);
@ -248,9 +250,9 @@ class Rendition {
this.displaying = displaying;
// Check if this is a book percentage
if (this.book.locations.length &&
if (this.book.locations.length() &&
(isFloat(target) ||
(typeof target === "string" && target == parseFloat(target))) // Handle 1.0
(target === "1.0")) // Handle 1.0
) {
target = this.book.locations.cfiFromPercentage(parseFloat(target));
}
@ -426,7 +428,8 @@ class Rendition {
var viewport = metadata.viewport || "";
var minSpreadWidth = this.settings.minSpreadWidth || metadata.minSpreadWidth || 800;
if (this.settings.width >= 0 && this.settings.height >= 0) {
if ((this.settings.width === 0 || this.settings.width > 0) &&
(this.settings.height === 0 || this.settings.height > 0)) {
viewport = "width="+this.settings.width+", height="+this.settings.height+"";
}
@ -481,7 +484,7 @@ class Rendition {
this.manager.updateFlow(_flow);
}
if (this.location) {
if (this.manager && this.manager.isRendered() && this.location) {
this.manager.clear();
this.display(this.location.start.cfi);
}
@ -496,7 +499,7 @@ class Rendition {
this._layout = new Layout(settings);
this._layout.spread(settings.spread, this.settings.minSpreadWidth);
this.mapping = new Mapping(this._layout.props);
// this.mapping = new Mapping(this._layout.props);
}
if (this.manager && this._layout) {
@ -520,6 +523,25 @@ class Rendition {
}
}
/**
* Adjust the flow of the rendition to paginated or scrolled
* (scrolled-continuous vs scrolled-doc are handled by different view managers)
* @param {string} flow
*/
direction(dir){
this.settings.direction = dir || "ltr";
if (this.manager) {
this.manager.direction(this.settings.direction);
}
if (this.manager && this.manager.isRendered() && this.location) {
this.manager.clear();
this.display(this.location.start.cfi);
}
}
/**
* Report the current location
* @private