Skip to content

Commit

Permalink
Fix IE11/Edge17 isseu when elem has no transformations
Browse files Browse the repository at this point in the history
  • Loading branch information
MNBuyskih committed Sep 4, 2018
1 parent 0b2d86a commit c89f8f5
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 20 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ test/actual_node
test/actual_browser
test/diff_node
test/diff_browser
.vscode
.vscode
.idea
36 changes: 28 additions & 8 deletions dist/browser/canvg.js
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,14 @@
}
};

var data = svg.trim(svg.compressSpaces(v)).replace(/\)([a-zA-Z])/g, ') $1').replace(/\)(\s?,\s?)/g, ') ').split(/\s(?=[a-z])/);
var data = svg
.trim(svg.compressSpaces(v))
.replace(/\)([a-zA-Z])/g, ') $1')
.replace(/\)(\s?,\s?)/g, ') ')
.split(/\s(?=[a-z])/)
.filter(function (d) {
return d !== 'none';
});
for (var i = 0; i < data.length; i++) {
var type = svg.trim(data[i].split('(')[0]);
var s = data[i].split('(')[1].replace(')', '');
Expand Down Expand Up @@ -1033,7 +1040,7 @@
var gaps = svg.ToNumberArray(this.style('stroke-dasharray').value);
if (typeof ctx.setLineDash != 'undefined') { ctx.setLineDash(gaps); } else if (typeof ctx.webkitLineDash != 'undefined') { ctx.webkitLineDash = gaps; } else if (typeof ctx.mozDash != 'undefined' && !(gaps.length == 1 && gaps[0] == 0)) { ctx.mozDash = gaps; }

var offset = this.style('stroke-dashoffset').numValueOrDefault(1);
var offset = this.style('stroke-dashoffset').toPixels();
if (typeof ctx.lineDashOffset != 'undefined') { ctx.lineDashOffset = offset; } else if (typeof ctx.webkitLineDashOffset != 'undefined') { ctx.webkitLineDashOffset = offset; } else if (typeof ctx.mozDashOffset != 'undefined') { ctx.mozDashOffset = offset; }
}

Expand Down Expand Up @@ -1242,7 +1249,7 @@

if (ctx != null) {
ctx.beginPath();
ctx.arc(cx, cy, r, 0, Math.PI * 2, true);
ctx.arc(cx, cy, r, 0, Math.PI * 2, false);
ctx.closePath();
}

Expand All @@ -1265,11 +1272,11 @@

if (ctx != null) {
ctx.beginPath();
ctx.moveTo(cx, cy - ry);
ctx.bezierCurveTo(cx + (KAPPA * rx), cy - ry, cx + rx, cy - (KAPPA * ry), cx + rx, cy);
ctx.moveTo(cx + rx, cy);
ctx.bezierCurveTo(cx + rx, cy + (KAPPA * ry), cx + (KAPPA * rx), cy + ry, cx, cy + ry);
ctx.bezierCurveTo(cx - (KAPPA * rx), cy + ry, cx - rx, cy + (KAPPA * ry), cx - rx, cy);
ctx.bezierCurveTo(cx - rx, cy - (KAPPA * ry), cx - (KAPPA * rx), cy - ry, cx, cy - ry);
ctx.bezierCurveTo(cx + (KAPPA * rx), cy - ry, cx + rx, cy - (KAPPA * ry), cx + rx, cy);
ctx.closePath();
}

Expand Down Expand Up @@ -1681,7 +1688,12 @@
break;
case 'Z':
case 'z':
if (ctx != null) ctx.closePath();
if (ctx != null) {
// only close path if it is not a straight line
if (bb.x1 !== bb.x2 && bb.y1 !== bb.y2) {
ctx.closePath();
}
}
pp.current = pp.start;
}
}
Expand Down Expand Up @@ -2612,6 +2624,12 @@
if (element != null) element.path(ctx);
};

this.elementTransform = function () {
if (element != null && element.style('transform', false, true).hasValue()) {
return new svg.Transform(element.style('transform', false, true).value);
}
};

this.getBoundingBox = function () {
if (element != null) return element.getBoundingBox();
};
Expand Down Expand Up @@ -2715,9 +2733,11 @@
for (var i = 0; i < this.children.length; i++) {
var child = this.children[i];
if (typeof child.path != 'undefined') {
var transform = null;
if (child.style('transform', false, true).hasValue()) {
var transform = typeof child.elementTransform != 'undefined' && child.elementTransform(); // handle <use />
if (!transform && child.style('transform', false, true).hasValue()) {
transform = new svg.Transform(child.style('transform', false, true).value);
}
if (transform) {
transform.apply(ctx);
}
child.path(ctx);
Expand Down
2 changes: 1 addition & 1 deletion dist/browser/canvg.min.js

Large diffs are not rendered by default.

36 changes: 28 additions & 8 deletions dist/node/canvg.js
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,14 @@
}
};

var data = svg.trim(svg.compressSpaces(v)).replace(/\)([a-zA-Z])/g, ') $1').replace(/\)(\s?,\s?)/g, ') ').split(/\s(?=[a-z])/);
var data = svg
.trim(svg.compressSpaces(v))
.replace(/\)([a-zA-Z])/g, ') $1')
.replace(/\)(\s?,\s?)/g, ') ')
.split(/\s(?=[a-z])/)
.filter(function (d) {
return d !== 'none';
});
for (var i = 0; i < data.length; i++) {
var type = svg.trim(data[i].split('(')[0]);
var s = data[i].split('(')[1].replace(')', '');
Expand Down Expand Up @@ -1035,7 +1042,7 @@
var gaps = svg.ToNumberArray(this.style('stroke-dasharray').value);
if (typeof ctx.setLineDash != 'undefined') { ctx.setLineDash(gaps); } else if (typeof ctx.webkitLineDash != 'undefined') { ctx.webkitLineDash = gaps; } else if (typeof ctx.mozDash != 'undefined' && !(gaps.length == 1 && gaps[0] == 0)) { ctx.mozDash = gaps; }

var offset = this.style('stroke-dashoffset').numValueOrDefault(1);
var offset = this.style('stroke-dashoffset').toPixels();
if (typeof ctx.lineDashOffset != 'undefined') { ctx.lineDashOffset = offset; } else if (typeof ctx.webkitLineDashOffset != 'undefined') { ctx.webkitLineDashOffset = offset; } else if (typeof ctx.mozDashOffset != 'undefined') { ctx.mozDashOffset = offset; }
}

Expand Down Expand Up @@ -1244,7 +1251,7 @@

if (ctx != null) {
ctx.beginPath();
ctx.arc(cx, cy, r, 0, Math.PI * 2, true);
ctx.arc(cx, cy, r, 0, Math.PI * 2, false);
ctx.closePath();
}

Expand All @@ -1267,11 +1274,11 @@

if (ctx != null) {
ctx.beginPath();
ctx.moveTo(cx, cy - ry);
ctx.bezierCurveTo(cx + (KAPPA * rx), cy - ry, cx + rx, cy - (KAPPA * ry), cx + rx, cy);
ctx.moveTo(cx + rx, cy);
ctx.bezierCurveTo(cx + rx, cy + (KAPPA * ry), cx + (KAPPA * rx), cy + ry, cx, cy + ry);
ctx.bezierCurveTo(cx - (KAPPA * rx), cy + ry, cx - rx, cy + (KAPPA * ry), cx - rx, cy);
ctx.bezierCurveTo(cx - rx, cy - (KAPPA * ry), cx - (KAPPA * rx), cy - ry, cx, cy - ry);
ctx.bezierCurveTo(cx + (KAPPA * rx), cy - ry, cx + rx, cy - (KAPPA * ry), cx + rx, cy);
ctx.closePath();
}

Expand Down Expand Up @@ -1683,7 +1690,12 @@
break;
case 'Z':
case 'z':
if (ctx != null) ctx.closePath();
if (ctx != null) {
// only close path if it is not a straight line
if (bb.x1 !== bb.x2 && bb.y1 !== bb.y2) {
ctx.closePath();
}
}
pp.current = pp.start;
}
}
Expand Down Expand Up @@ -2614,6 +2626,12 @@
if (element != null) element.path(ctx);
};

this.elementTransform = function () {
if (element != null && element.style('transform', false, true).hasValue()) {
return new svg.Transform(element.style('transform', false, true).value);
}
};

this.getBoundingBox = function () {
if (element != null) return element.getBoundingBox();
};
Expand Down Expand Up @@ -2717,9 +2735,11 @@
for (var i = 0; i < this.children.length; i++) {
var child = this.children[i];
if (typeof child.path != 'undefined') {
var transform = null;
if (child.style('transform', false, true).hasValue()) {
var transform = typeof child.elementTransform != 'undefined' && child.elementTransform(); // handle <use />
if (!transform && child.style('transform', false, true).hasValue()) {
transform = new svg.Transform(child.style('transform', false, true).value);
}
if (transform) {
transform.apply(ctx);
}
child.path(ctx);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"main": "dist/node/canvg.js",
"types": "dist/node/canvg.d.ts",
"browser": "dist/browser/canvg.min.js",
"version": "1.5.2",
"version": "1.5.3",
"scripts": {
"start": "node test/_server.js",
"build": "npm run build-browser && npm run build-node && npm run minify",
Expand Down
9 changes: 8 additions & 1 deletion src/canvg.js
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,14 @@ function build(opts) {
}
}

var data = svg.trim(svg.compressSpaces(v)).replace(/\)([a-zA-Z])/g, ') $1').replace(/\)(\s?,\s?)/g, ') ').split(/\s(?=[a-z])/);
var data = svg
.trim(svg.compressSpaces(v))
.replace(/\)([a-zA-Z])/g, ') $1')
.replace(/\)(\s?,\s?)/g, ') ')
.split(/\s(?=[a-z])/)
.filter(function (d) {
return d !== 'none';
});
for (var i = 0; i < data.length; i++) {
var type = svg.trim(data[i].split('(')[0]);
var s = data[i].split('(')[1].replace(')', '');
Expand Down

0 comments on commit c89f8f5

Please sign in to comment.