3
#include <pango/pangocairo.h>
6
draw_text (cairo_t *cr)
10
#define FONT "Sans Bold 27"
13
PangoFontDescription *desc;
16
/* Center coordinates on the middle of the region we are drawing
18
cairo_translate (cr, RADIUS, RADIUS);
20
/* Create a PangoLayout, set the font and text */
21
layout = pango_cairo_create_layout (cr);
23
pango_layout_set_text (layout, "Text", -1);
24
desc = pango_font_description_from_string (FONT);
25
pango_layout_set_font_description (layout, desc);
26
pango_font_description_free (desc);
28
/* Draw the layout N_WORDS times in a circle */
29
for (i = 0; i < N_WORDS; i++)
32
double angle = (360. * i) / N_WORDS;
37
/* Gradient from red at angle == 60 to blue at angle == 240 */
38
red = (1 + cos ((angle - 60) * G_PI / 180.)) / 2;
39
cairo_set_source_rgb (cr, red, 0, 1.0 - red);
41
cairo_rotate (cr, angle * G_PI / 180.);
43
/* Inform Pango to re-layout the text with the new transformation */
44
pango_cairo_update_layout (cr, layout);
46
pango_layout_get_size (layout, &width, &height);
47
cairo_move_to (cr, - ((double)width / PANGO_SCALE) / 2, - RADIUS);
48
pango_cairo_show_layout (cr, layout);
53
/* free the layout object */
54
g_object_unref (layout);
57
int main (int argc, char **argv)
61
cairo_status_t status;
62
cairo_surface_t *surface;
66
g_printerr ("Usage: cairosimple OUTPUT_FILENAME\n");
72
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
73
2 * RADIUS, 2 * RADIUS);
74
cr = cairo_create (surface);
77
cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
82
status = cairo_surface_write_to_png (surface, filename);
83
cairo_surface_destroy (surface);
85
if (status != CAIRO_STATUS_SUCCESS)
87
g_printerr ("Could not save png to '%s'\n", filename);