Library "libcairo:2"
Private Enum CAIRO_FONT_SLANT_NORMAL = 0, CAIRO_FONT_SLANT_ITALIC, CAIRO_FONT_SLANT_OBLIQUE
Private Enum CAIRO_FONT_WEIGHT_NORMAL = 0, CAIRO_FONT_WEIGHT_BOLD
Private Enum CAIRO_FORMAT_INVALID = -1, CAIRO_FORMAT_ARGB32, CAIRO_FORMAT_RGB24, CAIRO_FORMAT_A8,
CAIRO_FORMAT_A1, CAIRO_FORMAT_RGB16_565, CAIRO_FORMAT_RGB30
' cairo_surface_t * cairo_image_surface_create(cairo_format_t formatI, int width, int height)
' Creates an image surface of the specified format and dimensions.
Private Extern cairo_image_surface_create(formatI As Integer, width As Integer, height As Integer) As Pointer
' cairo_t* cairo_create(cairo_surface_t *target)
' Creates a new cairo_t with all graphics state parameters set to default values and with target as a target surface.
Private Extern cairo_create(target As Pointer) As Pointer
' void cairo_set_font_size(cairo_t *cr, double size)
' Sets the current font matrix to a scale by a factor of size.
Private Extern cairo_set_font_size(cr As Pointer, size As Float)
' void cairo_select_font_face(cairo_t *cr, const char *family, cairo_font_slant_t slant, cairo_font_weight_t weight)
' Selects a family and style of font from a simplified description as a family name, slant and weight.
Private Extern cairo_select_font_face(cr As Pointer, family As String, slant As Integer, font_weight As Integer)
' void cairo_move_to(cairo_t *cr, double x, double y)
' Begin a new sub-path.
Private Extern cairo_move_to(cr As Pointer, xF As Float, yF As Float)
' void cairo_text_path (cairo_t *cr, const char *utf8)
' Adds closed paths for text to the current path.
Private Extern cairo_text_path(cr As Pointer, utf8 As String)
' void cairo_fill_preserve (cairo_t *cr)
' Preserves the path within the cairo context.
Private Extern cairo_fill_preserve(cr As Pointer)
' void cairo_set_source_rgb(cairo_t *cr, double red, double green, double blue)
' Sets the source pattern within cr to an opaque color.
Private Extern cairo_set_source_rgb(cr As Pointer, red As Float, green As Float, blue As Float)
' void cairo_stroke (cairo_t *cr)
' void A drawing operator that strokes the current path according to the current line width.
Private Extern cairo_stroke(cr As Pointer)
' cairo_status_t cairo_surface_write_to_png(cairo_surface_t *surface, const char *filename)
' Writes the contents of surface to a new file filename as a PNG image.
Private Extern cairo_surface_write_to_png(cairo_surface As Pointer, filename As String) As Integer
' void cairo_destroy(cairo_t *cr)
' Decreases the reference count on cr by one.
Private Extern cairo_destroy(cr As Pointer)
' void cairo_surface_destroy(cairo_surface_t *surface)
' Decreases the reference count on surface by one.
Private Extern cairo_surface_destroy(cairo_surface As Pointer)
Public Sub Main()
Dim cairo, surface As Pointer
Dim err As Integer
' Crea la superficie dell'immagine (in questo caso trasparente):
surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 300, 300)
cairo = cairo_create(surface)
' Imposta il font:
cairo_set_font_size(cairo, 60)
cairo_select_font_face(cairo, "URW Palladio L", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL)
cairo_move_to(cairo, 50, 100)
cairo_text_path(cairo, "Events")
cairo_set_source_rgb(cairo, 0.5, 1.0, 0.0)
cairo_fill_preserve(cairo)
' Crea il contorno:
cairo_set_source_rgb(cairo, 1, 0, 0)
cairo_stroke(cairo)
err = cairo_surface_write_to_png(surface, "/tmp/esempio_Cairo.png")
If err > 0 Then Error.Raise("Errore nella creazione del file immagine .png !")
' Per generare il file stabilito, è necessario distruggere il contesto grafico "cairo_t" e la superficie dell'immagine:
cairo_destroy(cairo)
cairo_surface_destroy(surface)
End