mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -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# */{
|
||||
//initialize the svgObj
|
||||
initialize: function() {
|
||||
this.svgObj = this.create('svg');
|
||||
},
|
||||
|
||||
create: function(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
|
||||
exportProject: function(project) {
|
||||
var layerArray = project.layers;
|
||||
var layer;
|
||||
for (var i = 0; i < layerArray.length; ++i) {
|
||||
layer = layerArray[i];
|
||||
this.svgObj.appendChild(this.exportLayer(layer));
|
||||
var svg = this.create('svg'),
|
||||
layers = project.layers;
|
||||
for (var i = 0; i < layers.length; ++i) {
|
||||
svg.appendChild(this.exportLayer(layers[i]));
|
||||
}
|
||||
return this.svgObj;
|
||||
return svg;
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -366,7 +361,7 @@ var ExportSvg = this.ExportSvg = Base.extend(/** @Lends ExportSvg# */{
|
|||
y2 = pointArray[i + 1].getY();
|
||||
handleOut1 = hOArray[i];
|
||||
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
|
||||
pointString+= 'L' + x2 + ',' + y2 + ' ';
|
||||
} else {
|
||||
|
@ -376,7 +371,7 @@ var ExportSvg = this.ExportSvg = Base.extend(/** @Lends ExportSvg# */{
|
|||
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];
|
||||
handleIn2 = hIArray[0];
|
||||
// Bezier curve from last point to first
|
||||
|
|
|
@ -74,6 +74,7 @@ var ImportSvg = this.ImportSvg = Base.extend(/** @Lends ImportSvg# */{
|
|||
this._importAttributesAndStyles(svg, item);
|
||||
symbol = new Symbol(item);
|
||||
item = null;
|
||||
break;
|
||||
default:
|
||||
// Not supported yet.
|
||||
}
|
||||
|
@ -482,8 +483,10 @@ var ImportSvg = this.ImportSvg = Base.extend(/** @Lends ImportSvg# */{
|
|||
break;
|
||||
case 'transform':
|
||||
this._applyTransform(item, svg);
|
||||
break;
|
||||
case 'opacity':
|
||||
item.opacity = parseFloat(value, 10);
|
||||
break;
|
||||
case 'visibility':
|
||||
item.visibility = (value == 'visible') ? true : false;
|
||||
break;
|
||||
|
@ -566,8 +569,8 @@ var ImportSvg = this.ImportSvg = Base.extend(/** @Lends ImportSvg# */{
|
|||
transformMatrix.setShearX(0);
|
||||
break;
|
||||
case SVGTransform.SVG_TRANSFORM_ROTATE:
|
||||
transformMatrix.setShearX(transformMatrix.getShearX() * -1);
|
||||
transformMatrix.setShearY(transformMatrix.getShearY() * -1);
|
||||
transformMatrix.setShearX(-transformMatrix.getShearX());
|
||||
transformMatrix.setShearY(-transformMatrix.getShearY());
|
||||
break;
|
||||
}
|
||||
matrix.concatenate(transformMatrix);
|
||||
|
|
Loading…
Reference in a new issue