asSVGFile

Part of wslib


see also: SVG, SVGFile


There are a few SC objects responding to asSVGFile:


work in progress


Function:asSVGFile

Env:asSVGFile



Function:asSVGFile ( path )

this method can create a valid SVG file from a function containing GUI.pen instructions. 

They are collected by ColPen (no documentation yet). The example below should demonstrate the use of this method:


(

d = { 

GUI.pen.use({ // creates an SVGGroup

GUI.pen.translate( 100, 50 );

if( GUI.pen.respondsTo( \color_ ) ) // means SwingOSC is installed

{ GUI.pen.color = Color.blue; }  // GUI style color setting

{ Color.blue.set };

GUI.pen.width = 5;

GUI.pen.moveTo( 10@10 );

GUI.pen.lineTo( 100@20 );

GUI.pen.stroke

});

if( GUI.pen.respondsTo( \color_ ) ) // means SwingOSC is installed

{ GUI.pen.color = Color.red; }  // GUI style color setting

{ Color.red.set };

GUI.pen.strokeOval( Rect(10,10,380,280 ) );

};

w = GUI.window.new( "testplot" ).front.drawHook_( d );

)


f = d.asSVGFile( "~/Desktop/test asSVGFile" ); // creates a file (doesn't write)


f.plot; // check if it looks the same


f.postTree; // view the contents of the SVGFile


f[0][0][0].segments.collect({ |seg| [ seg.type ] ++ seg.propertyArray });


f.write; // write to file (open in graphic application to see if it works)



Notes:

- there are a few problems due to lack of standardization for GUI style coding. This is why String.draw and Color.set are not supported. GUI.pen.color_ does work, but is not comatible with SC versions which have no SwingOSC installed. Hence the split trick in the above example. GUI.pen.stringAtPoint and alike methods will be implemented in the future.

- addArc, addWedge and addAnnularWedge are not yet implemented. Requires study.. (the arc drawing options in the SVG file format are quite different from those in SC)

- curveTo and quadCurveTo are implemented, even though SVGFile doesn't plot qCurves in SC. They will display correctly in graphic applications