mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-03 19:45:44 -05:00
More SVG code refactoring.
Follow coding conventions and fix some forgotten renamings.
This commit is contained in:
parent
160095d6e3
commit
d4a60fb62a
12 changed files with 378 additions and 381 deletions
|
@ -11,8 +11,8 @@
|
||||||
// strokeWidth: 2,
|
// strokeWidth: 2,
|
||||||
// strokeCap: 'round'
|
// strokeCap: 'round'
|
||||||
};
|
};
|
||||||
var isvg = new ImportSvg;
|
var isvg = new ImportSvg();
|
||||||
isvg.importSVG(document.getElementById('svg'));
|
isvg.importSvg(document.getElementById('svg'));
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
|
@ -11,8 +11,8 @@
|
||||||
// strokeWidth: 2,
|
// strokeWidth: 2,
|
||||||
// strokeCap: 'round'
|
// strokeCap: 'round'
|
||||||
};
|
};
|
||||||
var isvg = new ImportSvg;
|
var isvg = new ImportSvg();
|
||||||
isvg.importSVG(document.getElementById('svg'));
|
isvg.importSvg(document.getElementById('svg'));
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
|
@ -11,8 +11,8 @@
|
||||||
// strokeWidth: 2,
|
// strokeWidth: 2,
|
||||||
// strokeCap: 'round'
|
// strokeCap: 'round'
|
||||||
};
|
};
|
||||||
var isvg = new ImportSvg;
|
var isvg = new ImportSvg();
|
||||||
isvg.importSVG(document.getElementById('svg'));
|
isvg.importSvg(document.getElementById('svg'));
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
|
@ -11,8 +11,8 @@
|
||||||
// strokeWidth: 2,
|
// strokeWidth: 2,
|
||||||
// strokeCap: 'round'
|
// strokeCap: 'round'
|
||||||
};
|
};
|
||||||
var isvg = new ImportSvg;
|
var isvg = new ImportSvg();
|
||||||
isvg.importSVG(document.getElementById('svg'));
|
isvg.importSvg(document.getElementById('svg'));
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
|
@ -12,8 +12,8 @@
|
||||||
// strokeWidth: 2,
|
// strokeWidth: 2,
|
||||||
// strokeCap: 'round'
|
// strokeCap: 'round'
|
||||||
};
|
};
|
||||||
var isvg = new ImportSvg;
|
var isvg = new ImportSvg();
|
||||||
isvg.importSVG(document.getElementById('svg'));
|
isvg.importSvg(document.getElementById('svg'));
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
|
@ -11,8 +11,8 @@
|
||||||
// strokeWidth: 2,
|
// strokeWidth: 2,
|
||||||
// strokeCap: 'round'
|
// strokeCap: 'round'
|
||||||
};
|
};
|
||||||
var isvg = new ImportSvg;
|
var isvg = new ImportSvg();
|
||||||
isvg.importSVG(document.getElementById('svg'));
|
isvg.importSvg(document.getElementById('svg'));
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
|
@ -11,8 +11,8 @@
|
||||||
// strokeWidth: 2,
|
// strokeWidth: 2,
|
||||||
// strokeCap: 'round'
|
// strokeCap: 'round'
|
||||||
};
|
};
|
||||||
var isvg = new ImportSvg;
|
var isvg = new ImportSvg();
|
||||||
isvg.importSVG(document.getElementById('svg'));
|
isvg.importSvg(document.getElementById('svg'));
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
|
@ -11,8 +11,8 @@
|
||||||
// strokeWidth: 2,
|
// strokeWidth: 2,
|
||||||
// strokeCap: 'round'
|
// strokeCap: 'round'
|
||||||
};
|
};
|
||||||
var isvg = new ImportSvg;
|
var isvg = new ImportSvg();
|
||||||
isvg.importSVG(document.getElementById('svg'));
|
isvg.importSvg(document.getElementById('svg'));
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
|
@ -11,8 +11,8 @@
|
||||||
// strokeWidth: 2,
|
// strokeWidth: 2,
|
||||||
// strokeCap: 'round'
|
// strokeCap: 'round'
|
||||||
};
|
};
|
||||||
var isvg = new ImportSvg;
|
var isvg = new ImportSvg();
|
||||||
isvg.importSVG(document.getElementById('svg'));
|
isvg.importSvg(document.getElementById('svg'));
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
|
@ -111,6 +111,7 @@ var ExportSvg = this.ExportSvg = Base.extend(/** @Lends ExportSvg# */{
|
||||||
var pointArray;
|
var pointArray;
|
||||||
var handleInArray;
|
var handleInArray;
|
||||||
var handleOutArray;
|
var handleOutArray;
|
||||||
|
var type;
|
||||||
//finding the type of path to export
|
//finding the type of path to export
|
||||||
if (path.content) {
|
if (path.content) {
|
||||||
type = 'text';
|
type = 'text';
|
||||||
|
@ -118,16 +119,16 @@ var ExportSvg = this.ExportSvg = Base.extend(/** @Lends ExportSvg# */{
|
||||||
//Values are only defined if the path is not text because
|
//Values are only defined if the path is not text because
|
||||||
// text does not have these values
|
// text does not have these values
|
||||||
segArray = path.getSegments();
|
segArray = path.getSegments();
|
||||||
pointArray = new Array();
|
pointArray = [];
|
||||||
handleInArray = new Array();
|
handleInArray = [];
|
||||||
handleOutArray = new Array();
|
handleOutArray = [];
|
||||||
for (i = 0; i < segArray.length; i++) {
|
for (i = 0; i < segArray.length; i++) {
|
||||||
pointArray[i] = segArray[i].getPoint();
|
pointArray[i] = segArray[i].getPoint();
|
||||||
handleInArray[i] = segArray[i].getHandleIn();
|
handleInArray[i] = segArray[i].getHandleIn();
|
||||||
handleOutArray[i] = segArray[i].getHandleOut();
|
handleOutArray[i] = segArray[i].getHandleOut();
|
||||||
}
|
}
|
||||||
var exp = this;
|
var exp = this;
|
||||||
var type = exp._determineType(path, segArray, pointArray, handleInArray, handleOutArray);
|
type = exp._determineType(path, segArray, pointArray, handleInArray, handleOutArray);
|
||||||
}
|
}
|
||||||
//switch statement that determines what type of SVG element to add to the SVG Object
|
//switch statement that determines what type of SVG element to add to the SVG Object
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
|
|
@ -39,7 +39,7 @@ var ImportSvg = this.ImportSvg = Base.extend(/** @Lends ImportSvg# */{
|
||||||
* @param {SVG DOM} svg An SVG DOM object with parameters
|
* @param {SVG DOM} svg An SVG DOM object with parameters
|
||||||
* @return {item} A Paper.js layer
|
* @return {item} A Paper.js layer
|
||||||
*/
|
*/
|
||||||
importSVG: function(svg) {
|
importSvg: function(svg) {
|
||||||
var item;
|
var item;
|
||||||
var symbol;
|
var symbol;
|
||||||
switch (svg.nodeName.toLowerCase()) {
|
switch (svg.nodeName.toLowerCase()) {
|
||||||
|
@ -78,9 +78,8 @@ var ImportSvg = this.ImportSvg = Base.extend(/** @Lends ImportSvg# */{
|
||||||
// Not supported yet.
|
// Not supported yet.
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item) {
|
if (item)
|
||||||
this._importAttributesAndStyles(svg, item);
|
this._importAttributesAndStyles(svg, item);
|
||||||
}
|
|
||||||
|
|
||||||
return item;
|
return item;
|
||||||
},
|
},
|
||||||
|
@ -101,14 +100,12 @@ var ImportSvg = this.ImportSvg = Base.extend(/** @Lends ImportSvg# */{
|
||||||
var child;
|
var child;
|
||||||
for (var i in svg.childNodes) {
|
for (var i in svg.childNodes) {
|
||||||
child = svg.childNodes[i];
|
child = svg.childNodes[i];
|
||||||
if (child.nodeType != 1) {
|
if (child.nodeType != 1)
|
||||||
continue;
|
continue;
|
||||||
}
|
item = this.importSvg(child);
|
||||||
item = this.importSVG(child);
|
if (item)
|
||||||
if (item) {
|
|
||||||
group.addChild(item);
|
group.addChild(item);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return group;
|
return group;
|
||||||
},
|
},
|
||||||
|
@ -554,7 +551,6 @@ var ImportSvg = this.ImportSvg = Base.extend(/** @Lends ImportSvg# */{
|
||||||
break;
|
break;
|
||||||
case SVGTransform.SVG_TRANSFORM_SCALE:
|
case SVGTransform.SVG_TRANSFORM_SCALE:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
//Compensate for SVG's theta rotation going the opposite direction
|
//Compensate for SVG's theta rotation going the opposite direction
|
||||||
case SVGTransform.SVG_TRANSFORM_MATRIX:
|
case SVGTransform.SVG_TRANSFORM_MATRIX:
|
||||||
var temp = transformMatrix.getShearX();
|
var temp = transformMatrix.getShearX();
|
||||||
|
|
|
@ -31,7 +31,7 @@ test('make an svg line', function() {
|
||||||
shape.setAttribute('y2', y2);
|
shape.setAttribute('y2', y2);
|
||||||
|
|
||||||
var isvg = new ImportSvg();
|
var isvg = new ImportSvg();
|
||||||
var importedLine = isvg.importSVG(shape);
|
var importedLine = isvg.importSvg(shape);
|
||||||
|
|
||||||
var line = new Path.Line([x1, y1], [x2, y2]);
|
var line = new Path.Line([x1, y1], [x2, y2]);
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ test('make an svg line with invalid values', function() {
|
||||||
shape.setAttribute('y2', null);
|
shape.setAttribute('y2', null);
|
||||||
|
|
||||||
var isvg = new ImportSvg();
|
var isvg = new ImportSvg();
|
||||||
var importedLine = isvg.importSVG(shape);
|
var importedLine = isvg.importSvg(shape);
|
||||||
|
|
||||||
var line = new Path.Line([0, 0], [0, 0]);
|
var line = new Path.Line([0, 0], [0, 0]);
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ test('compare rectangle values', function() {
|
||||||
shape.setAttribute('height', height);
|
shape.setAttribute('height', height);
|
||||||
|
|
||||||
var isvg = new ImportSvg();
|
var isvg = new ImportSvg();
|
||||||
var importedRectangle = isvg.importSVG(shape);
|
var importedRectangle = isvg.importSvg(shape);
|
||||||
|
|
||||||
var topLeft = new Point(x, y);
|
var topLeft = new Point(x, y);
|
||||||
var size = new Size(width, height);
|
var size = new Size(width, height);
|
||||||
|
@ -92,7 +92,7 @@ test('compare negative rectangle values', function() {
|
||||||
shape.setAttribute('height', height);
|
shape.setAttribute('height', height);
|
||||||
|
|
||||||
var isvg = new ImportSvg();
|
var isvg = new ImportSvg();
|
||||||
var importedRectangle = isvg.importSVG(shape);
|
var importedRectangle = isvg.importSvg(shape);
|
||||||
var topLeft = new Point(x, y);
|
var topLeft = new Point(x, y);
|
||||||
var size = new Size(width, height);
|
var size = new Size(width, height);
|
||||||
var rectangle = new Rectangle(topLeft, size);
|
var rectangle = new Rectangle(topLeft, size);
|
||||||
|
@ -112,7 +112,7 @@ test('compare invalid rectangle values', function() {
|
||||||
shape.setAttribute('height', null);
|
shape.setAttribute('height', null);
|
||||||
|
|
||||||
var isvg = new ImportSvg();
|
var isvg = new ImportSvg();
|
||||||
var importedRectangle = isvg.importSVG(shape);
|
var importedRectangle = isvg.importSvg(shape);
|
||||||
|
|
||||||
var topLeft = new Point(0, 0);
|
var topLeft = new Point(0, 0);
|
||||||
var size = new Size(0, 0);
|
var size = new Size(0, 0);
|
||||||
|
@ -139,7 +139,7 @@ test('compare round rectangle values', function() {
|
||||||
shape.setAttribute('height', height);
|
shape.setAttribute('height', height);
|
||||||
|
|
||||||
var isvg = new ImportSvg();
|
var isvg = new ImportSvg();
|
||||||
var importedRectangle = isvg.importSVG(shape);
|
var importedRectangle = isvg.importSvg(shape);
|
||||||
|
|
||||||
var topLeft = new Point(x, y);
|
var topLeft = new Point(x, y);
|
||||||
var size = new Size(width, height);
|
var size = new Size(width, height);
|
||||||
|
@ -167,7 +167,7 @@ test('compare negative round rectangle values', function() {
|
||||||
shape.setAttribute('height', height);
|
shape.setAttribute('height', height);
|
||||||
|
|
||||||
var isvg = new ImportSvg();
|
var isvg = new ImportSvg();
|
||||||
var importedRectangle = isvg.importSVG(shape);
|
var importedRectangle = isvg.importSvg(shape);
|
||||||
|
|
||||||
var topLeft = new Point(x, y);
|
var topLeft = new Point(x, y);
|
||||||
var size = new Size(width, height);
|
var size = new Size(width, height);
|
||||||
|
@ -195,7 +195,7 @@ test('compare invalid round rectangle values', function() {
|
||||||
shape.setAttribute('height', height);
|
shape.setAttribute('height', height);
|
||||||
|
|
||||||
var isvg = new ImportSvg();
|
var isvg = new ImportSvg();
|
||||||
var importedRectangle = isvg.importSVG(shape);
|
var importedRectangle = isvg.importSvg(shape);
|
||||||
|
|
||||||
var topLeft = new Point(x, y);
|
var topLeft = new Point(x, y);
|
||||||
var size = new Size(width, height);
|
var size = new Size(width, height);
|
||||||
|
@ -219,7 +219,7 @@ test('compare oval values', function() {
|
||||||
shape.setAttribute('ry', ry);
|
shape.setAttribute('ry', ry);
|
||||||
|
|
||||||
var isvg = new ImportSvg();
|
var isvg = new ImportSvg();
|
||||||
var importedOval = isvg.importSVG(shape);
|
var importedOval = isvg.importSvg(shape);
|
||||||
|
|
||||||
var center = new Point(cx, cy);
|
var center = new Point(cx, cy);
|
||||||
var offset = new Point(rx, ry);
|
var offset = new Point(rx, ry);
|
||||||
|
@ -247,7 +247,7 @@ test('compare negative oval values', function() {
|
||||||
shape.setAttribute('ry', ry);
|
shape.setAttribute('ry', ry);
|
||||||
|
|
||||||
var isvg = new ImportSvg();
|
var isvg = new ImportSvg();
|
||||||
var importedOval = isvg.importSVG(shape);
|
var importedOval = isvg.importSvg(shape);
|
||||||
|
|
||||||
var center = new Point(cx, cy);
|
var center = new Point(cx, cy);
|
||||||
var offset = new Point(rx, ry);
|
var offset = new Point(rx, ry);
|
||||||
|
@ -270,7 +270,7 @@ test('compare invalid oval values', function() {
|
||||||
shape.setAttribute('ry', null);
|
shape.setAttribute('ry', null);
|
||||||
|
|
||||||
var isvg = new ImportSvg();
|
var isvg = new ImportSvg();
|
||||||
var importedOval = isvg.importSVG(shape);
|
var importedOval = isvg.importSvg(shape);
|
||||||
|
|
||||||
var center = new Point(0, 0);
|
var center = new Point(0, 0);
|
||||||
var offset = new Point(0, 0);
|
var offset = new Point(0, 0);
|
||||||
|
@ -295,7 +295,7 @@ test('compare circle values', function() {
|
||||||
shape.setAttribute('r', r);
|
shape.setAttribute('r', r);
|
||||||
|
|
||||||
var isvg = new ImportSvg();
|
var isvg = new ImportSvg();
|
||||||
var importedCircle = isvg.importSVG(shape);
|
var importedCircle = isvg.importSvg(shape);
|
||||||
|
|
||||||
var center = new Point(cx, cy);
|
var center = new Point(cx, cy);
|
||||||
var circle = new Path.Circle(center, r);
|
var circle = new Path.Circle(center, r);
|
||||||
|
@ -315,7 +315,7 @@ test('compare negative circle values', function() {
|
||||||
shape.setAttribute('r', r);
|
shape.setAttribute('r', r);
|
||||||
|
|
||||||
var isvg = new ImportSvg();
|
var isvg = new ImportSvg();
|
||||||
var importedCircle = isvg.importSVG(shape);
|
var importedCircle = isvg.importSvg(shape);
|
||||||
|
|
||||||
var center = new Point(cx, cy);
|
var center = new Point(cx, cy);
|
||||||
var circle = new Path.Circle(center, r);
|
var circle = new Path.Circle(center, r);
|
||||||
|
@ -333,7 +333,7 @@ test('compare invalid circle values', function() {
|
||||||
shape.setAttribute('r', null);
|
shape.setAttribute('r', null);
|
||||||
|
|
||||||
var isvg = new ImportSvg();
|
var isvg = new ImportSvg();
|
||||||
var importedCircle = isvg.importSVG(shape);
|
var importedCircle = isvg.importSvg(shape);
|
||||||
|
|
||||||
var center = new Point(0, 0);
|
var center = new Point(0, 0);
|
||||||
var circle = new Path.Circle(center, 0);
|
var circle = new Path.Circle(center, 0);
|
||||||
|
@ -349,7 +349,7 @@ test('compare polygon values', function() {
|
||||||
shape.setAttribute('points', svgpoints);
|
shape.setAttribute('points', svgpoints);
|
||||||
|
|
||||||
var isvg = new ImportSvg();
|
var isvg = new ImportSvg();
|
||||||
var importedPolygon = isvg.importSVG(shape);
|
var importedPolygon = isvg.importSvg(shape);
|
||||||
|
|
||||||
var poly = new Path();
|
var poly = new Path();
|
||||||
var points = shape.points;
|
var points = shape.points;
|
||||||
|
@ -376,7 +376,7 @@ test('compare negative polygon values', function() {
|
||||||
shape.setAttribute('points', svgpoints);
|
shape.setAttribute('points', svgpoints);
|
||||||
|
|
||||||
var isvg = new ImportSvg();
|
var isvg = new ImportSvg();
|
||||||
var importedPolygon = isvg.importSVG(shape);
|
var importedPolygon = isvg.importSvg(shape);
|
||||||
|
|
||||||
var poly = new Path();
|
var poly = new Path();
|
||||||
var points = shape.points;
|
var points = shape.points;
|
||||||
|
@ -403,7 +403,7 @@ test('compare polyline values', function() {
|
||||||
shape.setAttribute('points', svgpoints);
|
shape.setAttribute('points', svgpoints);
|
||||||
|
|
||||||
var isvg = new ImportSvg();
|
var isvg = new ImportSvg();
|
||||||
var importedPolyline = isvg.importSVG(shape);
|
var importedPolyline = isvg.importSvg(shape);
|
||||||
|
|
||||||
var poly = new Path();
|
var poly = new Path();
|
||||||
var points = shape.points;
|
var points = shape.points;
|
||||||
|
@ -430,7 +430,7 @@ test('compare polyline values', function() {
|
||||||
shape.setAttribute('points', svgpoints);
|
shape.setAttribute('points', svgpoints);
|
||||||
|
|
||||||
var isvg = new ImportSvg();
|
var isvg = new ImportSvg();
|
||||||
var importedPolyline = isvg.importSVG(shape);
|
var importedPolyline = isvg.importSvg(shape);
|
||||||
|
|
||||||
var poly = new Path();
|
var poly = new Path();
|
||||||
var points = shape.points;
|
var points = shape.points;
|
||||||
|
|
Loading…
Reference in a new issue