Have option.matchShapes control conversion to SVG polygon elements as well.

Closes #753
This commit is contained in:
Jürg Lehni 2015-08-17 14:18:22 +02:00
parent 2b0098321f
commit 65f085cc98
4 changed files with 8 additions and 7 deletions

View file

@ -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

View file

@ -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

View file

@ -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 = [];

View file

@ -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() {