geomerative 1.1.0-java → 2.0.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/.mvn/extensions.xml +1 -1
  4. data/.mvn/wrapper/maven-wrapper.properties +1 -1
  5. data/CHANGELOG.md +3 -0
  6. data/COPYING.md +1 -1
  7. data/README.md +0 -1
  8. data/Rakefile +2 -15
  9. data/docs/_includes/header.html +6 -6
  10. data/docs/_includes/icon-github.svg +3 -1
  11. data/docs/_includes/icon-twitter.svg +3 -1
  12. data/docs/_includes/navigation.html +18 -18
  13. data/docs/_sass/_base.scss +79 -79
  14. data/docs/_sass/_layout.scss +137 -137
  15. data/docs/_sass/_syntax-highlighting.scss +64 -64
  16. data/docs/index.html +18 -18
  17. data/examples/data/bot1.svg +1 -1
  18. data/examples/data/lion.svg +156 -156
  19. data/examples/data/ruby.svg +1 -1
  20. data/geomerative.gemspec +1 -2
  21. data/lib/geomerative/version.rb +1 -1
  22. data/mvnw +234 -0
  23. data/mvnw.cmd +145 -0
  24. data/pom.rb +14 -13
  25. data/pom.xml +14 -13
  26. data/src/geomerative/FastRClip.java +2149 -2156
  27. data/src/geomerative/RClip.java +2237 -2539
  28. data/src/geomerative/RClosest.java +33 -31
  29. data/src/geomerative/RCommand.java +1750 -1758
  30. data/src/geomerative/RContour.java +290 -292
  31. data/src/geomerative/RFont.java +277 -246
  32. data/src/geomerative/RG.java +722 -727
  33. data/src/geomerative/RGeomElem.java +967 -960
  34. data/src/geomerative/RGroup.java +508 -467
  35. data/src/geomerative/RMatrix.java +304 -289
  36. data/src/geomerative/RMesh.java +241 -229
  37. data/src/geomerative/RPath.java +924 -925
  38. data/src/geomerative/RPoint.java +391 -391
  39. data/src/geomerative/RPolygon.java +998 -988
  40. data/src/geomerative/RRectangle.java +43 -52
  41. data/src/geomerative/RSVG.java +480 -516
  42. data/src/geomerative/RShape.java +1767 -1777
  43. data/src/geomerative/RStrip.java +173 -176
  44. data/src/geomerative/RStyle.java +197 -194
  45. data/src/org/apache/batik/svggen/font/Font.java +141 -142
  46. data/src/org/apache/batik/svggen/font/Glyph.java +102 -71
  47. data/src/org/apache/batik/svggen/font/Point.java +12 -12
  48. data/src/org/apache/batik/svggen/font/RandomAccessFileEmulator.java +14 -12
  49. data/src/org/apache/batik/svggen/font/table/ClassDef.java +12 -12
  50. data/src/org/apache/batik/svggen/font/table/ClassDefFormat1.java +27 -24
  51. data/src/org/apache/batik/svggen/font/table/ClassDefFormat2.java +20 -17
  52. data/src/org/apache/batik/svggen/font/table/CmapFormat.java +43 -43
  53. data/src/org/apache/batik/svggen/font/table/CmapFormat0.java +33 -26
  54. data/src/org/apache/batik/svggen/font/table/CmapFormat2.java +25 -20
  55. data/src/org/apache/batik/svggen/font/table/CmapFormat4.java +106 -96
  56. data/src/org/apache/batik/svggen/font/table/CmapFormat6.java +36 -32
  57. data/src/org/apache/batik/svggen/font/table/CmapIndexEntry.java +69 -49
  58. data/src/org/apache/batik/svggen/font/table/CmapTable.java +50 -50
  59. data/src/org/apache/batik/svggen/font/table/Coverage.java +19 -19
  60. data/src/org/apache/batik/svggen/font/table/CoverageFormat1.java +30 -27
  61. data/src/org/apache/batik/svggen/font/table/CoverageFormat2.java +26 -24
  62. data/src/org/apache/batik/svggen/font/table/CvtTable.java +16 -16
  63. data/src/org/apache/batik/svggen/font/table/Device.java +32 -32
  64. data/src/org/apache/batik/svggen/font/table/DirectoryEntry.java +39 -39
  65. data/src/org/apache/batik/svggen/font/table/Feature.java +26 -23
  66. data/src/org/apache/batik/svggen/font/table/FeatureList.java +37 -35
  67. data/src/org/apache/batik/svggen/font/table/FeatureRecord.java +22 -22
  68. data/src/org/apache/batik/svggen/font/table/FeatureTags.java +4 -3
  69. data/src/org/apache/batik/svggen/font/table/FpgmTable.java +9 -9
  70. data/src/org/apache/batik/svggen/font/table/GlyfCompositeComp.java +134 -132
  71. data/src/org/apache/batik/svggen/font/table/GlyfCompositeDescript.java +123 -122
  72. data/src/org/apache/batik/svggen/font/table/GlyfDescript.java +44 -44
  73. data/src/org/apache/batik/svggen/font/table/GlyfSimpleDescript.java +110 -109
  74. data/src/org/apache/batik/svggen/font/table/GlyfTable.java +46 -46
  75. data/src/org/apache/batik/svggen/font/table/GlyphDescription.java +25 -13
  76. data/src/org/apache/batik/svggen/font/table/GposTable.java +26 -23
  77. data/src/org/apache/batik/svggen/font/table/GsubTable.java +85 -82
  78. data/src/org/apache/batik/svggen/font/table/HeadTable.java +131 -131
  79. data/src/org/apache/batik/svggen/font/table/HheaTable.java +80 -80
  80. data/src/org/apache/batik/svggen/font/table/HmtxTable.java +50 -49
  81. data/src/org/apache/batik/svggen/font/table/KernSubtable.java +29 -27
  82. data/src/org/apache/batik/svggen/font/table/KernSubtableFormat0.java +35 -32
  83. data/src/org/apache/batik/svggen/font/table/KernSubtableFormat2.java +28 -26
  84. data/src/org/apache/batik/svggen/font/table/KernTable.java +36 -31
  85. data/src/org/apache/batik/svggen/font/table/KerningPair.java +27 -23
  86. data/src/org/apache/batik/svggen/font/table/LangSys.java +28 -26
  87. data/src/org/apache/batik/svggen/font/table/LangSysRecord.java +22 -22
  88. data/src/org/apache/batik/svggen/font/table/Ligature.java +24 -24
  89. data/src/org/apache/batik/svggen/font/table/LigatureSet.java +24 -24
  90. data/src/org/apache/batik/svggen/font/table/LigatureSubst.java +9 -9
  91. data/src/org/apache/batik/svggen/font/table/LigatureSubstFormat1.java +30 -30
  92. data/src/org/apache/batik/svggen/font/table/LocaTable.java +37 -37
  93. data/src/org/apache/batik/svggen/font/table/Lookup.java +41 -40
  94. data/src/org/apache/batik/svggen/font/table/LookupList.java +34 -34
  95. data/src/org/apache/batik/svggen/font/table/LookupSubtableFactory.java +7 -5
  96. data/src/org/apache/batik/svggen/font/table/MaxpTable.java +96 -96
  97. data/src/org/apache/batik/svggen/font/table/NameRecord.java +64 -65
  98. data/src/org/apache/batik/svggen/font/table/NameTable.java +33 -33
  99. data/src/org/apache/batik/svggen/font/table/Os2Table.java +196 -196
  100. data/src/org/apache/batik/svggen/font/table/Panose.java +14 -12
  101. data/src/org/apache/batik/svggen/font/table/PostTable.java +338 -338
  102. data/src/org/apache/batik/svggen/font/table/PrepTable.java +9 -9
  103. data/src/org/apache/batik/svggen/font/table/Program.java +15 -15
  104. data/src/org/apache/batik/svggen/font/table/RangeRecord.java +26 -25
  105. data/src/org/apache/batik/svggen/font/table/Script.java +38 -38
  106. data/src/org/apache/batik/svggen/font/table/ScriptList.java +42 -42
  107. data/src/org/apache/batik/svggen/font/table/ScriptRecord.java +22 -22
  108. data/src/org/apache/batik/svggen/font/table/ScriptTags.java +2 -1
  109. data/src/org/apache/batik/svggen/font/table/SingleSubst.java +15 -16
  110. data/src/org/apache/batik/svggen/font/table/SingleSubstFormat1.java +33 -33
  111. data/src/org/apache/batik/svggen/font/table/SingleSubstFormat2.java +32 -32
  112. data/src/org/apache/batik/svggen/font/table/Table.java +171 -170
  113. data/src/org/apache/batik/svggen/font/table/TableDirectory.java +55 -55
  114. data/src/org/apache/batik/svggen/font/table/TableFactory.java +92 -93
  115. metadata +10 -11
  116. data/.travis.yml +0 -9
@@ -1,91 +1,82 @@
1
1
  /**
2
- Copyright 2004-2008 Ricard Marxer <email@ricardmarxer.com>
2
+ * Copyright 2004-2008 Ricard Marxer <email@ricardmarxer.com>
3
+ *
4
+ * This file is part of Geomerative.
5
+ *
6
+ * Geomerative is free software: you can redistribute it and/or modify it under
7
+ * the terms of the GNU General Public License as published by the Free Software
8
+ * Foundation, either version 3 of the License, or (at your option) any later
9
+ * version.
10
+ *
11
+ * Geomerative is distributed in the hope that it will be useful, but WITHOUT
12
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14
+ * details.
15
+ *
16
+ * You should have received a copy of the GNU General Public License along with
17
+ * Geomerative. If not, see <http://www.gnu.org/licenses/>.
18
+ */
19
+ package geomerative;
3
20
 
4
- This file is part of Geomerative.
21
+ public class RRectangle {
5
22
 
6
- Geomerative is free software: you can redistribute it and/or modify
7
- it under the terms of the GNU General Public License as published by
8
- the Free Software Foundation, either version 3 of the License, or
9
- (at your option) any later version.
10
-
11
- Geomerative is distributed in the hope that it will be useful,
12
- but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- GNU General Public License for more details.
15
-
16
- You should have received a copy of the GNU General Public License
17
- along with Geomerative. If not, see <http://www.gnu.org/licenses/>.
18
- */
19
-
20
- package geomerative ;
21
-
22
- public class RRectangle
23
- {
24
23
  RPoint topLeft;
25
24
  RPoint bottomRight;
26
-
27
- public RRectangle()
28
- {
25
+
26
+ public RRectangle() {
29
27
  topLeft = new RPoint();
30
28
  bottomRight = new RPoint();
31
29
  }
32
-
33
- public RRectangle(float x,float y,float w,float h)
34
- {
35
- topLeft = new RPoint(x,y);
36
- bottomRight = new RPoint(x+w,y+h);
37
-
30
+
31
+ public RRectangle(float x, float y, float w, float h) {
32
+ topLeft = new RPoint(x, y);
33
+ bottomRight = new RPoint(x + w, y + h);
34
+
38
35
  }
39
-
40
- public RRectangle(RPoint _topLeft,RPoint _bottomRight)
41
- {
36
+
37
+ public RRectangle(RPoint _topLeft, RPoint _bottomRight) {
42
38
  this.topLeft = _topLeft;
43
39
  this.bottomRight = _bottomRight;
44
- }
40
+ }
45
41
 
46
42
  RPoint[] getPoints() {
47
43
  RPoint[] ps = new RPoint[4];
48
44
 
49
45
  ps[0] = new RPoint(topLeft);
50
-
46
+
51
47
  ps[1] = new RPoint(topLeft);
52
48
  ps[1].x = bottomRight.x;
53
-
49
+
54
50
  ps[2] = new RPoint(bottomRight);
55
-
51
+
56
52
  ps[3] = new RPoint(bottomRight);
57
53
  ps[3].x = topLeft.x;
58
-
54
+
59
55
  return ps;
60
56
  }
61
-
62
- float getMaxX()
63
- {
57
+
58
+ float getMaxX() {
64
59
  //return (topLeft.x > bottomRight.x) ? topLeft.x : bottomRight.x;
65
60
  return bottomRight.x;
66
61
  }
67
-
68
- float getMaxY()
69
- {
62
+
63
+ float getMaxY() {
70
64
  //return (topLeft.y > bottomRight.y) ? topLeft.y : bottomRight.y;
71
65
  return bottomRight.y;
72
66
  }
73
-
74
- float getMinX()
75
- {
67
+
68
+ float getMinX() {
76
69
  //return (topLeft.x < bottomRight.x) ? topLeft.x : bottomRight.x;
77
70
  return topLeft.x;
78
71
  }
79
-
80
- float getMinY()
81
- {
72
+
73
+ float getMinY() {
82
74
  //return (topLeft.y < bottomRight.y) ? topLeft.y : bottomRight.y;
83
75
  return topLeft.y;
84
76
  }
85
-
77
+
86
78
  @Override
87
- public String toString()
88
- {
79
+ public String toString() {
89
80
  return "";
90
81
  }
91
82
  }
@@ -1,47 +1,42 @@
1
1
  /**
2
- Copyright 2004-2008 Ricard Marxer <email@ricardmarxer.com>
3
-
4
- This file is part of Geomerative.
5
-
6
- Geomerative is free software: you can redistribute it and/or modify
7
- it under the terms of the GNU General Public License as published by
8
- the Free Software Foundation, either version 3 of the License, or
9
- (at your option) any later version.
10
-
11
- Geomerative is distributed in the hope that it will be useful,
12
- but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- GNU General Public License for more details.
15
-
16
- You should have received a copy of the GNU General Public License
17
- along with Geomerative. If not, see <http://www.gnu.org/licenses/>.
18
- */
19
-
2
+ * Copyright 2004-2008 Ricard Marxer <email@ricardmarxer.com>
3
+ *
4
+ * This file is part of Geomerative.
5
+ *
6
+ * Geomerative is free software: you can redistribute it and/or modify it under
7
+ * the terms of the GNU General Public License as published by the Free Software
8
+ * Foundation, either version 3 of the License, or (at your option) any later
9
+ * version.
10
+ *
11
+ * Geomerative is distributed in the hope that it will be useful, but WITHOUT
12
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14
+ * details.
15
+ *
16
+ * You should have received a copy of the GNU General Public License along with
17
+ * Geomerative. If not, see <http://www.gnu.org/licenses/>.
18
+ */
20
19
  package geomerative;
21
20
 
22
-
23
21
  import processing.core.PApplet;
24
22
  import processing.core.PConstants;
25
23
  import processing.core.PGraphics;
26
24
  import processing.data.XML;
27
25
 
28
26
  /**
29
- * @extended
27
+
30
28
  */
31
- public class RSVG
32
- {
33
- public void draw(String filename, PGraphics g)
34
- {
29
+ public class RSVG {
30
+
31
+ public void draw(String filename, PGraphics g) {
35
32
  this.toGroup(filename).draw(g);
36
33
  }
37
34
 
38
- public void draw(String filename, PApplet p)
39
- {
35
+ public void draw(String filename, PApplet p) {
40
36
  this.toGroup(filename).draw(p);
41
37
  }
42
38
 
43
- public void draw(String filename)
44
- {
39
+ public void draw(String filename) {
45
40
  this.toGroup(filename).draw();
46
41
  }
47
42
 
@@ -69,24 +64,22 @@ public class RSVG
69
64
  return header + groupToString(group) + "</svg>";
70
65
  }
71
66
 
72
-
73
-
74
- public RGroup toGroup(String filename)
75
- {
67
+ public RGroup toGroup(String filename) {
76
68
  XML svg;
77
69
 
78
- svg = RG.parent().loadXML(filename);
79
-
80
-
81
- if (svg == null) return new RGroup();
82
-
70
+ svg = RG.parent().loadXML(filename);
71
+
72
+ if (svg == null) {
73
+ return new RGroup();
74
+ }
75
+
83
76
  if (!svg.getName().equals("svg")) {
84
77
  throw new RuntimeException("root is not <svg>, it's <" + svg.getName() + ">");
85
78
  }
86
79
 
87
80
  return elemToGroup(svg);
88
81
  }
89
-
82
+
90
83
  public float unitsToPixels(String units, float originalPxSize) {
91
84
  // TODO: check if it is possible to know the dpi of a given PGraphics or device
92
85
  return unitsToPixels(units, originalPxSize, 72.0f/*Toolkit.getDefaultToolkit().getScreenResolution()*/);
@@ -128,20 +121,19 @@ public class RSVG
128
121
  multiplier = 1.0f;
129
122
  }
130
123
 
131
- return Float.parseFloat(units.substring(0, units.length()-chars)) * multiplier;
124
+ return Float.parseFloat(units.substring(0, units.length() - chars)) * multiplier;
132
125
  }
133
126
 
134
- public RShape toShape(String filename)
135
- {
136
- XML svg;
127
+ public RShape toShape(String filename) {
128
+ XML svg;
137
129
 
138
- svg = RG.parent().loadXML(filename);
130
+ svg = RG.parent().loadXML(filename);
139
131
 
140
-
141
- if (svg == null) return new RShape();
132
+ if (svg == null) {
133
+ return new RShape();
134
+ }
142
135
 
143
- if ( !svg.getName().equals("svg") )
144
- {
136
+ if (!svg.getName().equals("svg")) {
145
137
  throw new RuntimeException("root is not <svg>, it's <" + svg.getName() + ">");
146
138
  }
147
139
 
@@ -153,24 +145,22 @@ public class RSVG
153
145
  if (svg.hasAttribute("width") && svg.hasAttribute("height")) {
154
146
  String widthStr = svg.getString("width").trim();
155
147
  String heightStr = svg.getString("height").trim();
156
-
148
+
157
149
  result.width = unitsToPixels(widthStr, result.origWidth);
158
150
  result.height = unitsToPixels(heightStr, result.origHeight);
159
151
  } else {
160
152
  result.width = result.origWidth;
161
153
  result.height = result.origHeight;
162
154
  }
163
-
155
+
164
156
  return result;
165
157
  }
166
158
 
167
- public RPolygon toPolygon(String filename)
168
- {
159
+ public RPolygon toPolygon(String filename) {
169
160
  return toGroup(filename).toPolygon();
170
161
  }
171
162
 
172
- public RMesh toMesh(String filename)
173
- {
163
+ public RMesh toMesh(String filename) {
174
164
  return toGroup(filename).toMesh();
175
165
  }
176
166
 
@@ -180,19 +170,19 @@ public class RSVG
180
170
  result += styleToString(grp.getStyle());
181
171
  result += ">\n";
182
172
 
183
- for(int i=0;i<grp.countElements();i++) {
184
- switch(grp.elements[i].getType()){
185
- case RGeomElem.GROUP:
186
- result += groupToString((RGroup)grp.elements[i]);
187
- break;
173
+ for (int i = 0; i < grp.countElements(); i++) {
174
+ switch (grp.elements[i].getType()) {
175
+ case RGeomElem.GROUP:
176
+ result += groupToString((RGroup) grp.elements[i]);
177
+ break;
188
178
 
189
- case RGeomElem.POLYGON:
190
- result += polygonToString((RPolygon)grp.elements[i]);
191
- break;
179
+ case RGeomElem.POLYGON:
180
+ result += polygonToString((RPolygon) grp.elements[i]);
181
+ break;
192
182
 
193
- case RGeomElem.SHAPE:
194
- result += shapeToString((RShape)grp.elements[i]);
195
- break;
183
+ case RGeomElem.SHAPE:
184
+ result += shapeToString((RShape) grp.elements[i]);
185
+ break;
196
186
 
197
187
  }
198
188
  }
@@ -219,10 +209,10 @@ public class RSVG
219
209
  result += "<path ";
220
210
  result += "d=\"";
221
211
 
222
- for(int i=0; i<shp.countPaths(); i++) {
212
+ for (int i = 0; i < shp.countPaths(); i++) {
223
213
  RPath sushp = shp.paths[i];
224
214
  boolean init = true;
225
- for ( int j = 0; j < sushp.countCommands(); j++ ) {
215
+ for (int j = 0; j < sushp.countCommands(); j++) {
226
216
  RCommand cmd = sushp.commands[j];
227
217
 
228
218
  if (init) {
@@ -230,8 +220,7 @@ public class RSVG
230
220
  init = false;
231
221
  }
232
222
 
233
- switch( cmd.getCommandType() )
234
- {
223
+ switch (cmd.getCommandType()) {
235
224
  case RCommand.LINETO:
236
225
  result += "L" + cmd.endPoint.x + " " + cmd.endPoint.y + " ";
237
226
  break;
@@ -243,7 +232,7 @@ public class RSVG
243
232
  case RCommand.CUBICBEZIERTO:
244
233
  result += "C" + cmd.controlPoints[0].x + " " + cmd.controlPoints[0].y + " " + cmd.controlPoints[1].x + " " + cmd.controlPoints[1].y + " " + cmd.endPoint.x + " " + cmd.endPoint.y + " ";
245
234
  break;
246
- }
235
+ }
247
236
  }
248
237
 
249
238
  if (sushp.closed) {
@@ -254,8 +243,8 @@ public class RSVG
254
243
  result += "\"/>\n";
255
244
  }
256
245
 
257
- for (int i=0; i<shp.countChildren(); i++) {
258
- result+=shapeToString(shp.children[i]);
246
+ for (int i = 0; i < shp.countChildren(); i++) {
247
+ result += shapeToString(shp.children[i]);
259
248
  }
260
249
 
261
250
  result += "</g>\n";
@@ -274,7 +263,7 @@ public class RSVG
274
263
  }
275
264
 
276
265
  if (style.fillAlphaDef) {
277
- result += "fill-opacity:" + style.fillAlpha/255.0f + ";";
266
+ result += "fill-opacity:" + style.fillAlpha / 255.0f + ";";
278
267
  }
279
268
 
280
269
  if (style.strokeDef) {
@@ -286,51 +275,50 @@ public class RSVG
286
275
  }
287
276
 
288
277
  if (style.strokeAlphaDef) {
289
- result += "stroke-opacity:" + style.strokeAlpha/255.0f + ";";
278
+ result += "stroke-opacity:" + style.strokeAlpha / 255.0f + ";";
290
279
  }
291
280
 
292
281
  if (style.strokeWeightDef) {
293
282
  result += "stroke-width:" + style.strokeWeight + ";";
294
283
  }
295
284
 
296
-
297
- if(style.strokeCapDef) {
285
+ if (style.strokeCapDef) {
298
286
  result += "stroke-linecap:";
299
287
 
300
288
  switch (style.strokeCap) {
301
- case PConstants.PROJECT:
302
- result += "butt";
303
- break;
304
- case PConstants.ROUND:
305
- result += "round";
306
- break;
307
- case PConstants.SQUARE:
308
- result += "square";
309
- break;
310
-
311
- default:
312
- break;
289
+ case PConstants.PROJECT:
290
+ result += "butt";
291
+ break;
292
+ case PConstants.ROUND:
293
+ result += "round";
294
+ break;
295
+ case PConstants.SQUARE:
296
+ result += "square";
297
+ break;
298
+
299
+ default:
300
+ break;
313
301
  }
314
302
 
315
303
  result += ";";
316
304
  }
317
305
 
318
- if(style.strokeJoinDef) {
306
+ if (style.strokeJoinDef) {
319
307
  result += "stroke-linejoin:";
320
308
 
321
309
  switch (style.strokeJoin) {
322
- case PConstants.MITER:
323
- result += "miter";
324
- break;
325
- case PConstants.ROUND:
326
- result += "round";
327
- break;
328
- case PConstants.BEVEL:
329
- result += "bevel";
330
- break;
331
-
332
- default:
333
- break;
310
+ case PConstants.MITER:
311
+ result += "miter";
312
+ break;
313
+ case PConstants.ROUND:
314
+ result += "round";
315
+ break;
316
+ case PConstants.BEVEL:
317
+ result += "bevel";
318
+ break;
319
+
320
+ default:
321
+ break;
334
322
  }
335
323
 
336
324
  result += ";";
@@ -341,16 +329,15 @@ public class RSVG
341
329
  }
342
330
 
343
331
  /**
344
- * @param elem
345
- * @return
346
- * @invisible
332
+ * @param elem
333
+ * @return
334
+ *
347
335
  */
348
- public RGroup elemToGroup(XML elem)
349
- {
336
+ public RGroup elemToGroup(XML elem) {
350
337
  RGroup grp = new RGroup();
351
338
 
352
339
  // Set the defaults SVG styles for the root
353
- if(elem.getName().toLowerCase().equals("svg")){
340
+ if (elem.getName().toLowerCase().equals("svg")) {
354
341
  grp.setFill(0); // By default in SVG it's black
355
342
  grp.setFillAlpha(255); // By default in SVG it's 1
356
343
  grp.setStroke(false); // By default in SVG it's none
@@ -362,106 +349,106 @@ public class RSVG
362
349
  }
363
350
 
364
351
  XML elems[] = elem.getChildren();
365
- for (XML elem1 : elems) {
366
- String name = elem1.getName().toLowerCase();
367
- XML element = elem1;
368
- // Parse and create the geometrical element
369
- RGeomElem geomElem = null;
370
- switch (name) {
371
- case "g":
372
- geomElem = elemToGroup(element);
373
- break;
374
- case "path":
375
- geomElem = elemToShape(element);
376
- break;
377
- case "polygon":
378
- geomElem = elemToPolygon(element);
379
- break;
380
- case "polyline":
381
- geomElem = elemToPolyline(element);
382
- break;
383
- case "circle":
384
- geomElem = elemToCircle(element);
385
- break;
386
- case "ellipse":
387
- geomElem = elemToEllipse(element);
388
- break;
389
- case "rect":
390
- geomElem = elemToRect(element);
391
- break;
392
- case "line":
393
- geomElem = elemToLine(element);
394
- break;
395
- case "defs":
396
- break;
397
- case "#text":
398
- break;
399
- default:
400
- PApplet.println("Element '" + name + "' not know. Ignoring it.");
401
- break; // If the geometrical element has been correctly created
352
+ for (XML elem1 : elems) {
353
+ String name = elem1.getName().toLowerCase();
354
+ XML element = elem1;
355
+ // Parse and create the geometrical element
356
+ RGeomElem geomElem = null;
357
+ switch (name) {
358
+ case "g":
359
+ geomElem = elemToGroup(element);
360
+ break;
361
+ case "path":
362
+ geomElem = elemToShape(element);
363
+ break;
364
+ case "polygon":
365
+ geomElem = elemToPolygon(element);
366
+ break;
367
+ case "polyline":
368
+ geomElem = elemToPolyline(element);
369
+ break;
370
+ case "circle":
371
+ geomElem = elemToCircle(element);
372
+ break;
373
+ case "ellipse":
374
+ geomElem = elemToEllipse(element);
375
+ break;
376
+ case "rect":
377
+ geomElem = elemToRect(element);
378
+ break;
379
+ case "line":
380
+ geomElem = elemToLine(element);
381
+ break;
382
+ case "defs":
383
+ break;
384
+ case "#text":
385
+ break;
386
+ default:
387
+ PApplet.println("Element '" + name + "' not know. Ignoring it.");
388
+ break; // If the geometrical element has been correctly created
402
389
  }
403
- if((geomElem != null)){
404
- // Transform geometrical element
405
- if(element.hasAttribute("transform")){
406
- String transformString = element.getString("transform");
407
- RMatrix transf = new RMatrix(transformString);
408
- geomElem.transform(transf);
409
- }
410
-
411
- // Get the id for the geometrical element
412
- if(element.hasAttribute("id")){
413
- geomElem.name = element.getString("id");
414
- }
415
-
416
- // Get the style for the geometrical element
417
- if(element.hasAttribute("style")){
418
- geomElem.setStyle(element.getString("style"));
419
- }
420
-
421
- // Get the fill for the geometrical element
422
- if(element.hasAttribute("fill")){
423
- geomElem.setFill(element.getString("fill"));
424
- }
425
-
426
- // Get the fill-linejoin for the geometrical element
427
- if(element.hasAttribute("fill-opacity")){
428
- geomElem.setFillAlpha(element.getString("fill-opacity"));
429
- }
430
-
431
- // Get the stroke for the geometrical element
432
- if(element.hasAttribute("stroke")){
433
- geomElem.setStroke(element.getString("stroke"));
434
- }
435
-
436
- // Get the stroke-width for the geometrical element
437
- if(element.hasAttribute("stroke-width")){
438
- geomElem.setStrokeWeight(element.getString("stroke-width"));
439
- }
440
-
441
- // Get the stroke-linecap for the geometrical element
442
- if(element.hasAttribute("stroke-linecap")){
443
- geomElem.setStrokeCap(element.getString("stroke-linecap"));
444
- }
445
-
446
- // Get the stroke-linejoin for the geometrical element
447
- if(element.hasAttribute("stroke-linejoin")){
448
- geomElem.setStrokeJoin(element.getString("stroke-linejoin"));
449
- }
450
-
451
- // Get the stroke-linejoin for the geometrical element
452
- if(element.hasAttribute("stroke-opacity")){
453
- geomElem.setStrokeAlpha(element.getString("stroke-opacity"));
454
- }
455
-
456
- // Get the opacity for the geometrical element
457
- if(element.hasAttribute("opacity")){
390
+ if ((geomElem != null)) {
391
+ // Transform geometrical element
392
+ if (element.hasAttribute("transform")) {
393
+ String transformString = element.getString("transform");
394
+ RMatrix transf = new RMatrix(transformString);
395
+ geomElem.transform(transf);
396
+ }
397
+
398
+ // Get the id for the geometrical element
399
+ if (element.hasAttribute("id")) {
400
+ geomElem.name = element.getString("id");
401
+ }
402
+
403
+ // Get the style for the geometrical element
404
+ if (element.hasAttribute("style")) {
405
+ geomElem.setStyle(element.getString("style"));
406
+ }
407
+
408
+ // Get the fill for the geometrical element
409
+ if (element.hasAttribute("fill")) {
410
+ geomElem.setFill(element.getString("fill"));
411
+ }
412
+
413
+ // Get the fill-linejoin for the geometrical element
414
+ if (element.hasAttribute("fill-opacity")) {
415
+ geomElem.setFillAlpha(element.getString("fill-opacity"));
416
+ }
417
+
418
+ // Get the stroke for the geometrical element
419
+ if (element.hasAttribute("stroke")) {
420
+ geomElem.setStroke(element.getString("stroke"));
421
+ }
422
+
423
+ // Get the stroke-width for the geometrical element
424
+ if (element.hasAttribute("stroke-width")) {
425
+ geomElem.setStrokeWeight(element.getString("stroke-width"));
426
+ }
427
+
428
+ // Get the stroke-linecap for the geometrical element
429
+ if (element.hasAttribute("stroke-linecap")) {
430
+ geomElem.setStrokeCap(element.getString("stroke-linecap"));
431
+ }
432
+
433
+ // Get the stroke-linejoin for the geometrical element
434
+ if (element.hasAttribute("stroke-linejoin")) {
435
+ geomElem.setStrokeJoin(element.getString("stroke-linejoin"));
436
+ }
437
+
438
+ // Get the stroke-linejoin for the geometrical element
439
+ if (element.hasAttribute("stroke-opacity")) {
440
+ geomElem.setStrokeAlpha(element.getString("stroke-opacity"));
441
+ }
442
+
443
+ // Get the opacity for the geometrical element
444
+ if (element.hasAttribute("opacity")) {
458
445
  geomElem.setAlpha(element.getString("opacity"));
459
446
  }
460
447
 
461
448
  // Get the style for the geometrical element
462
449
  grp.addElement(geomElem);
463
450
  }
464
- }
451
+ }
465
452
 
466
453
  // Set the original width and height
467
454
  grp.updateOrigParams();
@@ -470,17 +457,15 @@ public class RSVG
470
457
  }
471
458
 
472
459
  /**
473
- * @param elem
474
- * @return
475
- * @invisible
460
+ * @param elem
461
+ * @return
462
+ *
476
463
  */
477
- public RShape elemToCompositeShape( XML elem )
478
- {
464
+ public RShape elemToCompositeShape(XML elem) {
479
465
  RShape shp = new RShape();
480
466
 
481
467
  // Set the defaults SVG styles for the root
482
- if (elem.getName().toLowerCase().equals("svg"))
483
- {
468
+ if (elem.getName().toLowerCase().equals("svg")) {
484
469
  shp.setFill(0); // By default in SVG it's black
485
470
  shp.setFillAlpha(255); // By default in SVG it's 1
486
471
  shp.setStroke(false); // By default in SVG it's none
@@ -493,108 +478,110 @@ public class RSVG
493
478
 
494
479
  XML elems[] = elem.getChildren();
495
480
 
496
- for (XML elem1 : elems) {
497
- String name = elem1.getName();
498
- if ( name == null ) continue;
499
- name = name.toLowerCase();
500
- XML element = elem1;
501
- // Parse and create the geometrical element
502
- RShape geomElem = null;
503
- switch (name) {
504
- case "g":
505
- geomElem = elemToCompositeShape(element);
506
- break;
507
- case "path":
508
- geomElem = elemToShape(element);
509
- break;
510
- case "polygon":
511
- geomElem = elemToPolygon(element);
512
- break;
513
- case "polyline":
514
- geomElem = elemToPolyline(element);
515
- break;
516
- case "circle":
517
- geomElem = elemToCircle(element);
518
- break;
519
- case "ellipse":
520
- geomElem = elemToEllipse(element);
521
- break;
522
- case "rect":
523
- geomElem = elemToRect(element);
524
- break;
525
- case "line":
526
- geomElem = elemToLine(element);
527
- break;
528
- case "#text":
529
- break;
530
- case "defs":
531
- break;
532
- default:
533
- PApplet.println("Element '" + name + "' not know. Ignoring it.");
534
- break; // If the geometrical element has been correctly created
481
+ for (XML elem1 : elems) {
482
+ String name = elem1.getName();
483
+ if (name == null) {
484
+ continue;
485
+ }
486
+ name = name.toLowerCase();
487
+ XML element = elem1;
488
+ // Parse and create the geometrical element
489
+ RShape geomElem = null;
490
+ switch (name) {
491
+ case "g":
492
+ geomElem = elemToCompositeShape(element);
493
+ break;
494
+ case "path":
495
+ geomElem = elemToShape(element);
496
+ break;
497
+ case "polygon":
498
+ geomElem = elemToPolygon(element);
499
+ break;
500
+ case "polyline":
501
+ geomElem = elemToPolyline(element);
502
+ break;
503
+ case "circle":
504
+ geomElem = elemToCircle(element);
505
+ break;
506
+ case "ellipse":
507
+ geomElem = elemToEllipse(element);
508
+ break;
509
+ case "rect":
510
+ geomElem = elemToRect(element);
511
+ break;
512
+ case "line":
513
+ geomElem = elemToLine(element);
514
+ break;
515
+ case "#text":
516
+ break;
517
+ case "defs":
518
+ break;
519
+ default:
520
+ PApplet.println("Element '" + name + "' not know. Ignoring it.");
521
+ break; // If the geometrical element has been correctly created
522
+ }
523
+ if ((geomElem != null)) {
524
+ // Transform geometrical element
525
+ if (element.hasAttribute("transform")) {
526
+ String transformString = element.getString("transform");
527
+ RMatrix transf = new RMatrix(transformString);
528
+ geomElem.transform(transf);
529
+ }
530
+
531
+ // Get the id for the geometrical element
532
+ if (element.hasAttribute("id")) {
533
+ geomElem.name = element.getString("id");
534
+ }
535
+
536
+ // Get the style for the geometrical element
537
+ if (element.hasAttribute("style")) {
538
+ geomElem.setStyle(element.getString("style"));
539
+ }
540
+
541
+ // Get the fill for the geometrical element
542
+ if (element.hasAttribute("fill")) {
543
+ geomElem.setFill(element.getString("fill"));
544
+ }
545
+
546
+ // Get the fill-linejoin for the geometrical element
547
+ if (element.hasAttribute("fill-opacity")) {
548
+ geomElem.setFillAlpha(element.getString("fill-opacity"));
549
+ }
550
+
551
+ // Get the stroke for the geometrical element
552
+ if (element.hasAttribute("stroke")) {
553
+ geomElem.setStroke(element.getString("stroke"));
554
+ }
555
+
556
+ // Get the stroke-width for the geometrical element
557
+ if (element.hasAttribute("stroke-width")) {
558
+ geomElem.setStrokeWeight(element.getString("stroke-width"));
559
+ }
560
+
561
+ // Get the stroke-linecap for the geometrical element
562
+ if (element.hasAttribute("stroke-linecap")) {
563
+ geomElem.setStrokeCap(element.getString("stroke-linecap"));
564
+ }
565
+
566
+ // Get the stroke-linejoin for the geometrical element
567
+ if (element.hasAttribute("stroke-linejoin")) {
568
+ geomElem.setStrokeJoin(element.getString("stroke-linejoin"));
535
569
  }
536
- if((geomElem != null)){
537
- // Transform geometrical element
538
- if(element.hasAttribute("transform")){
539
- String transformString = element.getString("transform");
540
- RMatrix transf = new RMatrix(transformString);
541
- geomElem.transform(transf);
542
- }
543
-
544
- // Get the id for the geometrical element
545
- if(element.hasAttribute("id")){
546
- geomElem.name = element.getString("id");
547
- }
548
-
549
- // Get the style for the geometrical element
550
- if(element.hasAttribute("style")){
551
- geomElem.setStyle(element.getString("style"));
552
- }
553
-
554
- // Get the fill for the geometrical element
555
- if(element.hasAttribute("fill")){
556
- geomElem.setFill(element.getString("fill"));
557
- }
558
-
559
- // Get the fill-linejoin for the geometrical element
560
- if(element.hasAttribute("fill-opacity")){
561
- geomElem.setFillAlpha(element.getString("fill-opacity"));
562
- }
563
-
564
- // Get the stroke for the geometrical element
565
- if(element.hasAttribute("stroke")){
566
- geomElem.setStroke(element.getString("stroke"));
567
- }
568
-
569
- // Get the stroke-width for the geometrical element
570
- if(element.hasAttribute("stroke-width")){
571
- geomElem.setStrokeWeight(element.getString("stroke-width"));
572
- }
573
-
574
- // Get the stroke-linecap for the geometrical element
575
- if(element.hasAttribute("stroke-linecap")){
576
- geomElem.setStrokeCap(element.getString("stroke-linecap"));
577
- }
578
-
579
- // Get the stroke-linejoin for the geometrical element
580
- if(element.hasAttribute("stroke-linejoin")){
581
- geomElem.setStrokeJoin(element.getString("stroke-linejoin"));
582
- }
583
-
584
- // Get the stroke-linejoin for the geometrical element
585
- if(element.hasAttribute("stroke-opacity")){
586
- geomElem.setStrokeAlpha(element.getString("stroke-opacity"));
587
- }
588
-
589
- // Get the opacity for the geometrical element
590
- if(element.hasAttribute("opacity")){
570
+
571
+ // Get the stroke-linejoin for the geometrical element
572
+ if (element.hasAttribute("stroke-opacity")) {
573
+ geomElem.setStrokeAlpha(element.getString("stroke-opacity"));
574
+ }
575
+
576
+ // Get the opacity for the geometrical element
577
+ if (element.hasAttribute("opacity")) {
591
578
  geomElem.setAlpha(element.getString("opacity"));
592
579
  }
593
580
 
594
581
  // Get the style for the geometrical element
595
582
  shp.addChild(geomElem);
596
583
  }
597
- }
584
+ }
598
585
 
599
586
  shp.updateOrigParams();
600
587
 
@@ -602,12 +589,11 @@ public class RSVG
602
589
  }
603
590
 
604
591
  /**
605
- * @param elem
606
- * @return
607
- * @invisible
592
+ * @param elem
593
+ * @return
594
+ *
608
595
  */
609
- public RShape elemToPolyline(XML elem)
610
- {
596
+ public RShape elemToPolyline(XML elem) {
611
597
  RShape shp = getPolyline(elem.getString("points").trim());
612
598
 
613
599
  shp.updateOrigParams();
@@ -616,12 +602,11 @@ public class RSVG
616
602
  }
617
603
 
618
604
  /**
619
- * @param elem
620
- * @return
621
- * @invisible
605
+ * @param elem
606
+ * @return
607
+ *
622
608
  */
623
- public RShape elemToPolygon(XML elem)
624
- {
609
+ public RShape elemToPolygon(XML elem) {
625
610
  RShape poly = elemToPolyline(elem);
626
611
 
627
612
  poly.addClose();
@@ -632,12 +617,11 @@ public class RSVG
632
617
  }
633
618
 
634
619
  /**
635
- * @param elem
636
- * @return
637
- * @invisible
620
+ * @param elem
621
+ * @return
622
+ *
638
623
  */
639
- public RShape elemToRect(XML elem)
640
- {
624
+ public RShape elemToRect(XML elem) {
641
625
 
642
626
  RShape shp = getRect(elem.getFloat("x"), elem.getFloat("y"), elem.getFloat("width"), elem.getFloat("height"));
643
627
 
@@ -647,12 +631,11 @@ public class RSVG
647
631
  }
648
632
 
649
633
  /**
650
- * @param elem
651
- * @return
652
- * @invisible
634
+ * @param elem
635
+ * @return
636
+ *
653
637
  */
654
- public RShape elemToLine(XML elem)
655
- {
638
+ public RShape elemToLine(XML elem) {
656
639
  RShape shp = getLine(elem.getFloat("x1"), elem.getFloat("y1"), elem.getFloat("x2"), elem.getFloat("y2"));
657
640
 
658
641
  shp.updateOrigParams();
@@ -660,14 +643,12 @@ public class RSVG
660
643
  return shp;
661
644
  }
662
645
 
663
-
664
646
  /**
665
- * @param elem
666
- * @return
667
- * @invisible
647
+ * @param elem
648
+ * @return
649
+ *
668
650
  */
669
- public RShape elemToEllipse(XML elem)
670
- {
651
+ public RShape elemToEllipse(XML elem) {
671
652
  RShape shp = getEllipse(elem.getFloat("cx"), elem.getFloat("cy"), elem.getFloat("rx"), elem.getFloat("ry"));
672
653
 
673
654
  shp.updateOrigParams();
@@ -675,14 +656,12 @@ public class RSVG
675
656
  return shp;
676
657
  }
677
658
 
678
-
679
659
  /**
680
- * @param elem
681
- * @return
682
- * @invisible
660
+ * @param elem
661
+ * @return
662
+ *
683
663
  */
684
- public RShape elemToCircle(XML elem)
685
- {
664
+ public RShape elemToCircle(XML elem) {
686
665
  float r = elem.getFloat("r");
687
666
  RShape shp = getEllipse(elem.getFloat("cx"), elem.getFloat("cy"), r, r);
688
667
 
@@ -692,12 +671,11 @@ public class RSVG
692
671
  }
693
672
 
694
673
  /**
695
- * @param elem
696
- * @return
697
- * @invisible
674
+ * @param elem
675
+ * @return
676
+ *
698
677
  */
699
- public RShape elemToShape(XML elem)
700
- {
678
+ public RShape elemToShape(XML elem) {
701
679
  RShape shp = getShape(elem.getString("d"));
702
680
 
703
681
  shp.updateOrigParams();
@@ -706,10 +684,9 @@ public class RSVG
706
684
  }
707
685
 
708
686
  /**
709
- * @invisible
687
+ *
710
688
  */
711
- private RShape getRect(float x, float y, float w, float h)
712
- {
689
+ private RShape getRect(float x, float y, float w, float h) {
713
690
  RShape shp = RShape.createRectangle(x, y, w, h);
714
691
 
715
692
  shp.updateOrigParams();
@@ -718,10 +695,9 @@ public class RSVG
718
695
  }
719
696
 
720
697
  /**
721
- * @invisible
698
+ *
722
699
  */
723
- private RShape getLine(float x1, float y1, float x2, float y2)
724
- {
700
+ private RShape getLine(float x1, float y1, float x2, float y2) {
725
701
  RShape shp = new RShape();
726
702
 
727
703
  shp.addMoveTo(x1, y1);
@@ -730,119 +706,110 @@ public class RSVG
730
706
  return shp;
731
707
  }
732
708
 
733
-
734
709
  /**
735
- * @invisible
710
+ *
736
711
  */
737
- private RShape getEllipse(float cx, float cy, float rx, float ry)
738
- {
712
+ private RShape getEllipse(float cx, float cy, float rx, float ry) {
739
713
  // RShape createEllipse takes as input the width and height of the ellipses
740
- return RShape.createEllipse(cx, cy, rx*2F, ry*2F);
714
+ return RShape.createEllipse(cx, cy, rx * 2F, ry * 2F);
741
715
  }
742
716
 
743
717
  /**
744
- * @invisible
718
+ *
745
719
  */
746
- private RShape getPolyline(String s)
747
- {
720
+ private RShape getPolyline(String s) {
748
721
  RShape poly = new RShape();
749
722
  boolean first = true;
750
723
 
751
724
  //format string to usable format
752
- char charline[]=s.toCharArray();
753
- for(int i=0;i<charline.length;i++)
754
- {
755
- switch(charline[i])
756
- {
757
- case '-':
758
- if(charline[i-1] != 'e' && charline[i-1] != 'E'){
759
- charline=PApplet.splice(charline,' ',i);
760
- i++;
761
- }
762
- break;
763
- case ',':
764
- case '\n':
765
- case '\r':
766
- case '\t':
767
- charline[i]=' ';
768
- break;
725
+ char charline[] = s.toCharArray();
726
+ for (int i = 0; i < charline.length; i++) {
727
+ switch (charline[i]) {
728
+ case '-':
729
+ if (charline[i - 1] != 'e' && charline[i - 1] != 'E') {
730
+ charline = PApplet.splice(charline, ' ', i);
731
+ i++;
769
732
  }
733
+ break;
734
+ case ',':
735
+ case '\n':
736
+ case '\r':
737
+ case '\t':
738
+ charline[i] = ' ';
739
+ break;
770
740
  }
771
- String formatted=new String(charline);
772
- String tags[]=PApplet.splitTokens(formatted,", ");
773
- for(int i=0;i<tags.length;i++){
741
+ }
742
+ String formatted = new String(charline);
743
+ String tags[] = PApplet.splitTokens(formatted, ", ");
744
+ for (int i = 0; i < tags.length; i++) {
774
745
  float x = PApplet.parseFloat(tags[i]);
775
- float y = PApplet.parseFloat(tags[i+1]);
746
+ float y = PApplet.parseFloat(tags[i + 1]);
776
747
  i++;
777
- if(first){
778
- poly.addMoveTo(x,y);
748
+ if (first) {
749
+ poly.addMoveTo(x, y);
779
750
  first = false;
780
- }else{
781
- poly.addLineTo(x,y);
751
+ } else {
752
+ poly.addLineTo(x, y);
782
753
  }
783
754
  }
784
755
  return poly;
785
756
  }
786
757
 
787
758
  /**
788
- * @invisible
759
+ *
789
760
  */
790
- private RShape getShape(String s)
791
- {
761
+ private RShape getShape(String s) {
792
762
  RShape shp = new RShape();
793
763
 
794
- if(s == null){
764
+ if (s == null) {
795
765
  return shp;
796
766
  }
797
767
 
798
768
  //format string to usable format
799
769
  char charline[] = s.toCharArray();
800
- for( int i = 0 ; i < charline.length ; i++)
801
- {
802
- switch(charline[i])
803
- {
804
- case 'M':
805
- case 'm':
806
- case 'Z':
807
- case 'z':
808
- case 'C':
809
- case 'c':
810
- case 'S':
811
- case 's':
812
- case 'L':
813
- case 'l':
814
- case 'H':
815
- case 'h':
816
- case 'V':
817
- case 'v':
818
- charline = PApplet.splice(charline,' ',i);
819
- i ++;
820
- charline = PApplet.splice(charline,' ',i+1);
821
- i ++;
822
- break;
823
-
824
- case '-':
825
- if(i>0 && charline[i-1] != 'e' && charline[i-1] != 'E'){
826
- charline=PApplet.splice(charline,' ',i);
827
- i++;
828
- }
829
- break;
830
- case ',':
831
- case '\n':
832
- case '\r':
833
- case '\t':
834
- charline[i] = ' ';
835
- break;
836
-
770
+ for (int i = 0; i < charline.length; i++) {
771
+ switch (charline[i]) {
772
+ case 'M':
773
+ case 'm':
774
+ case 'Z':
775
+ case 'z':
776
+ case 'C':
777
+ case 'c':
778
+ case 'S':
779
+ case 's':
780
+ case 'L':
781
+ case 'l':
782
+ case 'H':
783
+ case 'h':
784
+ case 'V':
785
+ case 'v':
786
+ charline = PApplet.splice(charline, ' ', i);
787
+ i++;
788
+ charline = PApplet.splice(charline, ' ', i + 1);
789
+ i++;
790
+ break;
791
+
792
+ case '-':
793
+ if (i > 0 && charline[i - 1] != 'e' && charline[i - 1] != 'E') {
794
+ charline = PApplet.splice(charline, ' ', i);
795
+ i++;
837
796
  }
797
+ break;
798
+ case ',':
799
+ case '\n':
800
+ case '\r':
801
+ case '\t':
802
+ charline[i] = ' ';
803
+ break;
804
+
838
805
  }
806
+ }
839
807
  String formatted = new String(charline);
840
808
  String[] tags = PApplet.splitTokens(formatted);
841
809
 
842
810
  //PApplet.println("formatted: " + formatted);
843
811
  //PApplet.println("tags: ");
844
812
  //PApplet.println(tags);
845
-
846
813
  //build points
847
814
  RPoint curp = new RPoint();
848
815
  RPoint relp = new RPoint();
@@ -851,132 +818,129 @@ public class RSVG
851
818
 
852
819
  char command = 'a';
853
820
 
854
- for (int i=0;i<tags.length;i++)
855
- {
856
- char nextChar = tags[i].charAt(0);
857
- switch(nextChar)
858
- {
859
- case 'm':
860
- case 'M':
861
- case 'c':
862
- case 'C':
863
- case 's':
864
- case 'S':
865
- case 'l':
866
- case 'L':
867
- case 'h':
868
- case 'H':
869
- case 'v':
870
- case 'V':
871
- i += 1;
872
- case 'z':
873
- case 'Z':
874
- command = nextChar;
875
- break;
876
- default:
877
- if (command == 'm') {
878
- command = 'l';
879
- } else if (command == 'M') {
880
- command = 'L';
881
- }
882
- }
883
-
884
- relp.setLocation(0F, 0F);
885
-
886
- switch(command)
887
- {
888
- case 'm':
889
- relp.setLocation(curp.x, curp.y);
890
- case 'M':
891
- i = move(shp, curp, relp, refp, strp, tags, i);
892
- break;
893
-
894
- case 'z':
895
- relp.setLocation(curp.x, curp.y);
896
- case 'Z':
897
- shp.addClose();
898
- break;
899
-
900
- case 'c':
901
- relp.setLocation(curp.x, curp.y);
902
- case 'C':
903
- i = curve(shp, curp, relp, refp, strp, tags, i);
904
- break;
905
-
906
- case 's':
907
- relp.setLocation(curp.x, curp.y);
908
- case 'S':
909
- i = smooth(shp, curp, relp, refp, strp, tags, i);
910
- break;
911
-
912
- case 'l':
913
- relp.setLocation(curp.x, curp.y);
914
- case 'L':
915
- i = line(shp, curp, relp, refp, strp, tags, i);
916
- break;
917
-
918
- case 'h':
919
- relp.setLocation(curp.x, curp.y);
920
- case 'H':
921
- i = horizontal(shp, curp, relp, refp, strp, tags, i);
922
- break;
923
-
924
- case 'v':
925
- relp.setLocation(curp.x, curp.y);
926
- case 'V':
927
- i = vertical(shp, curp, relp, refp, strp, tags, i);
928
- break;
821
+ for (int i = 0; i < tags.length; i++) {
822
+ char nextChar = tags[i].charAt(0);
823
+ switch (nextChar) {
824
+ case 'm':
825
+ case 'M':
826
+ case 'c':
827
+ case 'C':
828
+ case 's':
829
+ case 'S':
830
+ case 'l':
831
+ case 'L':
832
+ case 'h':
833
+ case 'H':
834
+ case 'v':
835
+ case 'V':
836
+ i += 1;
837
+ case 'z':
838
+ case 'Z':
839
+ command = nextChar;
840
+ break;
841
+ default:
842
+ if (command == 'm') {
843
+ command = 'l';
844
+ } else if (command == 'M') {
845
+ command = 'L';
929
846
  }
930
847
  }
848
+
849
+ relp.setLocation(0F, 0F);
850
+
851
+ switch (command) {
852
+ case 'm':
853
+ relp.setLocation(curp.x, curp.y);
854
+ case 'M':
855
+ i = move(shp, curp, relp, refp, strp, tags, i);
856
+ break;
857
+
858
+ case 'z':
859
+ relp.setLocation(curp.x, curp.y);
860
+ case 'Z':
861
+ shp.addClose();
862
+ break;
863
+
864
+ case 'c':
865
+ relp.setLocation(curp.x, curp.y);
866
+ case 'C':
867
+ i = curve(shp, curp, relp, refp, strp, tags, i);
868
+ break;
869
+
870
+ case 's':
871
+ relp.setLocation(curp.x, curp.y);
872
+ case 'S':
873
+ i = smooth(shp, curp, relp, refp, strp, tags, i);
874
+ break;
875
+
876
+ case 'l':
877
+ relp.setLocation(curp.x, curp.y);
878
+ case 'L':
879
+ i = line(shp, curp, relp, refp, strp, tags, i);
880
+ break;
881
+
882
+ case 'h':
883
+ relp.setLocation(curp.x, curp.y);
884
+ case 'H':
885
+ i = horizontal(shp, curp, relp, refp, strp, tags, i);
886
+ break;
887
+
888
+ case 'v':
889
+ relp.setLocation(curp.x, curp.y);
890
+ case 'V':
891
+ i = vertical(shp, curp, relp, refp, strp, tags, i);
892
+ break;
893
+ }
894
+ }
931
895
  return shp;
932
896
  }
933
897
 
934
- private int move(RShape shp, RPoint curp, RPoint relp, RPoint refp, RPoint strp, String[] tags, int i){
935
- shp.addMoveTo(PApplet.parseFloat(tags[i])+relp.x, PApplet.parseFloat(tags[i+1])+relp.y);
898
+ private int move(RShape shp, RPoint curp, RPoint relp, RPoint refp, RPoint strp, String[] tags, int i) {
899
+ shp.addMoveTo(PApplet.parseFloat(tags[i]) + relp.x, PApplet.parseFloat(tags[i + 1]) + relp.y);
936
900
 
937
- curp.setLocation(PApplet.parseFloat(tags[i])+relp.x, PApplet.parseFloat(tags[i+1])+relp.y);
938
- refp.setLocation(curp.x,curp.y);
939
- strp.setLocation(curp.x,curp.y);
901
+ curp.setLocation(PApplet.parseFloat(tags[i]) + relp.x, PApplet.parseFloat(tags[i + 1]) + relp.y);
902
+ refp.setLocation(curp.x, curp.y);
903
+ strp.setLocation(curp.x, curp.y);
940
904
  //relp.setLocation(0F, 0F);
941
905
  return i + 1;
942
906
  }
943
907
 
944
- private int curve(RShape shp, RPoint curp, RPoint relp, RPoint refp, RPoint strp, String[] tags, int i){
945
- shp.addBezierTo(PApplet.parseFloat(tags[i])+relp.x, PApplet.parseFloat(tags[i+1])+relp.y, PApplet.parseFloat(tags[i+2])+relp.x, PApplet.parseFloat(tags[i+3])+relp.y, PApplet.parseFloat(tags[i+4])+relp.x, PApplet.parseFloat(tags[i+5])+relp.y);
908
+ private int curve(RShape shp, RPoint curp, RPoint relp, RPoint refp, RPoint strp, String[] tags, int i) {
909
+ shp.addBezierTo(PApplet.parseFloat(tags[i]) + relp.x, PApplet.parseFloat(tags[i + 1]) + relp.y, PApplet.parseFloat(tags[i + 2]) + relp.x, PApplet.parseFloat(tags[i + 3]) + relp.y, PApplet.parseFloat(tags[i + 4]) + relp.x, PApplet.parseFloat(tags[i + 5]) + relp.y);
946
910
 
947
- curp.setLocation(PApplet.parseFloat(tags[i+4])+relp.x, PApplet.parseFloat(tags[i+5])+relp.y);
948
- refp.setLocation(2.0f*curp.x-(PApplet.parseFloat(tags[i+2])+relp.x), 2.0f*curp.y-(PApplet.parseFloat(tags[i+3])+relp.y));
911
+ curp.setLocation(PApplet.parseFloat(tags[i + 4]) + relp.x, PApplet.parseFloat(tags[i + 5]) + relp.y);
912
+ refp.setLocation(2.0f * curp.x - (PApplet.parseFloat(tags[i + 2]) + relp.x), 2.0f * curp.y - (PApplet.parseFloat(tags[i + 3]) + relp.y));
949
913
  return i + 5;
950
914
  }
951
915
 
952
- private int smooth(RShape shp, RPoint curp, RPoint relp, RPoint refp, RPoint strp, String[] tags, int i){
953
- shp.addBezierTo(refp.x, refp.y, PApplet.parseFloat(tags[i])+relp.x, PApplet.parseFloat(tags[i+1])+relp.y, PApplet.parseFloat(tags[i+2])+relp.x, PApplet.parseFloat(tags[i+3])+relp.y);
916
+ private int smooth(RShape shp, RPoint curp, RPoint relp, RPoint refp, RPoint strp, String[] tags, int i) {
917
+ shp.addBezierTo(refp.x, refp.y, PApplet.parseFloat(tags[i]) + relp.x, PApplet.parseFloat(tags[i + 1]) + relp.y, PApplet.parseFloat(tags[i + 2]) + relp.x, PApplet.parseFloat(tags[i + 3]) + relp.y);
954
918
 
955
- curp.setLocation(PApplet.parseFloat(tags[i+2])+relp.x, PApplet.parseFloat(tags[i+3])+relp.y);
956
- refp.setLocation(2.0f*curp.x-(PApplet.parseFloat(tags[i])+relp.x), 2.0f*curp.y-(PApplet.parseFloat(tags[i+1])+relp.y));
919
+ curp.setLocation(PApplet.parseFloat(tags[i + 2]) + relp.x, PApplet.parseFloat(tags[i + 3]) + relp.y);
920
+ refp.setLocation(2.0f * curp.x - (PApplet.parseFloat(tags[i]) + relp.x), 2.0f * curp.y - (PApplet.parseFloat(tags[i + 1]) + relp.y));
957
921
  return i + 3;
958
922
  }
959
923
 
960
- private int line(RShape shp, RPoint curp, RPoint relp, RPoint refp, RPoint strp, String[] tags, int i){
961
- shp.addLineTo(PApplet.parseFloat(tags[i])+relp.x, PApplet.parseFloat(tags[i+1])+relp.y);
924
+ private int line(RShape shp, RPoint curp, RPoint relp, RPoint refp, RPoint strp, String[] tags, int i) {
925
+ shp.addLineTo(PApplet.parseFloat(tags[i]) + relp.x, PApplet.parseFloat(tags[i + 1]) + relp.y);
962
926
 
963
- curp.setLocation(PApplet.parseFloat(tags[i])+relp.x, PApplet.parseFloat(tags[i+1])+relp.y);
927
+ curp.setLocation(PApplet.parseFloat(tags[i]) + relp.x, PApplet.parseFloat(tags[i + 1]) + relp.y);
964
928
  refp.setLocation(curp.x, curp.y);
965
929
  return i + 1;
966
930
  }
967
931
 
968
- private int horizontal(RShape shp, RPoint curp, RPoint relp, RPoint refp, RPoint strp, String[] tags, int i){
969
- shp.addLineTo(PApplet.parseFloat(tags[i])+relp.x, curp.y);
932
+ private int horizontal(RShape shp, RPoint curp, RPoint relp, RPoint refp, RPoint strp, String[] tags, int i) {
933
+ shp.addLineTo(PApplet.parseFloat(tags[i]) + relp.x, curp.y);
970
934
 
971
- curp.setLocation(PApplet.parseFloat(tags[i])+relp.x, curp.y);
935
+ curp.setLocation(PApplet.parseFloat(tags[i]) + relp.x, curp.y);
972
936
  refp.setLocation(curp.x, curp.y);
973
937
  return i;
974
938
  }
975
939
 
976
- private int vertical(RShape shp, RPoint curp, RPoint relp, RPoint refp, RPoint strp, String[] tags, int i){
977
- shp.addLineTo(curp.x, PApplet.parseFloat(tags[i])+relp.y);
940
+ private int vertical(RShape shp, RPoint curp, RPoint relp, RPoint refp, RPoint strp, String[] tags, int i) {
941
+ shp.addLineTo(curp.x, PApplet.parseFloat(tags[i]) + relp.y);
978
942
 
979
- curp.setLocation(curp.x, PApplet.parseFloat(tags[i])+relp.y);
943
+ curp.setLocation(curp.x, PApplet.parseFloat(tags[i]) + relp.y);
980
944
  refp.setLocation(curp.x, curp.y);
981
945
  return i;
982
946
  }