mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -05:00
Have option.matchShapes control conversion to SVG polygon elements as well.
Closes #753
This commit is contained in:
parent
2b0098321f
commit
65f085cc98
4 changed files with 8 additions and 7 deletions
|
@ -2084,8 +2084,8 @@ var Item = Base.extend(Emitter, /** @lends Item# */{
|
||||||
* @option [options.precision=5] {Number} the amount of fractional digits in
|
* @option [options.precision=5] {Number} the amount of fractional digits in
|
||||||
* numbers used in SVG data
|
* numbers used in SVG data
|
||||||
* @option [options.matchShapes=false] {Boolean} whether path items should
|
* @option [options.matchShapes=false] {Boolean} whether path items should
|
||||||
* tried to be converted to shape items, if their geometries can be made to
|
* tried to be converted to SVG shape items (rect, circle, ellipse, line,
|
||||||
* match
|
* polyline, polygon), if their geometries match
|
||||||
*
|
*
|
||||||
* @param {Object} [options] the export options
|
* @param {Object} [options] the export options
|
||||||
* @return {SVGElement} the item converted to an SVG node
|
* @return {SVGElement} the item converted to an SVG node
|
||||||
|
|
|
@ -641,8 +641,8 @@ var Project = PaperScopeItem.extend(/** @lends Project# */{
|
||||||
* @option [options.precision=5] {Number} the amount of fractional digits in
|
* @option [options.precision=5] {Number} the amount of fractional digits in
|
||||||
* numbers used in SVG data
|
* numbers used in SVG data
|
||||||
* @option [options.matchShapes=false] {Boolean} whether path items should
|
* @option [options.matchShapes=false] {Boolean} whether path items should
|
||||||
* tried to be converted to shape items, if their geometries can be made to
|
* tried to be converted to SVG shape items (rect, circle, ellipse, line,
|
||||||
* match
|
* polyline, polygon), if their geometries match
|
||||||
*
|
*
|
||||||
* @param {Object} [options] the export options
|
* @param {Object} [options] the export options
|
||||||
* @return {SVGElement} the project converted to an SVG node
|
* @return {SVGElement} the project converted to an SVG node
|
||||||
|
|
|
@ -114,7 +114,8 @@ new function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function exportPath(item, options) {
|
function exportPath(item, options) {
|
||||||
if (options.matchShapes) {
|
var matchShapes = options.matchShapes;
|
||||||
|
if (matchShapes) {
|
||||||
var shape = item.toShape(false);
|
var shape = item.toShape(false);
|
||||||
if (shape)
|
if (shape)
|
||||||
return exportShape(shape, options);
|
return exportShape(shape, options);
|
||||||
|
@ -124,7 +125,7 @@ new function() {
|
||||||
attrs = getTransform(item._matrix);
|
attrs = getTransform(item._matrix);
|
||||||
if (segments.length === 0)
|
if (segments.length === 0)
|
||||||
return null;
|
return null;
|
||||||
if (item.isPolygon()) {
|
if (matchShapes && !item.isPolygon()) {
|
||||||
if (segments.length >= 3) {
|
if (segments.length >= 3) {
|
||||||
type = item._closed ? 'polygon' : 'polyline';
|
type = item._closed ? 'polygon' : 'polyline';
|
||||||
var parts = [];
|
var parts = [];
|
||||||
|
|
|
@ -20,7 +20,7 @@ test('Export SVG line', function() {
|
||||||
y2: 45
|
y2: 45
|
||||||
};
|
};
|
||||||
var path = new Path.Line([attrs.x1, attrs.y1], [attrs.x2, attrs.y2]);
|
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() {
|
test('Export SVG rect', function() {
|
||||||
|
|
Loading…
Reference in a new issue