From de824e184617f3d8454482eb1825dc13b6ed554e Mon Sep 17 00:00:00 2001 From: Samuel Asensi Date: Fri, 7 Jun 2019 22:30:01 +0200 Subject: [PATCH] Fix exported SVG missing viewBox attribute (#1576) SVG viewBox attribute was not added when bounds rectangle point was 0,0. --- src/svg/SvgExport.js | 2 +- test/tests/SvgExport.js | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/svg/SvgExport.js b/src/svg/SvgExport.js index 5048bc2c..9dc464a3 100644 --- a/src/svg/SvgExport.js +++ b/src/svg/SvgExport.js @@ -427,7 +427,7 @@ new function() { if (rect) { attrs.width = rect.width; attrs.height = rect.height; - if (rect.x || rect.y) + if (rect.x || rect.x === 0 || rect.y || rect.y === 0) attrs.viewBox = formatter.rectangle(rect); } var node = SvgElement.create('svg', attrs, formatter), diff --git a/test/tests/SvgExport.js b/test/tests/SvgExport.js index e50225c2..004a3f27 100644 --- a/test/tests/SvgExport.js +++ b/test/tests/SvgExport.js @@ -113,6 +113,12 @@ test('Export SVG path at precision 0', function() { equals(path.exportSVG({ precision: 0 }).getAttribute('d'), 'M0,2l1,1'); }); +test('Export SVG viewbox attribute with top left at origin', function() { + var path = new Path.Rectangle(new Point(10, 10), new Size(80)); + var rectangle = new Rectangle(new Point(0, 0), new Size(100)); + equals(project.exportSVG({ bounds: rectangle }).getAttribute('viewBox'), '0,0,100,100'); +}); + if (!isNode) { // JSDom does not have SVG rendering, so we can't test there. test('Export transformed shapes', function(assert) {