@@ -14,9 +14,11 @@ import Archive from "./archive";
14
14
import request from "./utils/request" ;
15
15
import EpubCFI from "./epubcfi" ;
16
16
import Store from "./store" ;
17
+ import DisplayOptions from "./displayoptions" ;
17
18
import { EPUBJS_VERSION , EVENTS } from "./utils/constants" ;
18
19
19
20
const CONTAINER_PATH = "META-INF/container.xml" ;
21
+ const IBOOKS_DISPLAY_OPTIONS_PATH = "META-INF/com.apple.ibooks.display-options.xml" ;
20
22
21
23
const INPUT_TYPE = {
22
24
BINARY : "binary" ,
@@ -85,7 +87,8 @@ class Book {
85
87
cover : new defer ( ) ,
86
88
navigation : new defer ( ) ,
87
89
pageList : new defer ( ) ,
88
- resources : new defer ( )
90
+ resources : new defer ( ) ,
91
+ displayOptions : new defer ( )
89
92
} ;
90
93
91
94
this . loaded = {
@@ -95,7 +98,8 @@ class Book {
95
98
cover : this . loading . cover . promise ,
96
99
navigation : this . loading . navigation . promise ,
97
100
pageList : this . loading . pageList . promise ,
98
- resources : this . loading . resources . promise
101
+ resources : this . loading . resources . promise ,
102
+ displayOptions : this . loading . displayOptions . promise
99
103
} ;
100
104
101
105
/**
@@ -109,7 +113,8 @@ class Book {
109
113
this . loaded . metadata ,
110
114
this . loaded . cover ,
111
115
this . loaded . navigation ,
112
- this . loaded . resources
116
+ this . loaded . resources ,
117
+ this . loaded . displayOptions
113
118
] ) ;
114
119
115
120
@@ -211,6 +216,13 @@ class Book {
211
216
*/
212
217
this . packaging = undefined ;
213
218
219
+ /**
220
+ * @member {DisplayOptions} displayOptions
221
+ * @memberof DisplayOptions
222
+ * @private
223
+ */
224
+ this . displayOptions = undefined ;
225
+
214
226
// this.toc = undefined;
215
227
if ( this . settings . store ) {
216
228
this . store ( this . settings . store ) ;
@@ -437,6 +449,20 @@ class Book {
437
449
unpack ( packaging ) {
438
450
this . package = packaging ; //TODO: deprecated this
439
451
452
+ if ( this . packaging . metadata . layout === "" ) {
453
+ // rendition:layout not set - check display options if book is pre-paginated
454
+ this . load ( this . url . resolve ( IBOOKS_DISPLAY_OPTIONS_PATH ) ) . then ( ( xml ) => {
455
+ this . displayOptions = new DisplayOptions ( xml ) ;
456
+ this . loading . displayOptions . resolve ( this . displayOptions ) ;
457
+ } ) . catch ( ( err ) => {
458
+ this . displayOptions = new DisplayOptions ( ) ;
459
+ this . loading . displayOptions . resolve ( this . displayOptions ) ;
460
+ } ) ;
461
+ } else {
462
+ this . displayOptions = new DisplayOptions ( ) ;
463
+ this . loading . displayOptions . resolve ( this . displayOptions ) ;
464
+ }
465
+
440
466
this . spine . unpack ( this . packaging , this . resolve . bind ( this ) , this . canonical . bind ( this ) ) ;
441
467
442
468
this . resources = new Resources ( this . packaging . manifest , {
@@ -466,14 +492,18 @@ class Book {
466
492
467
493
if ( this . archived || this . settings . replacements && this . settings . replacements != "none" ) {
468
494
this . replacements ( ) . then ( ( ) => {
469
- this . opening . resolve ( this ) ;
495
+ this . loaded . displayOptions . then ( ( ) => {
496
+ this . opening . resolve ( this ) ;
497
+ } ) ;
470
498
} )
471
499
. catch ( ( err ) => {
472
500
console . error ( err ) ;
473
501
} ) ;
474
502
} else {
475
503
// Resolve book opened promise
476
- this . opening . resolve ( this ) ;
504
+ this . loaded . displayOptions . then ( ( ) => {
505
+ this . opening . resolve ( this ) ;
506
+ } ) ;
477
507
}
478
508
479
509
}
@@ -707,6 +737,7 @@ class Book {
707
737
this . container && this . container . destroy ( ) ;
708
738
this . packaging && this . packaging . destroy ( ) ;
709
739
this . rendition && this . rendition . destroy ( ) ;
740
+ this . displayOptions && this . displayOptions . destroy ( ) ;
710
741
711
742
this . spine = undefined ;
712
743
this . locations = undefined ;
0 commit comments