To get a good idea on how to use libart
in your own application, here is a simple example which does
nothing but render in a pixel buffer a small square. The full
source for this example is available for download:
(includes a simple Makefile to build it).
The above VPath is a list of drawing commands. There are 5 different drawing commands:
ART_LINETO, ART_CURVETO an ART_END.
ART_MOVETO and ART_MOVETO_OPEN describe where the
pen of the painter starts to draw the vectors. ART_MOVETO starts
a closed vector path (the last point of the vector path will be connected to the first one).
ART_END ends a vector path.
ART_LINETO and ART_CURVETO describe
the following point in the vector path.
ART_CURVETO is reserved for use with BPaths and
cannot be used with a Vpath.
The following figure summarizes the behaviour of these drawing commands:
Figure 1. Drawing commands
Once the SVP is built, we render it and save it to a file:
The rendering is itself pretty simple: we first fill the buffer with the 0xFFFFFFFF rgba color
(that is, 0xFFFFFF rgb color with a transparency of 0xFF which means no transparency at all. It
should be called opacity actually ;) with the art_rgb_run_alpha function.
Then, we fill the svp in the buffer with the 0xFF0000FF rgba color with the
Last, to save the pixel buffer, we just instantiate a GdkPixbuf
and save it with the pixbuf_save_to_file function we stole
from random pieces of code (namely, nautilus and gnome-iconedit).