BaH.libsvg: Types Modinfo Source  

Cairo - libSVG

Cairo - libSVG is a BlitzMax module which adds SVG file loading and rendering capabilities to the Cairo module.

SVG stands for Scalable Vector Graphics, and is a language for describing two-dimensional graphics and graphical applications in XML. Key features include shapes, text and embedded raster graphics, with many different painting styles. More information about the SVG formt can be found at it's home at The W3C.

Working with libSVG

Typically, you will use libSVG much in the same way as with Cairo, since this is purely an extension of the other.
To load and use a .svg file with your Cairo context you can use the ParseSVG method as so:

status = cairo.ParseSVG("myPicture.svg")

If status = SVG_CAIRO_STATUS_SUCCESS Then
	cairo.RenderSVG()
End If

The nature of Cairo allows you to set up how objects (like lines and polygons) will be drawn, whether they are scaled, rotated and such like. An SVG works in exactly the same way. You specify how and where you wish it to be rendered on the Cairo context :

cairo.Scale(0.5, 0.5)  ' half size
cairo.Rotate(45)       ' rotate 45 degrees
cairo.RenderSVG()

There are some more complete examples listed below :

balls.bmx
head.bmx

Types Summary

TSVGCairo SVG savvy Cairo Type.

Types

Type TSVGCairo Extends TCairo
DescriptionSVG savvy Cairo Type.
InformationThis Type introduces some methods which allow the loading and rendering of SVG files into a Cairo context.
Methods Summary
DestroySVG Removes the current SVG context and its associated resources.
GetSVGSize Returns the current width and height of the current SVG image into the specified parameters.
ParseSVG Loads and parses a .svg file ready for rendering with Cairo.
RenderSVG Renders the current SVG image onto the Cairo context.
Method DestroySVG:Int()
Returns0 for success, or an error status value. (See ParseSVG for list of possible values)
DescriptionRemoves the current SVG context and its associated resources.
Method GetSVGSize:Int(width:Int Var, height:Int Var)
Returns0 for success, or an error status value. (See ParseSVG for list of possible values)
DescriptionReturns the current width and height of the current SVG image into the specified parameters.
InformationParameters:
  • width : width of the current SVG image (out parameter)
  • height : height of the current SVG image (out parameter)
Method ParseSVG:Int(filename:String)
Returns0 for success, or an error status value.
DescriptionLoads and parses a .svg file ready for rendering with Cairo.
Information

The following details possible status values :

Constant
SVG_CAIRO_STATUS_SUCCESS
SVG_CAIRO_STATUS_NO_MEMORY
SVG_CAIRO_STATUS_IO_ERROR
SVG_CAIRO_STATUS_FILE_NOT_FOUND
SVG_CAIRO_STATUS_INVALID_VALUE
SVG_CAIRO_STATUS_INVALID_CALL
SVG_CAIRO_STATUS_PARSE_ERROR
SVG_CAIRO_STATUS_INIT_ERROR
Method RenderSVG:Int()
Returns0 for success, or an error status value. (See ParseSVG for list of possible values)
DescriptionRenders the current SVG image onto the Cairo context.
InformationHow the image renders is dependent on use of methods such as Scale, Translate, Rotate and PaintWithAlpha.

Module Information

Version1.02
LicenseLGPL
AuthorUniversity of Southern California and Carl D. Worth
CreditAdapted for BlitzMax by Bruce Henderson
ModserverBRL
History1.02
HistoryUpdates to cvs versions of libsvg and libsvg-cairo (1 Dec 2006)
History1.01
HistoryChanged to support revised Type structure for TCairo
History1.00 Initial Release (libsvg 0.1.4 and libsvg-cairo 0.1.6)