From 0a83da13b56785688a48618334bae8374337f7d9 Mon Sep 17 00:00:00 2001 From: Joost De Cock Date: Mon, 10 Dec 2018 12:52:24 +0100 Subject: [PATCH] :sparkles: Updated insertText hook --- src/pattern.js | 2 +- src/svg.js | 22 +++++++++++++--------- src/utils.js | 8 -------- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/pattern.js b/src/pattern.js index 558d68321fa..15dda669d80 100644 --- a/src/pattern.js +++ b/src/pattern.js @@ -1,4 +1,4 @@ -import { macroName, round, sampleStyle, methodHash } from "./utils"; +import { macroName, round, sampleStyle } from "./utils"; import Part from "./part"; import Point from "./point"; import Path from "./path"; diff --git a/src/svg.js b/src/svg.js index ba3412a6c5d..a8c651298a8 100644 --- a/src/svg.js +++ b/src/svg.js @@ -35,8 +35,14 @@ Svg.prototype.runHooks = function(hookName, data = false) { } }; -/** Method to attach insertText hooks on */ -Svg.prototype.insertText = function() {}; +/** Runs insertText hooks */ +Svg.prototype.insertText = function(text) { + if (this.hooks.insertText.length > 0) { + for (let hook of this.hooks.insertText) text = hook.method(text, hook.data); + } + + return text; +}; /** Debug method, exposes debug hook */ Svg.prototype.debug = function() {}; @@ -162,9 +168,9 @@ Svg.prototype.renderPath = function(path) { }; Svg.prototype.renderPathText = function(path) { - this.text = path.attributes.get("data-text"); - if (!this.text) return ""; - else this.insertText(); + let text = path.attributes.get("data-text"); + if (!text) return ""; + else this.text = this.insertText(text); let attributes = path.attributes.renderIfPrefixIs("data-text-"); // Sadly aligning text along a patch can't be done in CSS only let offset = ""; @@ -188,12 +194,10 @@ Svg.prototype.renderText = function(point) { if (text !== false) { let joint = ""; for (let string of text) { - this.text = string; - this.insertText(); + this.text = this.insertText(string); joint += this.text + " "; } - this.text = joint; - this.insertText(); + this.text = this.insertText(joint); } point.attributes.set("data-text-x", point.x); point.attributes.set("data-text-y", point.y); diff --git a/src/utils.js b/src/utils.js index fb34d400db7..05037155048 100644 --- a/src/utils.js +++ b/src/utils.js @@ -2,14 +2,6 @@ import Point from "./point"; import Bezier from "bezier-js"; import crypto from "crypto"; -/** Generates a hash, do not use this for security */ -export function methodHash(method) { - return crypto - .createHash("sha1") - .update(method.toSource()) - .digest("base64"); -} - /** Returns internal hook name for a macro */ export function macroName(name) { return `_macro_${name}`;