Skip to content

Commit

Permalink
Fix: svg import ignores rectangle radius when only one side is set.
Browse files Browse the repository at this point in the history
This follows the SVG spec in which only one side can be set and set the other
side to the same value in this case.
This also adds support for percent values.

Fixes #1863
  • Loading branch information
sasensi committed Nov 4, 2020
1 parent 0956710 commit 50b9b6b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/svg/SvgImport.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,18 @@ new function() {

// https://www.w3.org/TR/SVG/shapes.html#RectElement
rect: function(node) {
var rx = getValue(node, 'rx', false, true, true);
var ry = getValue(node, 'ry', false, true, true);
if (rx === null && ry !== null) {
rx = ry;
} else if (ry === null && rx !== null) {
ry = rx;
}
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
Expand Down
10 changes: 10 additions & 0 deletions test/assets/rectangles.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion test/tests/SvgImport.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ if (!isNodeContext) {
'gradients-1': {},
'gradients-2': !isPhantomContext && {},
'gradients-3': {},
'gradients-4': {}
'gradients-4': {},
'rectangles': {}
};
Base.each(svgFiles, function(options, name) {
if (options) {
Expand Down

0 comments on commit 50b9b6b

Please sign in to comment.