Skip to content
This repository has been archived by the owner on Nov 5, 2022. It is now read-only.

Commit

Permalink
Define ctx.ellipse separately from polyfilling Path2D.
Browse files Browse the repository at this point in the history
Also use a real SVGMatrix for unit tests.
  • Loading branch information
jcgregorio committed Feb 23, 2015
1 parent 0d35de2 commit b005fee
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 29 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
21 changes: 11 additions & 10 deletions canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@
* A polyfill for HTML Canvas features, including
* Path2D support.
*/
if (CanvasRenderingContext2D.prototype.ellipse == undefined) {
CanvasRenderingContext2D.prototype.ellipse = function(x, y, radiusX, radiusY, rotation, startAngle, endAngle, antiClockwise) {
this.save();
this.translate(x, y);
this.rotate(rotation);
this.scale(radiusX, radiusY);
this.arc(0, 0, 1, startAngle, endAngle, antiClockwise);
this.restore();
}
}

if (typeof Path2D !== 'function') {
(function() {

Expand Down Expand Up @@ -2100,16 +2111,6 @@ if (typeof Path2D !== 'function') {

// TODO(jcgregorio) test for arcTo and implement via something.

if (CanvasRenderingContext2D.prototype.ellipse == undefined) {
CanvasRenderingContext2D.prototype.ellipse = function(x, y, radiusX, radiusY, rotation, startAngle, endAngle, antiClockwise) {
this.save();
this.translate(x, y);
this.rotate(rotation);
this.scale(radiusX, radiusY);
this.arc(0, 0, 1, startAngle, endAngle, antiClockwise);
this.restore();
}
}

// Path methods that map simply to the CanvasRenderingContext2D.
var simple_mapping = [
Expand Down
22 changes: 12 additions & 10 deletions canvasv5.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@
* A polyfill for HTML Canvas features, including
* Path2D support.
*/
if (CanvasRenderingContext2D.prototype.ellipse == undefined) {
CanvasRenderingContext2D.prototype.ellipse = function(x, y, radiusX, radiusY, rotation, startAngle, endAngle, antiClockwise) {
this.save();
this.translate(x, y);
this.rotate(rotation);
this.scale(radiusX, radiusY);
this.arc(0, 0, 1, startAngle, endAngle, antiClockwise);
this.restore();
}
}

if (typeof Path2D !== 'function') {
(function() {

Expand All @@ -35,16 +46,6 @@ if (typeof Path2D !== 'function') {

// TODO(jcgregorio) test for arcTo and implement via something.

if (CanvasRenderingContext2D.prototype.ellipse == undefined) {
CanvasRenderingContext2D.prototype.ellipse = function(x, y, radiusX, radiusY, rotation, startAngle, endAngle, antiClockwise) {
this.save();
this.translate(x, y);
this.rotate(rotation);
this.scale(radiusX, radiusY);
this.arc(0, 0, 1, startAngle, endAngle, antiClockwise);
this.restore();
}
}

// Path methods that map simply to the CanvasRenderingContext2D.
var simple_mapping = [
Expand Down Expand Up @@ -171,3 +172,4 @@ if (typeof Path2D !== 'function') {
Path2D = Path_;
})();
}

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "canvas-5-polyfill",
"version": "0.1.0",
"version": "0.1.1",
"description": "Polyfill for HTML 5 Canvas features.",
"main": "canvas.js",
"directories": {
Expand Down
15 changes: 7 additions & 8 deletions test/addpath.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@ describe('AddPath Test Suite.',
var toadd = new Path2D();
toadd.rect(0, 0, 100, 100);

tr = {
a: 0,
b: 1,
c: 2,
d: 3,
e: 4,
f: 5
};
var tr = document.createElementNS("http://www.w3.org/2000/svg", "svg").createSVGMatrix();
tr.a = 0;
tr.b = 1;
tr.c = 2;
tr.d = 3;
tr.e = 4;
tr.f = 5;
path.addPath(toadd, tr);
assert.equal(path.ops_.length, 4);
assert.equal(path.ops_[0].type, 'save');
Expand Down

0 comments on commit b005fee

Please sign in to comment.