The svg2swf command-line usage is shown below.

Usage: svg2swf [options] (- | <svg uri or filename>) [<swf filename>]

-h | --help Print this usage message and examples and exit
--trace Print render engine calls to standard output
--font-info <filename> Print font information for the .ttf or .fdb font <filename> and exit
The format matches that required for --font
--asf <filename> Add actionscript text in <filename> to movie
--default-font <filename> Set the default font to <filename>
--font <name> <style> <filename> <name> is compared with the SVG font family name to find a match
<style> is a combination of letters, N (normal), B (bold), I (italic), O (oblique)
Valid <style> combinations are: N, B, I, O, BI, BO
<filename> is the font filename
--cubic <thresh> Threshold value for approximating cubic bezier curves (default 100)
--pat-res <factor> Pattern bitmap resolution factor (default 2.0)
--dsize <width>x<height> Default dimensions if SVG doesn't define a width or height (default 450.0x450.0)
--create-sprites Create a sprite (movie clip) for SVG elements with an id attribute; sprite name equals element id

The following illustrates the command-line for converting a source SVG document, example.svg, to a target Flash file, example.swf,

svg2swf example.svg example.swf

The same can be achieved using the stdin (identified using -) and stdout streams,

cat example.svg | svg2swf - >example.swf

svg2swf also accepts an SVG document URI. For example,

svg2swf example.swf

The --trace option is useful for understanding how the SVG document content is mapped to function calls in the render engine API (svg.h). It prints out the function calls and parameters, the URI of the source document (in_document and out_document) and the client application calls to render an element (begin_render and end_render). The element name and line number are shown in brackets (<>) after the begin_group and begin_element calls. The following illustrates the --trace option:

svg2swf --trace example.swf >Use03.trace.txt

The result is the following trace output: Use03.trace.txt.

The --asf option can be used to attach actionscript code to the Flash movie. An example actionscript file,, is provided to allow simple panning and zooming using the mouse and keyboard.

svg2swf has basic support for embedding (converted) TrueType (.ttf) and Ming font file (.fdb) fonts in the Flash file. It is recommended that users provide a default font file. Use the --default-font option to set the default font.

If there is no match for the SVG font family name and there is no default font then svg2swf uses a browser (device) font in a text field. There are disadvantages in using a text field to display text. For example, the text is positioned less accurately, rotated text doesn't show, text cannot be used in clipping paths or masks and only a single format (e.g. colour) can be used for each chunk of text.

Use the --font option to define the font to be used for text which has a corresponding font family name and style. The --font-info option can be used to extract the font information. E.g.

svg2swf --font-info ../../ming/test/Media/font01.fdb

results in the output string: "Bitstream Vera Sans" N "../../ming/test/Media/font01.fdb". This can then be passed to svg2swf using the --font parameter,

svg2swf --font "Bitstream Vera Sans" N "../../ming/test/Media/font01.fdb" example.svg example.swf

The font will only be used if the <name> matches the SVG document's font family name exactly. The same font file can be mapped to different <names> and <styles>.

The libming source package contains two font files which can be used for testing:

Flash only supports quadratic Bézier curves whilst SVG also defines cubic Bézier curves. The libming library includes a SWFShape_drawCubicTo function to approximate cubic curves using quadratic curves. The precision of the approximation is determined by the --cubic <threshold> value. Lower the value to get a better approximation, but at the cost of increased processing time and number of quadratic curves.

The --pat-res option can be used to set the resolution of the bitmaps used in pattern fills. Flash only supports bitmap patterns and therefore the content of pattern elements in SVG needs to be rendered to a bitmap. A resolution factor of 1 means the bitmap resolution is the same as it would be if the graphics were rendered at the resolution defined by the dimensions of the SVG document. A higher resolution factor (the default is 2) means the graphics can be enlarged without resulting in blockiness appearing in the patterns.

Some SVG documents don't define a width or height, or they define them as a percentage. The --dsize <width>x<height> option allows you to set a different default dimension for these cases.

The --create-sprites option is one example of how hooks can be provided to allow actionscript to reference the shapes produced from the SVG elements. SVG elements with an id attribute are mapped to a sprite (movie clip) containing the shape and this sprite can be referenced and manipulated using actionscript. This is just an example and a different approach is likely once the requirements are clearer.

Get svg2swf at Fast, secure and Free Open Source software downloads Valid XHTML 1.0 Strict