From f43ff8ba15c2c9a7d674d1ecfda0ea420abb6c7e Mon Sep 17 00:00:00 2001 From: k1w1 Date: Mon, 5 Sep 2022 12:35:47 -0700 Subject: [PATCH] Apply transform to paths --- context.js | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/context.js b/context.js index e512322..c003d7a 100644 --- a/context.js +++ b/context.js @@ -633,35 +633,32 @@ export default (function () { * Sets the stroke property on the current element */ Context.prototype.stroke = function (path2d) { - if (path2d) { - var path = this.__createPathElement(); - this.__applyStyleToElement(path, "stroke"); - path.setAttribute("paint-order", "fill stroke markers"); - path.setAttribute("d", path2d.__pathString); - } else { - if (this.__currentElement.nodeName === "path") { - this.__currentElement.setAttribute("paint-order", "fill stroke markers"); - } - this.__applyCurrentDefaultPath(); - this.__applyStyleToElement(this.__currentElement, "stroke"); - } + this.__strokeOrFill(path2d, "stroke"); }; /** * Sets fill properties on the current element */ Context.prototype.fill = function (path2d) { + this.__strokeOrFill(path2d, "fill"); + }; + + Context.prototype.__strokeOrFill = function (path2d, action) { if (path2d) { var path = this.__createPathElement(); - this.__applyStyleToElement(path, "fill"); + this.__applyStyleToElement(path, action); path.setAttribute("paint-order", "fill stroke markers"); path.setAttribute("d", path2d.__pathString); + this.__applyTransformation(path); } else { if (this.__currentElement.nodeName === "path") { - this.__currentElement.setAttribute("paint-order", "stroke fill markers"); + this.__currentElement.setAttribute( + "paint-order", + "stroke fill markers" + ); } this.__applyCurrentDefaultPath(); - this.__applyStyleToElement(this.__currentElement, "fill"); + this.__applyStyleToElement(this.__currentElement, action); } };