From 8e45fa2d58c5cb34fd36fa8ebc24a4814eb1824b Mon Sep 17 00:00:00 2001 From: Taylor Hunt Date: Sat, 13 Jul 2019 15:31:22 -0400 Subject: [PATCH] =?UTF-8?q?Add=20=E2=80=98ellipseToCircle=E2=80=99=20plugi?= =?UTF-8?q?n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Converts non-eccentric ellipse elements to circle elements. Adobe Illustrator seems to be fond of using ellipses even if their rx === ry. --- plugins/convertEllipseToCircle.js | 39 ++++++++++++++++++++++ test/plugins/convertEllipseToCircle.01.svg | 13 ++++++++ 2 files changed, 52 insertions(+) create mode 100644 plugins/convertEllipseToCircle.js create mode 100644 test/plugins/convertEllipseToCircle.01.svg diff --git a/plugins/convertEllipseToCircle.js b/plugins/convertEllipseToCircle.js new file mode 100644 index 00000000..f1af11a9 --- /dev/null +++ b/plugins/convertEllipseToCircle.js @@ -0,0 +1,39 @@ +'use strict'; + +exports.type = 'perItem'; + +exports.active = true; + +exports.description = 'converts non-eccentric s to s'; + +/** + * Converts non-eccentric s to s. + * + * @see http://www.w3.org/TR/SVG/shapes.html + * + * @param {Object} item current iteration item + * @return {Boolean} if false, item will be filtered out + * + * @author Taylor Hunt + */ +exports.fn = function(item) { + if (item.isElem('ellipse')) { + var rx = item.attr('rx').value || 0; + var ry = item.attr('ry').value || 0; + + if (rx === ry || + rx === 'auto' || ry === 'auto' // SVG2 + ) { + var radius = rx !== 'auto' ? rx : ry; + item.renameElem('circle'); + item.removeAttr(['rx', 'ry']); + item.addAttr({ + name: 'r', + value: radius, + prefix: '', + local: 'r', + }); + } + } + return; +}; diff --git a/test/plugins/convertEllipseToCircle.01.svg b/test/plugins/convertEllipseToCircle.01.svg new file mode 100644 index 00000000..b1146dfa --- /dev/null +++ b/test/plugins/convertEllipseToCircle.01.svg @@ -0,0 +1,13 @@ + + + + + + +@@@ + + + + + +