allow the last page in double page mode to be blank

This commit is contained in:
Bala Clark 2015-07-20 22:54:45 +02:00
parent 226a772452
commit 108e696d6b
6 changed files with 15 additions and 12 deletions

View file

@ -16,8 +16,8 @@ class Canvas extends EventEmitter {
drawImage (page, page2, opts = {}) { drawImage (page, page2, opts = {}) {
this.emit('draw:start') this.emit('draw:start')
if (!(page2 instanceof window.Image)) { if (page2 === null || !(page2 instanceof window.Image)) {
opts = page2 opts = page2 || opts
} }
let options = Object.assign({ let options = Object.assign({
@ -25,7 +25,7 @@ class Canvas extends EventEmitter {
zoomMode: 'fitWidth' zoomMode: 'fitWidth'
}, opts) }, opts)
if (!(page instanceof window.Image) || (options.doublePage && !(page2 instanceof window.Image))) { if (!(page instanceof window.Image) || (options.doublePage && page2 === null)) {
throw new Error('Invalid image') throw new Error('Invalid image')
} }
@ -56,7 +56,7 @@ class Canvas extends EventEmitter {
if (doublePageMode) { if (doublePageMode) {
// for double page spreads, factor in the width of both pages // for double page spreads, factor in the width of both pages
if (typeof page2 === 'object') { if (page2 instanceof window.Image) {
width += page2.width width += page2.width
// if this is the last page and there is no page2, still keep the canvas wide // if this is the last page and there is no page2, still keep the canvas wide
} else { } else {

8
dist/comicbook.js vendored
View file

@ -226,8 +226,8 @@ var Canvas = (function (_EventEmitter) {
this.emit('draw:start'); this.emit('draw:start');
if (!(page2 instanceof window.Image)) { if (page2 === null || !(page2 instanceof window.Image)) {
opts = page2; opts = page2 || opts;
} }
var options = _Object$assign({ var options = _Object$assign({
@ -235,7 +235,7 @@ var Canvas = (function (_EventEmitter) {
zoomMode: 'fitWidth' zoomMode: 'fitWidth'
}, opts); }, opts);
if (!(page instanceof window.Image) || options.doublePage && !(page2 instanceof window.Image)) { if (!(page instanceof window.Image) || options.doublePage && page2 === null) {
throw new Error('Invalid image'); throw new Error('Invalid image');
} }
@ -262,7 +262,7 @@ var Canvas = (function (_EventEmitter) {
if (doublePageMode) { if (doublePageMode) {
// for double page spreads, factor in the width of both pages // for double page spreads, factor in the width of both pages
if (typeof page2 === 'object') { if (page2 instanceof window.Image) {
width += page2.width width += page2.width
// if this is the last page and there is no page2, still keep the canvas wide // if this is the last page and there is no page2, still keep the canvas wide
; ;

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -13,6 +13,9 @@ describe('Canvas', function () {
assert.throws(canvas.drawImage, 'Invalid image') assert.throws(canvas.drawImage, 'Invalid image')
assert.throws(canvas.drawImage.bind(canvas, image, { doublePage: true }), 'Invalid image') assert.throws(canvas.drawImage.bind(canvas, image, { doublePage: true }), 'Invalid image')
assert.throws(canvas.drawImage.bind(canvas, image, null, { doublePage: true, test: 'ing' }), 'Invalid image')
assert.doesNotThrow(canvas.drawImage.bind(canvas, image, undefined, { doublePage: true }), 'Invalid image',
'Allow "undefined image 2 as the last page in double page mode could be blank"')
assert.doesNotThrow(canvas.drawImage.bind(canvas, image, image, { doublePage: true }), 'Invalid image') assert.doesNotThrow(canvas.drawImage.bind(canvas, image, image, { doublePage: true }), 'Invalid image')
}) })