Skip to content

Commit 216412d

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 216412d

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

src/svg/SvgImport.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,11 +281,25 @@ new function() {
281281

282282
// https://www.w3.org/TR/SVG/shapes.html#RectElement
283283
rect: function(node) {
284+
var rx = SvgElement.get(node, 'rx');
285+
var ry = SvgElement.get(node, 'ry');
286+
if (rx === null && ry !== null) {
287+
rx = ry;
288+
} else if (ry === null && rx !== null) {
289+
ry = rx;
290+
}
291+
if (/%\s*$/.test(rx)) {
292+
rx = parseFloat(rx) * rootSize.width / 100;
293+
}
294+
if (/%\s*$/.test(ry)) {
295+
ry = parseFloat(ry) * rootSize.height / 100;
296+
}
297+
var radius = rx !== null && ry !== null ? new Size(rx, ry) : null;
284298
return new Shape.Rectangle(new Rectangle(
285299
getPoint(node),
286300
getSize(node)
287-
), getSize(node, 'rx', 'ry'));
288-
},
301+
), radius);
302+
},
289303

290304
// https://www.w3.org/TR/SVG/shapes.html#LineElement
291305
line: function(node) {

test/assets/rectangles.svg

Lines changed: 9 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)