mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-06 04:42:15 -05:00
Some more SVG code refactoring.
This commit is contained in:
parent
44fc5939e5
commit
155b6046cb
2 changed files with 12 additions and 14 deletions
|
@ -28,10 +28,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var ExportSvg = this.ExportSvg = Base.extend(/** @Lends ExportSvg# */{
|
var ExportSvg = this.ExportSvg = Base.extend(/** @Lends ExportSvg# */{
|
||||||
//initialize the svgObj
|
|
||||||
initialize: function() {
|
|
||||||
this.svgObj = this.create('svg');
|
|
||||||
},
|
|
||||||
|
|
||||||
create: function(tag) {
|
create: function(tag) {
|
||||||
return document.createElementNS('http://www.w3.org/2000/svg', tag);
|
return document.createElementNS('http://www.w3.org/2000/svg', tag);
|
||||||
|
@ -49,13 +45,12 @@ var ExportSvg = this.ExportSvg = Base.extend(/** @Lends ExportSvg# */{
|
||||||
*/
|
*/
|
||||||
//TODO: Implement symbols and Gradients
|
//TODO: Implement symbols and Gradients
|
||||||
exportProject: function(project) {
|
exportProject: function(project) {
|
||||||
var layerArray = project.layers;
|
var svg = this.create('svg'),
|
||||||
var layer;
|
layers = project.layers;
|
||||||
for (var i = 0; i < layerArray.length; ++i) {
|
for (var i = 0; i < layers.length; ++i) {
|
||||||
layer = layerArray[i];
|
svg.appendChild(this.exportLayer(layers[i]));
|
||||||
this.svgObj.appendChild(this.exportLayer(layer));
|
|
||||||
}
|
}
|
||||||
return this.svgObj;
|
return svg;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -366,7 +361,7 @@ var ExportSvg = this.ExportSvg = Base.extend(/** @Lends ExportSvg# */{
|
||||||
y2 = pointArray[i + 1].getY();
|
y2 = pointArray[i + 1].getY();
|
||||||
handleOut1 = hOArray[i];
|
handleOut1 = hOArray[i];
|
||||||
handleIn2 = hIArray[i+1];
|
handleIn2 = hIArray[i+1];
|
||||||
if (handleOut1.getX() == 0 && handleOut1.getY() == 0 && handleIn2.getX() == 0 && handleIn2.getY() ==0) {
|
if (handleOut1.getX() == 0 && handleOut1.getY() == 0 && handleIn2.getX() == 0 && handleIn2.getY() == 0) {
|
||||||
//L is lineto, moving to a point with drawing
|
//L is lineto, moving to a point with drawing
|
||||||
pointString+= 'L' + x2 + ',' + y2 + ' ';
|
pointString+= 'L' + x2 + ',' + y2 + ' ';
|
||||||
} else {
|
} else {
|
||||||
|
@ -376,7 +371,7 @@ var ExportSvg = this.ExportSvg = Base.extend(/** @Lends ExportSvg# */{
|
||||||
pointString+= (x2 - x1) + ',' + (y2-y1) + ' ';
|
pointString+= (x2 - x1) + ',' + (y2-y1) + ' ';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!hOArray[hOArray.length - 1].equals([0,0]) && !hIArray[0].equals([0,0])) {
|
if (!hOArray[hOArray.length - 1].equals([0, 0]) && !hIArray[0].equals([0, 0])) {
|
||||||
handleOut1 = hOArray[hOArray.length - 1];
|
handleOut1 = hOArray[hOArray.length - 1];
|
||||||
handleIn2 = hIArray[0];
|
handleIn2 = hIArray[0];
|
||||||
// Bezier curve from last point to first
|
// Bezier curve from last point to first
|
||||||
|
|
|
@ -74,6 +74,7 @@ var ImportSvg = this.ImportSvg = Base.extend(/** @Lends ImportSvg# */{
|
||||||
this._importAttributesAndStyles(svg, item);
|
this._importAttributesAndStyles(svg, item);
|
||||||
symbol = new Symbol(item);
|
symbol = new Symbol(item);
|
||||||
item = null;
|
item = null;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
// Not supported yet.
|
// Not supported yet.
|
||||||
}
|
}
|
||||||
|
@ -482,8 +483,10 @@ var ImportSvg = this.ImportSvg = Base.extend(/** @Lends ImportSvg# */{
|
||||||
break;
|
break;
|
||||||
case 'transform':
|
case 'transform':
|
||||||
this._applyTransform(item, svg);
|
this._applyTransform(item, svg);
|
||||||
|
break;
|
||||||
case 'opacity':
|
case 'opacity':
|
||||||
item.opacity = parseFloat(value, 10);
|
item.opacity = parseFloat(value, 10);
|
||||||
|
break;
|
||||||
case 'visibility':
|
case 'visibility':
|
||||||
item.visibility = (value == 'visible') ? true : false;
|
item.visibility = (value == 'visible') ? true : false;
|
||||||
break;
|
break;
|
||||||
|
@ -566,8 +569,8 @@ var ImportSvg = this.ImportSvg = Base.extend(/** @Lends ImportSvg# */{
|
||||||
transformMatrix.setShearX(0);
|
transformMatrix.setShearX(0);
|
||||||
break;
|
break;
|
||||||
case SVGTransform.SVG_TRANSFORM_ROTATE:
|
case SVGTransform.SVG_TRANSFORM_ROTATE:
|
||||||
transformMatrix.setShearX(transformMatrix.getShearX() * -1);
|
transformMatrix.setShearX(-transformMatrix.getShearX());
|
||||||
transformMatrix.setShearY(transformMatrix.getShearY() * -1);
|
transformMatrix.setShearY(-transformMatrix.getShearY());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
matrix.concatenate(transformMatrix);
|
matrix.concatenate(transformMatrix);
|
||||||
|
|
Loading…
Reference in a new issue