mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -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,
|
||||
// strokeCap: 'round'
|
||||
};
|
||||
var isvg = new ImportSvg;
|
||||
isvg.importSVG(document.getElementById('svg'));
|
||||
var isvg = new ImportSvg();
|
||||
isvg.importSvg(document.getElementById('svg'));
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
|
|
@ -11,8 +11,8 @@
|
|||
// strokeWidth: 2,
|
||||
// strokeCap: 'round'
|
||||
};
|
||||
var isvg = new ImportSvg;
|
||||
isvg.importSVG(document.getElementById('svg'));
|
||||
var isvg = new ImportSvg();
|
||||
isvg.importSvg(document.getElementById('svg'));
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
|
|
@ -11,8 +11,8 @@
|
|||
// strokeWidth: 2,
|
||||
// strokeCap: 'round'
|
||||
};
|
||||
var isvg = new ImportSvg;
|
||||
isvg.importSVG(document.getElementById('svg'));
|
||||
var isvg = new ImportSvg();
|
||||
isvg.importSvg(document.getElementById('svg'));
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
|
|
@ -11,8 +11,8 @@
|
|||
// strokeWidth: 2,
|
||||
// strokeCap: 'round'
|
||||
};
|
||||
var isvg = new ImportSvg;
|
||||
isvg.importSVG(document.getElementById('svg'));
|
||||
var isvg = new ImportSvg();
|
||||
isvg.importSvg(document.getElementById('svg'));
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
|
|
@ -12,8 +12,8 @@
|
|||
// strokeWidth: 2,
|
||||
// strokeCap: 'round'
|
||||
};
|
||||
var isvg = new ImportSvg;
|
||||
isvg.importSVG(document.getElementById('svg'));
|
||||
var isvg = new ImportSvg();
|
||||
isvg.importSvg(document.getElementById('svg'));
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
|
|
@ -11,8 +11,8 @@
|
|||
// strokeWidth: 2,
|
||||
// strokeCap: 'round'
|
||||
};
|
||||
var isvg = new ImportSvg;
|
||||
isvg.importSVG(document.getElementById('svg'));
|
||||
var isvg = new ImportSvg();
|
||||
isvg.importSvg(document.getElementById('svg'));
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
|
|
@ -11,8 +11,8 @@
|
|||
// strokeWidth: 2,
|
||||
// strokeCap: 'round'
|
||||
};
|
||||
var isvg = new ImportSvg;
|
||||
isvg.importSVG(document.getElementById('svg'));
|
||||
var isvg = new ImportSvg();
|
||||
isvg.importSvg(document.getElementById('svg'));
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
|
|
@ -11,8 +11,8 @@
|
|||
// strokeWidth: 2,
|
||||
// strokeCap: 'round'
|
||||
};
|
||||
var isvg = new ImportSvg;
|
||||
isvg.importSVG(document.getElementById('svg'));
|
||||
var isvg = new ImportSvg();
|
||||
isvg.importSvg(document.getElementById('svg'));
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
|
|
@ -11,8 +11,8 @@
|
|||
// strokeWidth: 2,
|
||||
// strokeCap: 'round'
|
||||
};
|
||||
var isvg = new ImportSvg;
|
||||
isvg.importSVG(document.getElementById('svg'));
|
||||
var isvg = new ImportSvg();
|
||||
isvg.importSvg(document.getElementById('svg'));
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
|
|
@ -111,6 +111,7 @@ var ExportSvg = this.ExportSvg = Base.extend(/** @Lends ExportSvg# */{
|
|||
var pointArray;
|
||||
var handleInArray;
|
||||
var handleOutArray;
|
||||
var type;
|
||||
//finding the type of path to export
|
||||
if (path.content) {
|
||||
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
|
||||
// text does not have these values
|
||||
segArray = path.getSegments();
|
||||
pointArray = new Array();
|
||||
handleInArray = new Array();
|
||||
handleOutArray = new Array();
|
||||
pointArray = [];
|
||||
handleInArray = [];
|
||||
handleOutArray = [];
|
||||
for (i = 0; i < segArray.length; i++) {
|
||||
pointArray[i] = segArray[i].getPoint();
|
||||
handleInArray[i] = segArray[i].getHandleIn();
|
||||
handleOutArray[i] = segArray[i].getHandleOut();
|
||||
}
|
||||
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 (type) {
|
||||
|
|
|
@ -39,7 +39,7 @@ var ImportSvg = this.ImportSvg = Base.extend(/** @Lends ImportSvg# */{
|
|||
* @param {SVG DOM} svg An SVG DOM object with parameters
|
||||
* @return {item} A Paper.js layer
|
||||
*/
|
||||
importSVG: function(svg) {
|
||||
importSvg: function(svg) {
|
||||
var item;
|
||||
var symbol;
|
||||
switch (svg.nodeName.toLowerCase()) {
|
||||
|
@ -78,9 +78,8 @@ var ImportSvg = this.ImportSvg = Base.extend(/** @Lends ImportSvg# */{
|
|||
// Not supported yet.
|
||||
}
|
||||
|
||||
if (item) {
|
||||
if (item)
|
||||
this._importAttributesAndStyles(svg, item);
|
||||
}
|
||||
|
||||
return item;
|
||||
},
|
||||
|
@ -101,14 +100,12 @@ var ImportSvg = this.ImportSvg = Base.extend(/** @Lends ImportSvg# */{
|
|||
var child;
|
||||
for (var i in svg.childNodes) {
|
||||
child = svg.childNodes[i];
|
||||
if (child.nodeType != 1) {
|
||||
if (child.nodeType != 1)
|
||||
continue;
|
||||
}
|
||||
item = this.importSVG(child);
|
||||
if (item) {
|
||||
item = this.importSvg(child);
|
||||
if (item)
|
||||
group.addChild(item);
|
||||
}
|
||||
}
|
||||
|
||||
return group;
|
||||
},
|
||||
|
@ -554,7 +551,6 @@ var ImportSvg = this.ImportSvg = Base.extend(/** @Lends ImportSvg# */{
|
|||
break;
|
||||
case SVGTransform.SVG_TRANSFORM_SCALE:
|
||||
break;
|
||||
|
||||
//Compensate for SVG's theta rotation going the opposite direction
|
||||
case SVGTransform.SVG_TRANSFORM_MATRIX:
|
||||
var temp = transformMatrix.getShearX();
|
||||
|
|
|
@ -31,7 +31,7 @@ test('make an svg line', function() {
|
|||
shape.setAttribute('y2', y2);
|
||||
|
||||
var isvg = new ImportSvg();
|
||||
var importedLine = isvg.importSVG(shape);
|
||||
var importedLine = isvg.importSvg(shape);
|
||||
|
||||
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);
|
||||
|
||||
var isvg = new ImportSvg();
|
||||
var importedLine = isvg.importSVG(shape);
|
||||
var importedLine = isvg.importSvg(shape);
|
||||
|
||||
var line = new Path.Line([0, 0], [0, 0]);
|
||||
|
||||
|
@ -68,7 +68,7 @@ test('compare rectangle values', function() {
|
|||
shape.setAttribute('height', height);
|
||||
|
||||
var isvg = new ImportSvg();
|
||||
var importedRectangle = isvg.importSVG(shape);
|
||||
var importedRectangle = isvg.importSvg(shape);
|
||||
|
||||
var topLeft = new Point(x, y);
|
||||
var size = new Size(width, height);
|
||||
|
@ -92,7 +92,7 @@ test('compare negative rectangle values', function() {
|
|||
shape.setAttribute('height', height);
|
||||
|
||||
var isvg = new ImportSvg();
|
||||
var importedRectangle = isvg.importSVG(shape);
|
||||
var importedRectangle = isvg.importSvg(shape);
|
||||
var topLeft = new Point(x, y);
|
||||
var size = new Size(width, height);
|
||||
var rectangle = new Rectangle(topLeft, size);
|
||||
|
@ -112,7 +112,7 @@ test('compare invalid rectangle values', function() {
|
|||
shape.setAttribute('height', null);
|
||||
|
||||
var isvg = new ImportSvg();
|
||||
var importedRectangle = isvg.importSVG(shape);
|
||||
var importedRectangle = isvg.importSvg(shape);
|
||||
|
||||
var topLeft = new Point(0, 0);
|
||||
var size = new Size(0, 0);
|
||||
|
@ -139,7 +139,7 @@ test('compare round rectangle values', function() {
|
|||
shape.setAttribute('height', height);
|
||||
|
||||
var isvg = new ImportSvg();
|
||||
var importedRectangle = isvg.importSVG(shape);
|
||||
var importedRectangle = isvg.importSvg(shape);
|
||||
|
||||
var topLeft = new Point(x, y);
|
||||
var size = new Size(width, height);
|
||||
|
@ -167,7 +167,7 @@ test('compare negative round rectangle values', function() {
|
|||
shape.setAttribute('height', height);
|
||||
|
||||
var isvg = new ImportSvg();
|
||||
var importedRectangle = isvg.importSVG(shape);
|
||||
var importedRectangle = isvg.importSvg(shape);
|
||||
|
||||
var topLeft = new Point(x, y);
|
||||
var size = new Size(width, height);
|
||||
|
@ -195,7 +195,7 @@ test('compare invalid round rectangle values', function() {
|
|||
shape.setAttribute('height', height);
|
||||
|
||||
var isvg = new ImportSvg();
|
||||
var importedRectangle = isvg.importSVG(shape);
|
||||
var importedRectangle = isvg.importSvg(shape);
|
||||
|
||||
var topLeft = new Point(x, y);
|
||||
var size = new Size(width, height);
|
||||
|
@ -219,7 +219,7 @@ test('compare oval values', function() {
|
|||
shape.setAttribute('ry', ry);
|
||||
|
||||
var isvg = new ImportSvg();
|
||||
var importedOval = isvg.importSVG(shape);
|
||||
var importedOval = isvg.importSvg(shape);
|
||||
|
||||
var center = new Point(cx, cy);
|
||||
var offset = new Point(rx, ry);
|
||||
|
@ -247,7 +247,7 @@ test('compare negative oval values', function() {
|
|||
shape.setAttribute('ry', ry);
|
||||
|
||||
var isvg = new ImportSvg();
|
||||
var importedOval = isvg.importSVG(shape);
|
||||
var importedOval = isvg.importSvg(shape);
|
||||
|
||||
var center = new Point(cx, cy);
|
||||
var offset = new Point(rx, ry);
|
||||
|
@ -270,7 +270,7 @@ test('compare invalid oval values', function() {
|
|||
shape.setAttribute('ry', null);
|
||||
|
||||
var isvg = new ImportSvg();
|
||||
var importedOval = isvg.importSVG(shape);
|
||||
var importedOval = isvg.importSvg(shape);
|
||||
|
||||
var center = new Point(0, 0);
|
||||
var offset = new Point(0, 0);
|
||||
|
@ -295,7 +295,7 @@ test('compare circle values', function() {
|
|||
shape.setAttribute('r', r);
|
||||
|
||||
var isvg = new ImportSvg();
|
||||
var importedCircle = isvg.importSVG(shape);
|
||||
var importedCircle = isvg.importSvg(shape);
|
||||
|
||||
var center = new Point(cx, cy);
|
||||
var circle = new Path.Circle(center, r);
|
||||
|
@ -315,7 +315,7 @@ test('compare negative circle values', function() {
|
|||
shape.setAttribute('r', r);
|
||||
|
||||
var isvg = new ImportSvg();
|
||||
var importedCircle = isvg.importSVG(shape);
|
||||
var importedCircle = isvg.importSvg(shape);
|
||||
|
||||
var center = new Point(cx, cy);
|
||||
var circle = new Path.Circle(center, r);
|
||||
|
@ -333,7 +333,7 @@ test('compare invalid circle values', function() {
|
|||
shape.setAttribute('r', null);
|
||||
|
||||
var isvg = new ImportSvg();
|
||||
var importedCircle = isvg.importSVG(shape);
|
||||
var importedCircle = isvg.importSvg(shape);
|
||||
|
||||
var center = new Point(0, 0);
|
||||
var circle = new Path.Circle(center, 0);
|
||||
|
@ -349,7 +349,7 @@ test('compare polygon values', function() {
|
|||
shape.setAttribute('points', svgpoints);
|
||||
|
||||
var isvg = new ImportSvg();
|
||||
var importedPolygon = isvg.importSVG(shape);
|
||||
var importedPolygon = isvg.importSvg(shape);
|
||||
|
||||
var poly = new Path();
|
||||
var points = shape.points;
|
||||
|
@ -376,7 +376,7 @@ test('compare negative polygon values', function() {
|
|||
shape.setAttribute('points', svgpoints);
|
||||
|
||||
var isvg = new ImportSvg();
|
||||
var importedPolygon = isvg.importSVG(shape);
|
||||
var importedPolygon = isvg.importSvg(shape);
|
||||
|
||||
var poly = new Path();
|
||||
var points = shape.points;
|
||||
|
@ -403,7 +403,7 @@ test('compare polyline values', function() {
|
|||
shape.setAttribute('points', svgpoints);
|
||||
|
||||
var isvg = new ImportSvg();
|
||||
var importedPolyline = isvg.importSVG(shape);
|
||||
var importedPolyline = isvg.importSvg(shape);
|
||||
|
||||
var poly = new Path();
|
||||
var points = shape.points;
|
||||
|
@ -430,7 +430,7 @@ test('compare polyline values', function() {
|
|||
shape.setAttribute('points', svgpoints);
|
||||
|
||||
var isvg = new ImportSvg();
|
||||
var importedPolyline = isvg.importSVG(shape);
|
||||
var importedPolyline = isvg.importSvg(shape);
|
||||
|
||||
var poly = new Path();
|
||||
var points = shape.points;
|
||||
|
|
Loading…
Reference in a new issue