Skip to content

Commit

Permalink
Node canvas (#4497)
Browse files Browse the repository at this point in the history
* readded

* paused

* test

* try jsdom

* restore node methods

* restored

* restored

* fix tests
  • Loading branch information
asturur authored Nov 24, 2017
1 parent a9eacc4 commit 71b36f6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions HEADER.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ else {
FetchExternalResources: ['img']
}
});
fabric.jsdomImplForWrapper = require('jsdom/lib/jsdom/living/generated/utils').implForWrapper;
fabric.window = fabric.document.defaultView;
DOMParser = require('xmldom').DOMParser;
}
Expand Down
10 changes: 10 additions & 0 deletions src/static_canvas.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -1759,4 +1759,14 @@
*/
fabric.StaticCanvas.prototype.toJSON = fabric.StaticCanvas.prototype.toObject;

if (fabric.isLikelyNode) {
fabric.StaticCanvas.prototype.createPNGStream = function() {
var impl = fabric.jsdomImplForWrapper(this.lowerCanvasEl);
return impl && impl.createPNGStream();
};
fabric.StaticCanvas.prototype.createJPEGStream = function(opts) {
var impl = fabric.jsdomImplForWrapper(this.lowerCanvasEl);
return impl && impl.createJPEGStream(opts);
};
}
})();
18 changes: 18 additions & 0 deletions test/unit/canvas_static.js
Original file line number Diff line number Diff line change
Expand Up @@ -1572,6 +1572,24 @@
});
});

QUnit.test('createPNGStream', function(assert) {
if (!fabric.isLikelyNode) {
assert.ok(true, 'not supposed to run outside node');
}
else {
assert.ok(typeof canvas.createPNGStream === 'function', 'there is a createPNGStream method');
}
});

QUnit.test('createJPEGStream', function(assert) {
if (!fabric.isLikelyNode) {
assert.ok(true, 'not supposed to run outside node');
}
else {
assert.ok(typeof canvas.createJPEGStream === 'function', 'there is a createJPEGStream method');
}
});

// QUnit.test('backgroundImage', function(assert) {
// var done = assert.async();
// assert.deepEqual('', canvas.backgroundImage);
Expand Down

0 comments on commit 71b36f6

Please sign in to comment.