From e6d46b593babd445d513a2a5b13b5ba0af7ed071 Mon Sep 17 00:00:00 2001 From: Bala Clark Date: Thu, 16 Jul 2015 10:29:33 +0200 Subject: [PATCH] starting canvas module --- app/comic-book.js | 4 +++- app/view/canvas.js | 28 ++++++++++++++++++++++++++++ test/comic-book.test.js | 3 +++ test/view/canvas.test.js | 32 ++++++++++++++++++++++++++++++++ test/view/load-indicator.test.js | 2 +- 5 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 app/view/canvas.js create mode 100644 test/view/canvas.test.js diff --git a/app/comic-book.js b/app/comic-book.js index 977af1d..6ac9aca 100644 --- a/app/comic-book.js +++ b/app/comic-book.js @@ -1,7 +1,7 @@ let EventEmitter = require('events').EventEmitter let LoadIndicator = require('./view/load-indicator') -module.exports = class ComicBook extends EventEmitter { +class ComicBook extends EventEmitter { constructor (srcs = []) { super() @@ -45,3 +45,5 @@ module.exports = class ComicBook extends EventEmitter { } +module.exports = ComicBook + diff --git a/app/view/canvas.js b/app/view/canvas.js new file mode 100644 index 0000000..8296b42 --- /dev/null +++ b/app/view/canvas.js @@ -0,0 +1,28 @@ +let EventEmitter = require('events').EventEmitter + +class Canvas extends EventEmitter { + + constructor (options) { + super() + + this.options = Object.assign({ + // fitWidth, fitWindow, manua + zoomMode: 'fitWidth', + // ltr, rtl + readDirection: 'ltr' + }, options) + + this.canvas = document.createElement('canvas') + this.context = this.canvas.getContext('2d') + } + + draw (image, doublePage, image2) { + if (!(image instanceof window.Image) || (doublePage && !(image2 instanceof window.Image))) { + throw new Error('Invalid image') + } + + this.emit('draw') + } +} + +module.exports = Canvas diff --git a/test/comic-book.test.js b/test/comic-book.test.js index e850dd0..8fb285a 100644 --- a/test/comic-book.test.js +++ b/test/comic-book.test.js @@ -48,5 +48,8 @@ describe('ComicBook', function () { comic.loadIndicator.on('show', () => done()) comic.preload() }) + + it('should scroll to the top of the page on page turn') + }) }) diff --git a/test/view/canvas.test.js b/test/view/canvas.test.js new file mode 100644 index 0000000..8dc83e3 --- /dev/null +++ b/test/view/canvas.test.js @@ -0,0 +1,32 @@ +let assert = require('assert') +let Canvas = require('../../app/view/canvas') + +describe('Canvas', function () { + + it('should draw only Image objects', function () { + let canvas = new Canvas() + let image = new window.Image() + + assert.throws(canvas.draw, 'Invalid image') + assert.throws(canvas.draw.bind(canvas, image, true), 'Invalid image') + assert.doesNotThrow(canvas.draw.bind(canvas, image, true, image), 'Invalid image') + }) + + it('should draw a single page') + + it('should draw a double page') + + it('should draw a manga double page') + + it('should draw a single double page spread') + + it('should show a blank last page if the last double page only has one image') + + it('should auto-fit to window width') + + it('should auto-fit to window height') + + it('should manual zoom') + + it('should always center pages') +}) diff --git a/test/view/load-indicator.test.js b/test/view/load-indicator.test.js index 0323510..001c19f 100644 --- a/test/view/load-indicator.test.js +++ b/test/view/load-indicator.test.js @@ -1,7 +1,7 @@ let assert = require('assert') let LoadIndicator = require('../../app/view/load-indicator') -describe('#loadIndicator()', function () { +describe('LoadIndicator', function () { it('should render on init', function () { let indicator = new LoadIndicator()