From 65f085cc98aeaa9408eed885574d4e3c12b25fc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Mon, 17 Aug 2015 14:18:22 +0200 Subject: [PATCH] Have option.matchShapes control conversion to SVG polygon elements as well. Closes #753 --- src/item/Item.js | 4 ++-- src/project/Project.js | 4 ++-- src/svg/SVGExport.js | 5 +++-- test/tests/SVGExport.js | 2 +- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/item/Item.js b/src/item/Item.js index 78037458..ef653c8e 100644 --- a/src/item/Item.js +++ b/src/item/Item.js @@ -2084,8 +2084,8 @@ var Item = Base.extend(Emitter, /** @lends Item# */{ * @option [options.precision=5] {Number} the amount of fractional digits in * numbers used in SVG data * @option [options.matchShapes=false] {Boolean} whether path items should - * tried to be converted to shape items, if their geometries can be made to - * match + * tried to be converted to SVG shape items (rect, circle, ellipse, line, + * polyline, polygon), if their geometries match * * @param {Object} [options] the export options * @return {SVGElement} the item converted to an SVG node diff --git a/src/project/Project.js b/src/project/Project.js index 6ca3e4d7..8bddedb4 100644 --- a/src/project/Project.js +++ b/src/project/Project.js @@ -641,8 +641,8 @@ var Project = PaperScopeItem.extend(/** @lends Project# */{ * @option [options.precision=5] {Number} the amount of fractional digits in * numbers used in SVG data * @option [options.matchShapes=false] {Boolean} whether path items should - * tried to be converted to shape items, if their geometries can be made to - * match + * tried to be converted to SVG shape items (rect, circle, ellipse, line, + * polyline, polygon), if their geometries match * * @param {Object} [options] the export options * @return {SVGElement} the project converted to an SVG node diff --git a/src/svg/SVGExport.js b/src/svg/SVGExport.js index 99126cbe..d0fee4e4 100644 --- a/src/svg/SVGExport.js +++ b/src/svg/SVGExport.js @@ -114,7 +114,8 @@ new function() { } function exportPath(item, options) { - if (options.matchShapes) { + var matchShapes = options.matchShapes; + if (matchShapes) { var shape = item.toShape(false); if (shape) return exportShape(shape, options); @@ -124,7 +125,7 @@ new function() { attrs = getTransform(item._matrix); if (segments.length === 0) return null; - if (item.isPolygon()) { + if (matchShapes && !item.isPolygon()) { if (segments.length >= 3) { type = item._closed ? 'polygon' : 'polyline'; var parts = []; diff --git a/test/tests/SVGExport.js b/test/tests/SVGExport.js index 30eca294..29f53e6e 100644 --- a/test/tests/SVGExport.js +++ b/test/tests/SVGExport.js @@ -20,7 +20,7 @@ test('Export SVG line', function() { y2: 45 }; var path = new Path.Line([attrs.x1, attrs.y1], [attrs.x2, attrs.y2]); - equals(path.exportSVG(), createSVG('line', attrs)); + equals(path.exportSVG({ matchShapes: true }), createSVG('line', attrs)); }); test('Export SVG rect', function() {