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
Types
Type TSVGCairo Extends TCairo |
Description | SVG savvy Cairo Type. |
Information | This 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() |
Returns | 0 for success, or an error status value. (See ParseSVG for list of possible values) |
Description | Removes the current SVG context and its associated resources. |
Method GetSVGSize:Int(width:Int Var, height:Int Var) |
Returns | 0 for success, or an error status value. (See ParseSVG for list of possible values) |
Description | Returns the current width and height of the current SVG image into the specified parameters. |
Information | Parameters:
- width : width of the current SVG image (out parameter)
- height : height of the current SVG image (out parameter)
|
Method ParseSVG:Int(filename:String) |
Returns | 0 for success, or an error status value. |
Description | Loads 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() |
Returns | 0 for success, or an error status value. (See ParseSVG for list of possible values) |
Description | Renders the current SVG image onto the Cairo context. |
Information | How the image renders is dependent on use of methods such as
Scale,
Translate,
Rotate and
PaintWithAlpha. |
Module Information
Version | 1.02 |
License | LGPL |
Author | University of Southern California and Carl D. Worth |
Credit | Adapted for BlitzMax by Bruce Henderson |
Modserver | BRL |
History | 1.02 |
History | Updates to cvs versions of libsvg and libsvg-cairo (1 Dec 2006) |
History | 1.01 |
History | Changed to support revised Type structure for TCairo |
History | 1.00 Initial Release (libsvg 0.1.4 and libsvg-cairo 0.1.6) |