3.16.11. Producing SVG Graphics
(lsh/libstd/svgwindow.lsh)


SVG (Scalable Vector Graphics) is a W3C standard for vector graphics. Lush can produce SVG graphics into an SVG file that can be subsequently edited with SVG-compatible drawing tools such as inkscape and sodipodi on Linux.

Producing an SVG file from Lush graphic is easily achieved using the svg-window function. The resulting window descriptor works like standard lush graphic windows.

Graphic commands evaluated within a graphics-batch generate graphics objects that are grouped together. Bitmap images inserted in the SVG file through rgb-draw-matrix are saved in separate PNG files in the same directory as the SVG file. If the SVG file name is "/mydir/myfile.svg", the image files will be "/mydir/myfile-XXXX.png", where XXXX is a 4-digit integer.

The implementation of svg-window relies on class SVGWindow . An instance of this class can be obtained by applying function lisp-driver-delegate to the window descriptor. Class SVGWindow defines a number of new methods for drawing objects. This includes manipulating coordinate transforms, stroke width, stroke styles, separate stroke color and fill color, opacity, etc.



3.16.11.0. (svg-window [w h] name [rw rh units])
[DM] (lsh/libstd/svgwindow.lsh)


Function svg-window creates a window descriptor that produces an SVG file named name .

Arguments w and h specify the width and height of the drawing rectangle in drawing units (default: 512x512). Optional arguments rw rh and units indicate the physical size of the rectangle into which the drawing rectangle will be mapped (not necessarily preserving the aspect ratio). units is the unit in which this physical size is expressed. The default is "px" (pixels). Possible units are "pt" (=1.25px), "pc" (=15px), "mm" (=3.543307px), "cm" (=35.43307px), and "in" (=90px). By default, the real size is w px by h px. hence the resolution is 90 units per inch.

Unlike new-window or print-window , this function does not store the newly created window in the variable window , and thus does not make this window current.



3.16.11.1. SVGWindow
(lsh/libstd/svgwindow.lsh)


The implementation of svg-window relies on class SVGWindow . An instance of this class can be obtained by applying function lisp-driver-delegate to the window descriptor. Class SVGWindow defines a number of new methods for drawing objects. This includes manipulating coordinate transforms, stroke width, stroke styles, separate stroke color and fill color, opacity, etc.
 (let* ((window (svg-window 500 500 "myfile.svg"))
        (wobject (lisp-driver-delegate window)) )
   (draw-rect 100 100 300 300)
   (==> wobject start-group 120 240 -45 1 1)
   (draw-text 0 -12 "slanted text")
   (==> wobject end-group) )


3.16.11.2. (new SVGWindow svg-file w h [real-width real-height units])
[CLASS] (lsh/libstd/svgwindow.lsh)


Create a new SVGWindow object whose output is written to the file svg-file . The parameters w and h are size of the window in drawing coordinates (i.e. a object drawn at coordinates (0, 0) will be in the upper left corner, and an object with coordinates ( w , h ) will be in the lower right corner of the drawing area. Optional parameters real-width and real-height give the physical size of a rectangle within which the drawing are will be mapped (not necessarily preserving the aspect ratio). units is a string with the name of the units in which these sizes are expressed. The default is "px" (pixels). Possible units are "pt" (=1.25px), "pc" (=15px), "mm" (=3.543307px), "cm" (=35.43307px), and "in" (=90px). By default, the real size is w px by h px. hence the resolution is 90 units per inch. example:
  ;; make a drawing whose real size is 180x90mm
  ;; but the drawing coordinate range from 0,0 to 2000,1000
  (new SVGWindow "stuff.svg" 2000 1000 180 90 "mm")


3.16.11.3. Drawing Methods Specific to SVGWindow
(lsh/libstd/svgwindow.lsh)


These methods have no equivalent in traditional Lush graphic drivers.

3.16.11.3.0. (==> SVGWindow fill-opacity x)
[MSG] (lsh/libstd/svgwindow.lsh)


Set the opacity of fill operations.

3.16.11.3.1. (==> SVGWindow stroke-opacity x)
[MSG] (lsh/libstd/svgwindow.lsh)


Set the opacity of strokes.

3.16.11.3.2. (==> SVGWindow opacity x)
[MSG] (lsh/libstd/svgwindow.lsh)


Set the general opacity.

3.16.11.3.3. (==> SVGWindow stroke-width x)
[MSG] (lsh/libstd/svgwindow.lsh)


Set the stroke width.

3.16.11.3.4. (==> SVGWindow stroke-color x)
[MSG] (lsh/libstd/svgwindow.lsh)


Set the color used for strokes and outlines.

3.16.11.3.5. (==> SVGWindow fill-color x)
[MSG] (lsh/libstd/svgwindow.lsh)


Set the color used for filled shapes

3.16.11.3.6. (==> SVGWindow start-group [tx ty r sx sy skx sky])
[MSG] (lsh/libstd/svgwindow.lsh)


Start a new group of drawing commands. The optional arguments can be used to specify a local coordinate transform. tx and ty are the horizontal and vertical translations, r a clockwise rotation angle in degrees, and sx and sy are scaling factors, and skx and sky are skew angles in degrees along the X and Y axes. The order fo transformations is: translation, skew, rotation, scaling. The group is terminated by a call to the end-group method. This command can be handy for drawing rotated objects. For example, drawing a vertical text at coordinate 100 200 can be done with:
 
 (==> my-SVGWindow start-group 100 200 -90 1 1) 
 (draw-text 0 0 "blah blah")
 (==> my-SVGWindow end-group)


3.16.11.3.7. (==> SVGWindow end-group)
[MSG] (lsh/libstd/svgwindow.lsh)


End a group started with start-group , possibly restoring the previous coordinate system.

3.16.11.3.8. (==> SVGWindow gspecial s)
[MSG] (lsh/libstd/svgwindow.lsh)


Write string s into the SVG file. This allows to write raw SVG directly.

3.16.11.3.9. (==> SVGWindow font [s])
[MSG] (lsh/libstd/svgwindow.lsh)




3.16.11.4. (svg-demo "myfile.svg")
(lsh/libstd/svgwindow.lsh)


This is a simple demo code of the capabilitied SVG windows. Call this function, then edit myfile.svg with sodipodi or inkscape.