Skip to content

Commit

Permalink
Fix EdgeHTML14 broken Path2D
Browse files Browse the repository at this point in the history
This will detect and work around the broken Path2D in EdgeHTML14.
issue #136
  • Loading branch information
spatialillusions authored Oct 17, 2017
1 parent ef5f8e5 commit a1de5cb
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/symbol/ascanvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ module.exports = function(ratio) {

switch (instruction[i].type) {
case "path":
if (typeof Path2D != "undefined") {
if (!ms._brokenPath2D) {
var d = new Path2D(instruction[i].d);
if (
typeof instruction[i].fill === "undefined" ||
Expand Down Expand Up @@ -165,6 +165,29 @@ module.exports = function(ratio) {
}
}

if (typeof ms._brokenPath2D == "undefined") {
/* In EdgeHTML14 Microsoft implemented support for Path2D, but they didn't implement support
for initiating it with a SVG path, and if you initiate it with an SVG path, it will not throw
an error, instead it will return an empty path and log a warning.
This will check for that behaviour and make sure we use the workaround if Path2D is broken. */
if (typeof Path2D == "undefined") {
// If Path2D dosen't exist it is definetly broken
console.info("path 2d does not exist");
ms._brokenPath2D = true;
} else {
// If Path2D exists we need to check if it is broken
var canv = document.createElement("canvas");
canv.widht = 1;
canv.height = 1;
var _ctx = canv.getContext("2d");
var p = new Path2D("M0 0 h 10 v 10 h -10 Z");
_ctx.fill(p);
// Oh this is dirty, just compare part of the base64 string to see if it is "correct"
var url = canv.toDataURL();
ms._brokenPath2D = !(url.substr(url.length - 10) == "VORK5CYII=");
}
}

var canvas = document.createElement("canvas");
//TODO fix the pixel ratio
ratio = ratio || 1; //window.devicePixelRatio || 1;
Expand Down

0 comments on commit a1de5cb

Please sign in to comment.