Skip to content

Commit 76c20bc

Browse files
authored
Merge pull request #1 from CubesterYT/develop
Fix `rx` and `ry` attributes
2 parents ebf4bb2 + a0792cf commit 76c20bc

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

src/svg/SvgImport.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,24 @@ 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'));
301+
), radius);
288302
},
289303

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

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
@@ -214,7 +214,8 @@ if (!isNodeContext) {
214214
'gradients-1': {},
215215
'gradients-2': !isPhantomContext && {},
216216
'gradients-3': {},
217-
'gradients-4': {}
217+
'gradients-4': {},
218+
'rectangles': {}
218219
};
219220
Base.each(svgFiles, function(options, name) {
220221
if (options) {

0 commit comments

Comments
 (0)