From 88e6ac09d754effe0ac7750c37f3b41dd04b5aa2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Tue, 6 Nov 2012 12:49:12 -0800 Subject: [PATCH] Add methods to Item and Project to directly use SvgImporter / Exporter functionality. --- examples/SVG Export/Circle Testing.html | 9 ++--- examples/SVG Export/Empty Path Testing.html | 9 ++--- examples/SVG Export/Line Testing.html | 9 ++--- examples/SVG Export/Random Path Testing.html | 9 ++--- .../Rect and Attribute Testing.html | 9 ++--- examples/SVG Export/Rotated Primitives.html | 8 ++--- examples/SVG Export/Text Testing.html | 8 ++--- examples/SVG Export/Transform Test 1.html | 9 ++--- examples/SVG Export/Transform Test 2.html | 9 ++--- .../Circle and Ellipse Testing.html | 7 +--- examples/SVG Import/Line Testing.html | 7 +--- .../SVG Import/Multiple Paths Test 1.html | 7 +--- .../SVG Import/Multiple Paths Test 2.html | 7 +--- examples/SVG Import/Nested Groups Test.html | 7 +--- examples/SVG Import/Rect Testing.html | 7 +--- examples/SVG Import/Testing.html | 7 +--- examples/SVG Import/Text Testing.html | 7 +--- examples/SVG Import/Transform Testing.html | 7 +--- src/svg/SvgExporter.js | 12 +++++++ src/svg/SvgImporter.js | 13 +++++++ test/tests/SvgImporter.js | 36 +++++++++---------- 21 files changed, 71 insertions(+), 132 deletions(-) diff --git a/examples/SVG Export/Circle Testing.html b/examples/SVG Export/Circle Testing.html index 4959e0a2..a3b46560 100644 --- a/examples/SVG Export/Circle Testing.html +++ b/examples/SVG Export/Circle Testing.html @@ -25,13 +25,8 @@ var path = new Path.Circle(new Point(50, 50), 25); path.fillColor = 'red'; - var output = SvgExporter.exportProject(project); - console.log(output); - var test = document.getElementById('svg') - test.innerHTML = ""; - test.appendChild (output); + document.getElementById('svg').appendChild(project.exportSvg()); - - + \ No newline at end of file diff --git a/examples/SVG Export/Empty Path Testing.html b/examples/SVG Export/Empty Path Testing.html index c204324d..7698f7f5 100644 --- a/examples/SVG Export/Empty Path Testing.html +++ b/examples/SVG Export/Empty Path Testing.html @@ -19,13 +19,8 @@ var path2 = new Path(segments); path2.strokeColor = 'yellow'; - var output = SvgExporter.exportProject(project); - console.log(output); - var test = document.getElementById('svg') - test.innerHTML = ""; - test.appendChild (output); + document.getElementById('svg').appendChild(project.exportSvg()); - - + \ No newline at end of file diff --git a/examples/SVG Export/Line Testing.html b/examples/SVG Export/Line Testing.html index c6771693..dd95b7cb 100644 --- a/examples/SVG Export/Line Testing.html +++ b/examples/SVG Export/Line Testing.html @@ -34,13 +34,8 @@ line3.strokeColor = "yellow"; line3.strokeWidth = "5"; - var output = SvgExporter.exportProject(project); - console.log(output); - var test = document.getElementById('svg') - test.innerHTML = ""; - test.appendChild(output); + document.getElementById('svg').appendChild(project.exportSvg()); - - + \ No newline at end of file diff --git a/examples/SVG Export/Random Path Testing.html b/examples/SVG Export/Random Path Testing.html index bb82be40..3eac0188 100644 --- a/examples/SVG Export/Random Path Testing.html +++ b/examples/SVG Export/Random Path Testing.html @@ -32,13 +32,8 @@ var path = new Path.Star(center, points, radius1, radius2); path.fillColor = 'black'; - var output = SvgExporter.exportProject(project); - console.log(output); - var test = document.getElementById('svg') - test.innerHTML = ""; - test.appendChild(output); + document.getElementById('svg').appendChild(project.exportSvg()); - - + \ No newline at end of file diff --git a/examples/SVG Export/Rect and Attribute Testing.html b/examples/SVG Export/Rect and Attribute Testing.html index cee27ebb..22fe3791 100644 --- a/examples/SVG Export/Rect and Attribute Testing.html +++ b/examples/SVG Export/Rect and Attribute Testing.html @@ -46,13 +46,8 @@ path4.strokeColor= 'yellow'; path4.fillColor='purple'; - var output = SvgExporter.exportProject(project); - console.log(output); - var test = document.getElementById('svg') - test.innerHTML = ""; - test.appendChild(output); + document.getElementById('svg').appendChild(project.exportSvg()); - - + \ No newline at end of file diff --git a/examples/SVG Export/Rotated Primitives.html b/examples/SVG Export/Rotated Primitives.html index 50fcf890..7ebb72c6 100644 --- a/examples/SVG Export/Rotated Primitives.html +++ b/examples/SVG Export/Rotated Primitives.html @@ -34,12 +34,8 @@ rect.fillColor = 'yellow'; rect.rotate(-20); - var output = SvgExporter.exportProject(project); - var test = document.getElementById('svg') - test.innerHTML = ""; - test.appendChild (output); + document.getElementById('svg').appendChild(project.exportSvg()); - - + \ No newline at end of file diff --git a/examples/SVG Export/Text Testing.html b/examples/SVG Export/Text Testing.html index 1802df10..e9aa835b 100644 --- a/examples/SVG Export/Text Testing.html +++ b/examples/SVG Export/Text Testing.html @@ -38,12 +38,8 @@ c.fillColor = colors[i]; } - var output = SvgExporter.exportProject(project); - var test = document.getElementById('svg') - test.innerHTML = ""; - test.appendChild (output); + document.getElementById('svg').appendChild(project.exportSvg()); - - + \ No newline at end of file diff --git a/examples/SVG Export/Transform Test 1.html b/examples/SVG Export/Transform Test 1.html index ebdf5db3..fc5db0e3 100644 --- a/examples/SVG Export/Transform Test 1.html +++ b/examples/SVG Export/Transform Test 1.html @@ -22,13 +22,8 @@ clonedPath.rotate(angle * i, circlePath.bounds.topLeft); }; - var output = SvgExporter.exportProject(project); - console.log(output); - var test = document.getElementById('svg') - test.innerHTML = ""; - test.appendChild (output); + document.getElementById('svg').appendChild(project.exportSvg()); - - + \ No newline at end of file diff --git a/examples/SVG Export/Transform Test 2.html b/examples/SVG Export/Transform Test 2.html index 727990dc..dcfdd966 100644 --- a/examples/SVG Export/Transform Test 2.html +++ b/examples/SVG Export/Transform Test 2.html @@ -19,12 +19,9 @@ copy.strokeColor = 'red'; copy.rotate(-45); copy.scale(0.5); - var output = SvgExporter.exportProject(project); - var test = document.getElementById('svg') - test.innerHTML = ""; - test.appendChild (output); + + document.getElementById('svg').appendChild(project.exportSvg()); - - + \ No newline at end of file diff --git a/examples/SVG Import/Circle and Ellipse Testing.html b/examples/SVG Import/Circle and Ellipse Testing.html index a0532011..b214dcfb 100644 --- a/examples/SVG Import/Circle and Ellipse Testing.html +++ b/examples/SVG Import/Circle and Ellipse Testing.html @@ -6,12 +6,7 @@ diff --git a/examples/SVG Import/Line Testing.html b/examples/SVG Import/Line Testing.html index f6de53a9..1580f94e 100644 --- a/examples/SVG Import/Line Testing.html +++ b/examples/SVG Import/Line Testing.html @@ -6,12 +6,7 @@ diff --git a/examples/SVG Import/Multiple Paths Test 1.html b/examples/SVG Import/Multiple Paths Test 1.html index 5dc40663..3afaa70c 100644 --- a/examples/SVG Import/Multiple Paths Test 1.html +++ b/examples/SVG Import/Multiple Paths Test 1.html @@ -6,12 +6,7 @@ diff --git a/examples/SVG Import/Multiple Paths Test 2.html b/examples/SVG Import/Multiple Paths Test 2.html index 8e76110e..a5fc0007 100644 --- a/examples/SVG Import/Multiple Paths Test 2.html +++ b/examples/SVG Import/Multiple Paths Test 2.html @@ -6,12 +6,7 @@ diff --git a/examples/SVG Import/Nested Groups Test.html b/examples/SVG Import/Nested Groups Test.html index 21724315..2dd81a1f 100644 --- a/examples/SVG Import/Nested Groups Test.html +++ b/examples/SVG Import/Nested Groups Test.html @@ -6,12 +6,7 @@ diff --git a/examples/SVG Import/Rect Testing.html b/examples/SVG Import/Rect Testing.html index fc41948b..aa4db2f0 100644 --- a/examples/SVG Import/Rect Testing.html +++ b/examples/SVG Import/Rect Testing.html @@ -6,12 +6,7 @@ diff --git a/examples/SVG Import/Testing.html b/examples/SVG Import/Testing.html index 537d9252..c15762b2 100644 --- a/examples/SVG Import/Testing.html +++ b/examples/SVG Import/Testing.html @@ -6,12 +6,7 @@ diff --git a/examples/SVG Import/Text Testing.html b/examples/SVG Import/Text Testing.html index 1f574f63..16385370 100644 --- a/examples/SVG Import/Text Testing.html +++ b/examples/SVG Import/Text Testing.html @@ -6,12 +6,7 @@ diff --git a/examples/SVG Import/Transform Testing.html b/examples/SVG Import/Transform Testing.html index a74d8786..c6ccc736 100644 --- a/examples/SVG Import/Transform Testing.html +++ b/examples/SVG Import/Transform Testing.html @@ -6,12 +6,7 @@ diff --git a/src/svg/SvgExporter.js b/src/svg/SvgExporter.js index ec49241d..586a9187 100644 --- a/src/svg/SvgExporter.js +++ b/src/svg/SvgExporter.js @@ -392,3 +392,15 @@ var SvgExporter = this.SvgExporter = new function() { } }; }; + +Item.inject({ + exportSvg: function() { + return SvgExporter.exportItem(this); + } +}); + +Project.inject({ + exportSvg: function() { + return SvgExporter.exportProject(this); + } +}); diff --git a/src/svg/SvgImporter.js b/src/svg/SvgImporter.js index b8682389..a4384211 100644 --- a/src/svg/SvgImporter.js +++ b/src/svg/SvgImporter.js @@ -435,3 +435,16 @@ var SvgImporter = this.SvgImporter = new function() { } }; }; + +Item.inject({ + importSvg: function(svg) { + return this.addChild(SvgExporter.importSvg(svg)); + } +}); + +Project.inject({ + importSvg: function(svg) { + this.activate(); + return SvgImporter.importSvg(svg); + } +}); diff --git a/test/tests/SvgImporter.js b/test/tests/SvgImporter.js index 3bf21b37..4d3c3374 100644 --- a/test/tests/SvgImporter.js +++ b/test/tests/SvgImporter.js @@ -30,7 +30,7 @@ test('make an svg line', function() { shape.setAttribute('x2', x2); shape.setAttribute('y2', y2); - var importedLine = SvgImporter.importSvg(shape); + var importedLine = project.importSvg(shape); var line = new Path.Line([x1, y1], [x2, y2]); @@ -45,7 +45,7 @@ test('make an svg line with invalid values', function() { shape.setAttribute('x2', null); shape.setAttribute('y2', null); - var importedLine = SvgImporter.importSvg(shape); + var importedLine = project.importSvg(shape); var line = new Path.Line([0, 0], [0, 0]); @@ -64,7 +64,7 @@ test('compare rectangle values', function() { shape.setAttribute('width', width); shape.setAttribute('height', height); - var importedRectangle = SvgImporter.importSvg(shape); + var importedRectangle = project.importSvg(shape); var topLeft = new Point(x, y); var size = new Size(width, height); @@ -87,7 +87,7 @@ test('compare negative rectangle values', function() { shape.setAttribute('width', width); shape.setAttribute('height', height); - var importedRectangle = SvgImporter.importSvg(shape); + var importedRectangle = project.importSvg(shape); var topLeft = new Point(x, y); var size = new Size(width, height); var rectangle = new Rectangle(topLeft, size); @@ -106,7 +106,7 @@ test('compare invalid rectangle values', function() { shape.setAttribute('width', null); shape.setAttribute('height', null); - var importedRectangle = SvgImporter.importSvg(shape); + var importedRectangle = project.importSvg(shape); var topLeft = new Point(0, 0); var size = new Size(0, 0); @@ -132,7 +132,7 @@ test('compare round rectangle values', function() { shape.setAttribute('width', width); shape.setAttribute('height', height); - var importedRectangle = SvgImporter.importSvg(shape); + var importedRectangle = project.importSvg(shape); var topLeft = new Point(x, y); var size = new Size(width, height); @@ -159,7 +159,7 @@ test('compare negative round rectangle values', function() { shape.setAttribute('width', width); shape.setAttribute('height', height); - var importedRectangle = SvgImporter.importSvg(shape); + var importedRectangle = project.importSvg(shape); var topLeft = new Point(x, y); var size = new Size(width, height); @@ -186,7 +186,7 @@ test('compare invalid round rectangle values', function() { shape.setAttribute('width', width); shape.setAttribute('height', height); - var importedRectangle = SvgImporter.importSvg(shape); + var importedRectangle = project.importSvg(shape); var topLeft = new Point(x, y); var size = new Size(width, height); @@ -209,7 +209,7 @@ test('compare ellipse values', function() { shape.setAttribute('rx', rx); shape.setAttribute('ry', ry); - var importedEllipse = SvgImporter.importSvg(shape); + var importedEllipse = project.importSvg(shape); var center = new Point(cx, cy); var offset = new Point(rx, ry); @@ -234,7 +234,7 @@ test('compare negative ellipse values', function() { shape.setAttribute('rx', rx); shape.setAttribute('ry', ry); - var importedEllipse = SvgImporter.importSvg(shape); + var importedEllipse = project.importSvg(shape); var center = new Point(cx, cy); var offset = new Point(rx, ry); @@ -255,7 +255,7 @@ test('compare invalid ellipse values', function() { shape.setAttribute('rx', null); shape.setAttribute('ry', null); - var importedEllipse = SvgImporter.importSvg(shape); + var importedEllipse = project.importSvg(shape); var center = new Point(0, 0); var offset = new Point(0, 0); @@ -278,7 +278,7 @@ test('compare circle values', function() { shape.setAttribute('cy', cy); shape.setAttribute('r', r); - var importedCircle = SvgImporter.importSvg(shape); + var importedCircle = project.importSvg(shape); var center = new Point(cx, cy); var circle = new Path.Circle(center, r); @@ -296,7 +296,7 @@ test('compare negative circle values', function() { shape.setAttribute('cy', cy); shape.setAttribute('r', r); - var importedCircle = SvgImporter.importSvg(shape); + var importedCircle = project.importSvg(shape); var center = new Point(cx, cy); var circle = new Path.Circle(center, r); @@ -312,7 +312,7 @@ test('compare invalid circle values', function() { shape.setAttribute('cy', null); shape.setAttribute('r', null); - var importedCircle = SvgImporter.importSvg(shape); + var importedCircle = project.importSvg(shape); var center = new Point(0, 0); var circle = new Path.Circle(center, 0); @@ -327,7 +327,7 @@ test('compare polygon values', function() { var svgpoints = "100,10 40,180 190,60 10,60 160,180"; shape.setAttribute('points', svgpoints); - var importedPolygon = SvgImporter.importSvg(shape); + var importedPolygon = project.importSvg(shape); var poly = new Path(); var points = shape.points; @@ -348,7 +348,7 @@ test('compare negative polygon values', function() { var svgpoints = "-100,-10 -40,-180 -190,-60 -10,-60 -160,-180"; shape.setAttribute('points', svgpoints); - var importedPolygon = SvgImporter.importSvg(shape); + var importedPolygon = project.importSvg(shape); var poly = new Path(); var points = shape.points; @@ -369,7 +369,7 @@ test('compare polyline values', function() { var svgpoints = "5,5 45,45 5,45 45,5"; shape.setAttribute('points', svgpoints); - var importedPolyline = SvgImporter.importSvg(shape); + var importedPolyline = project.importSvg(shape); var poly = new Path(); var points = shape.points; @@ -390,7 +390,7 @@ test('compare negative polyline values', function() { var svgpoints = "-5,-5 -45,-45 -5,-45 -45,-5"; shape.setAttribute('points', svgpoints); - var importedPolyline = SvgImporter.importSvg(shape); + var importedPolyline = project.importSvg(shape); var poly = new Path(); var points = shape.points;