Skip to content

Commit 50b9b6b

Browse files
committed
Fix: svg import ignores rectangle radius when only one side is set.
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
1 parent 0956710 commit 50b9b6b

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

src/svg/SvgImport.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,18 @@ new function() {
281281

282282
// https://www.w3.org/TR/SVG/shapes.html#RectElement
283283
rect: function(node) {
284+
var rx = getValue(node, 'rx', false, true, true);
285+
var ry = getValue(node, 'ry', false, true, true);
286+
if (rx === null && ry !== null) {
287+
rx = ry;
288+
} else if (ry === null && rx !== null) {
289+
ry = rx;
290+
}
291+
var radius = rx !== null && ry !== null ? new Size(rx, ry) : null;
284292
return new Shape.Rectangle(new Rectangle(
285293
getPoint(node),
286294
getSize(node)
287-
), getSize(node, 'rx', 'ry'));
295+
), radius);
288296
},
289297

290298
// https://www.w3.org/TR/SVG/shapes.html#LineElement

test/assets/rectangles.svg

Lines changed: 10 additions & 0 deletions
Loading

test/tests/SvgImport.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ if (!isNodeContext) {
205205
'gradients-1': {},
206206
'gradients-2': !isPhantomContext && {},
207207
'gradients-3': {},
208-
'gradients-4': {}
208+
'gradients-4': {},
209+
'rectangles': {}
209210
};
210211
Base.each(svgFiles, function(options, name) {
211212
if (options) {

0 commit comments

Comments
 (0)