/* gcc -Wall `pkg-config --cflags --libs cairo` test.c -o test */ #include #include #include static const char font_family [] = "Terminus" ; static void render_text (cairo_surface_t * surface) { const char * text ; cairo_t * cr ; cr = cairo_create (surface) ; cairo_set_source_rgb (cr, 1.0, 1.0, 1.0) ; /* Print title. */ cairo_select_font_face (cr, font_family, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL) ; cairo_set_font_size (cr, 30.0) ; text = "Big text" ; cairo_move_to (cr, 20.0, 48.0) ; cairo_show_text (cr, text) ; cairo_set_font_size (cr, 12.0) ; text = "Normal text" ; cairo_move_to (cr, 20.0, 100.0) ; cairo_show_text (cr, text) ; cairo_destroy (cr) ; } /* render_text */ int main (void) { cairo_surface_t * surface = NULL ; cairo_status_t status ; surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, 400, 300) ; if (surface == NULL || cairo_surface_status (surface) != CAIRO_STATUS_SUCCESS) { status = cairo_surface_status (surface) ; printf ("Error while creating surface : %s\n", cairo_status_to_string (status)) ; exit (1) ; } ; cairo_surface_flush (surface) ; render_text (surface) ; status = cairo_surface_write_to_png (surface, "test.png") ; if (status != CAIRO_STATUS_SUCCESS) printf ("Error while creating PNG file : %s\n", cairo_status_to_string (status)) ; cairo_surface_destroy (surface) ; return 0 ; } /* main */