@@ -137,64 +137,6 @@ public PShapeSVG(XML svg) {
137137 }
138138
139139
140- // Broken out so that subclasses can copy any additional variables
141- // (i.e. fillGradientPaint and strokeGradientPaint)
142- protected void setParent (PShapeSVG parent ) {
143- // Need to set this so that findChild() works.
144- // Otherwise 'parent' is null until addChild() is called later.
145- this .parent = parent ;
146-
147- if (parent == null ) {
148- // set values to their defaults according to the SVG spec
149- stroke = false ;
150- strokeColor = 0xff000000 ;
151- strokeWeight = 1 ;
152- strokeCap = PConstants .SQUARE ; // equivalent to BUTT in svg spec
153- strokeJoin = PConstants .MITER ;
154- strokeGradient = null ;
155- // strokeGradientPaint = null;
156- strokeName = null ;
157-
158- fill = true ;
159- fillColor = 0xff000000 ;
160- fillGradient = null ;
161- // fillGradientPaint = null;
162- fillName = null ;
163-
164- //hasTransform = false;
165- //transformation = null; //new float[] { 1, 0, 0, 1, 0, 0 };
166-
167- // svgWidth, svgHeight, and svgXYSize done below.
168-
169- strokeOpacity = 1 ;
170- fillOpacity = 1 ;
171- opacity = 1 ;
172-
173- } else {
174- stroke = parent .stroke ;
175- strokeColor = parent .strokeColor ;
176- strokeWeight = parent .strokeWeight ;
177- strokeCap = parent .strokeCap ;
178- strokeJoin = parent .strokeJoin ;
179- strokeGradient = parent .strokeGradient ;
180- // strokeGradientPaint = parent.strokeGradientPaint;
181- strokeName = parent .strokeName ;
182-
183- fill = parent .fill ;
184- fillColor = parent .fillColor ;
185- fillGradient = parent .fillGradient ;
186- // fillGradientPaint = parent.fillGradientPaint;
187- fillName = parent .fillName ;
188-
189- svgWidth = parent .svgWidth ;
190- svgHeight = parent .svgHeight ;
191- svgXYSize = parent .svgXYSize ;
192-
193- opacity = parent .opacity ;
194- }
195- }
196-
197-
198140 protected PShapeSVG (PShapeSVG parent , XML properties , boolean parseKids ) {
199141 setParent (parent );
200142
@@ -280,6 +222,70 @@ protected PShapeSVG(PShapeSVG parent, XML properties, boolean parseKids) {
280222 }
281223
282224
225+ // Broken out so that subclasses can copy any additional variables
226+ // (i.e. fillGradientPaint and strokeGradientPaint)
227+ protected void setParent (PShapeSVG parent ) {
228+ // Need to set this so that findChild() works.
229+ // Otherwise 'parent' is null until addChild() is called later.
230+ this .parent = parent ;
231+
232+ if (parent == null ) {
233+ // set values to their defaults according to the SVG spec
234+ stroke = false ;
235+ strokeColor = 0xff000000 ;
236+ strokeWeight = 1 ;
237+ strokeCap = PConstants .SQUARE ; // equivalent to BUTT in svg spec
238+ strokeJoin = PConstants .MITER ;
239+ strokeGradient = null ;
240+ // strokeGradientPaint = null;
241+ strokeName = null ;
242+
243+ fill = true ;
244+ fillColor = 0xff000000 ;
245+ fillGradient = null ;
246+ // fillGradientPaint = null;
247+ fillName = null ;
248+
249+ //hasTransform = false;
250+ //transformation = null; //new float[] { 1, 0, 0, 1, 0, 0 };
251+
252+ // svgWidth, svgHeight, and svgXYSize done below.
253+
254+ strokeOpacity = 1 ;
255+ fillOpacity = 1 ;
256+ opacity = 1 ;
257+
258+ } else {
259+ stroke = parent .stroke ;
260+ strokeColor = parent .strokeColor ;
261+ strokeWeight = parent .strokeWeight ;
262+ strokeCap = parent .strokeCap ;
263+ strokeJoin = parent .strokeJoin ;
264+ strokeGradient = parent .strokeGradient ;
265+ // strokeGradientPaint = parent.strokeGradientPaint;
266+ strokeName = parent .strokeName ;
267+
268+ fill = parent .fill ;
269+ fillColor = parent .fillColor ;
270+ fillGradient = parent .fillGradient ;
271+ // fillGradientPaint = parent.fillGradientPaint;
272+ fillName = parent .fillName ;
273+
274+ svgWidth = parent .svgWidth ;
275+ svgHeight = parent .svgHeight ;
276+ svgXYSize = parent .svgXYSize ;
277+
278+ opacity = parent .opacity ;
279+ }
280+ }
281+
282+
283+ /** Factory method for subclasses. */
284+ protected PShapeSVG createShape (PShapeSVG parent , XML properties , boolean parseKids ) {
285+ return new PShapeSVG (parent , properties , parseKids );
286+ }
287+
288+
283289 protected void parseChildren (XML graphics ) {
284290 XML [] elements = graphics .getChildren ();
285291 children = new PShape [elements .length ];
@@ -307,49 +313,39 @@ protected PShape parseChild(XML elem) {
307313 // just some whitespace that can be ignored (hopefully)
308314
309315 } else if (name .equals ("g" )) {
310- //return new BaseObject(this, elem);
311- shape = new PShapeSVG (this , elem , true );
316+ shape = createShape (this , elem , true );
312317
313318 } else if (name .equals ("defs" )) {
314319 // generally this will contain gradient info, so may
315320 // as well just throw it into a group element for parsing
316- //return new BaseObject(this, elem);
317- shape = new PShapeSVG (this , elem , true );
321+ shape = createShape (this , elem , true );
318322
319323 } else if (name .equals ("line" )) {
320- //return new Line(this, elem);
321- //return new BaseObject(this, elem, LINE);
322- shape = new PShapeSVG (this , elem , true );
324+ shape = createShape (this , elem , true );
323325 shape .parseLine ();
324326
325327 } else if (name .equals ("circle" )) {
326- //return new BaseObject(this, elem, ELLIPSE);
327- shape = new PShapeSVG (this , elem , true );
328+ shape = createShape (this , elem , true );
328329 shape .parseEllipse (true );
329330
330331 } else if (name .equals ("ellipse" )) {
331- //return new BaseObject(this, elem, ELLIPSE);
332- shape = new PShapeSVG (this , elem , true );
332+ shape = createShape (this , elem , true );
333333 shape .parseEllipse (false );
334334
335335 } else if (name .equals ("rect" )) {
336- //return new BaseObject(this, elem, RECT);
337- shape = new PShapeSVG (this , elem , true );
336+ shape = createShape (this , elem , true );
338337 shape .parseRect ();
339338
340339 } else if (name .equals ("polygon" )) {
341- //return new BaseObject(this, elem, POLYGON);
342- shape = new PShapeSVG (this , elem , true );
340+ shape = createShape (this , elem , true );
343341 shape .parsePoly (true );
344342
345343 } else if (name .equals ("polyline" )) {
346- //return new BaseObject(this, elem, POLYGON);
347- shape = new PShapeSVG (this , elem , true );
344+ shape = createShape (this , elem , true );
348345 shape .parsePoly (false );
349346
350347 } else if (name .equals ("path" )) {
351- //return new BaseObject(this, elem, PATH);
352- shape = new PShapeSVG (this , elem , true );
348+ shape = createShape (this , elem , true );
353349 shape .parsePath ();
354350
355351 } else if (name .equals ("radialGradient" )) {
0 commit comments