From a0792cf56a5e99202fb4ecdb5458c2da7845121e Mon Sep 17 00:00:00 2001 From: Cubester Date: Mon, 15 Jul 2024 21:44:34 -0400 Subject: [PATCH] Fix `rx` and `ry` attributes --- src/svg/SvgImport.js | 16 +++++++++++++++- test/assets/rectangles.svg | 9 +++++++++ test/tests/SvgImport.js | 3 ++- 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 test/assets/rectangles.svg diff --git a/src/svg/SvgImport.js b/src/svg/SvgImport.js index f58c8c0232..063f759aca 100644 --- a/src/svg/SvgImport.js +++ b/src/svg/SvgImport.js @@ -281,10 +281,24 @@ new function() { // https://www.w3.org/TR/SVG/shapes.html#RectElement rect: function(node) { + var rx = SvgElement.get(node, 'rx'); + var ry = SvgElement.get(node, 'ry'); + if (rx === null && ry !== null) { + rx = ry; + } else if (ry === null && rx !== null) { + ry = rx; + } + if (/%\s*$/.test(rx)) { + rx = parseFloat(rx) * rootSize.width / 100; + } + if (/%\s*$/.test(ry)) { + ry = parseFloat(ry) * rootSize.height / 100; + } + var radius = rx !== null && ry !== null ? new Size(rx, ry) : null; return new Shape.Rectangle(new Rectangle( getPoint(node), getSize(node) - ), getSize(node, 'rx', 'ry')); + ), radius); }, // https://www.w3.org/TR/SVG/shapes.html#LineElement diff --git a/test/assets/rectangles.svg b/test/assets/rectangles.svg new file mode 100644 index 0000000000..40bd6d7182 --- /dev/null +++ b/test/assets/rectangles.svg @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/test/tests/SvgImport.js b/test/tests/SvgImport.js index 94477b25d5..5b17c34116 100644 --- a/test/tests/SvgImport.js +++ b/test/tests/SvgImport.js @@ -214,7 +214,8 @@ if (!isNodeContext) { 'gradients-1': {}, 'gradients-2': !isPhantomContext && {}, 'gradients-3': {}, - 'gradients-4': {} + 'gradients-4': {}, + 'rectangles': {} }; Base.each(svgFiles, function(options, name) { if (options) {