Merge pull request #20 from zenozeng/master
use currentDefaultPath instead of <path>'s d attribute, fixes stroke's different behavior in SVG and canvas.
This commit is contained in:
commit
bc53ac50ef
@ -260,7 +260,6 @@
|
||||
//also add a group child. the svg element can't use the transform attribute
|
||||
this.__currentElement = document.createElementNS("http://www.w3.org/2000/svg", "g");
|
||||
this.__root.appendChild(this.__currentElement);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
@ -504,29 +503,37 @@
|
||||
*/
|
||||
ctx.prototype.beginPath = function(){
|
||||
var path, parent;
|
||||
|
||||
// Note that there is only one current default path, it is not part of the drawing state.
|
||||
// See also: https://html.spec.whatwg.org/multipage/scripting.html#current-default-path
|
||||
this.__currentDefaultPath = "";
|
||||
|
||||
path = this.__createElement("path", {}, true);
|
||||
parent = this.__closestGroupOrSvg();
|
||||
parent.appendChild(path);
|
||||
this.__currentElement = path;
|
||||
};
|
||||
|
||||
/**
|
||||
* Helper function to apply currentDefaultPath to current path element
|
||||
* @private
|
||||
*/
|
||||
ctx.prototype.__applyCurrentDefaultPath = function() {
|
||||
if(this.__currentElement.nodeName === "path") {
|
||||
var d = this.__currentDefaultPath;
|
||||
this.__currentElement.setAttribute("d", d);
|
||||
} else {
|
||||
throw new Error("Attempted to apply path command to node " + this.__currentElement.nodeName);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Helper function to add path command
|
||||
* @private
|
||||
*/
|
||||
ctx.prototype.__addPathCommand = function(command){
|
||||
if(this.__currentElement.nodeName === "path") {
|
||||
var d = this.__currentElement.getAttribute("d");
|
||||
if(d) {
|
||||
d += " ";
|
||||
} else {
|
||||
d = "";
|
||||
}
|
||||
d += command;
|
||||
this.__currentElement.setAttribute("d", d);
|
||||
} else {
|
||||
throw new Error("Attempted to add path command to node " + this.__currentElement.nodeName);
|
||||
}
|
||||
this.__currentDefaultPath += " ";
|
||||
this.__currentDefaultPath += command;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -573,6 +580,7 @@
|
||||
* Sets the stroke property on the current element
|
||||
*/
|
||||
ctx.prototype.stroke = function(){
|
||||
this.__applyCurrentDefaultPath();
|
||||
this.__applyStyleToCurrentElement("stroke");
|
||||
};
|
||||
|
||||
@ -580,6 +588,7 @@
|
||||
* Sets fill properties on the current element
|
||||
*/
|
||||
ctx.prototype.fill = function(){
|
||||
this.__applyCurrentDefaultPath();
|
||||
this.__applyStyleToCurrentElement("fill");
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user