From 30dc6c3bb2dd3b3f14780cad10a545e4d768baf3 Mon Sep 17 00:00:00 2001 From: Joost De Cock Date: Sat, 22 Dec 2018 17:20:04 +0100 Subject: [PATCH] sparkles: Added support for scale and rotation --- packages/plugin-title/src/index.js | 32 +++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/packages/plugin-title/src/index.js b/packages/plugin-title/src/index.js index 4323a1c7cfc..4a003f6afd3 100644 --- a/packages/plugin-title/src/index.js +++ b/packages/plugin-title/src/index.js @@ -14,6 +14,19 @@ export default { }, macros: { title: function(so) { + const transform = function(anchor) { + let cx = anchor.x - so.scale * anchor.x; + let cy = anchor.y - so.scale * anchor.y; + + return `matrix(${so.scale}, 0, 0, ${so.scale}, ${cx}, ${cy}) rotate(${ + so.rotation + } ${anchor.x} ${anchor.y})`; + }; + let defaults = { + scale: 1, + rotation: 0 + }; + so = { ...defaults, ...so }; let overwrite = true; if (so.append) overwrite = false; let prefix = ""; @@ -21,20 +34,29 @@ export default { this.points[`_${prefix}_titleNr`] = so.at .clone() .attr("data-text", so.nr, overwrite) - .attr("data-text-class", "title-nr note fill-note"); + .attr("data-text-class", "title-nr note fill-note") + .attr("data-text-transform", transform(so.at, so.at)); let shift = 10; if (so.title) { this.points[`_${prefix}_titleName`] = so.at - .shift(-90, 13) + .shift(-90 - so.rotation, 13 * so.scale) .attr("data-text", so.title) - .attr("data-text-class", "title-name"); + .attr("data-text-class", "title-name") + .attr( + "data-text-transform", + transform(so.at.shift(-90 - so.rotation, 13 * so.scale)) + ); shift += 10; } this.points[`_${prefix}_titlePattern`] = so.at - .shift(-90, shift) + .shift(-90 - so.rotation, shift * so.scale) .attr("data-text", this.context.config.name) .attr("data-text", "v" + this.context.config.version) - .attr("data-text-class", "title-pattern fill-note"); + .attr("data-text-class", "title-pattern fill-note") + .attr( + "data-text-transform", + transform(so.at.shift(-90 - so.rotation, shift * so.scale)) + ); } } };