1 /* Simple example to use pangocairo to render rotated text */
4 #include <pango/pangocairo.h>
7 draw_text (cairo_t *cr)
11 #define FONT "Sans Bold 27"
14 PangoFontDescription *desc;
17 /* Center coordinates on the middle of the region we are drawing
19 cairo_translate (cr, RADIUS, RADIUS);
21 /* Create a PangoLayout, set the font and text */
22 layout = pango_cairo_create_layout (cr);
24 pango_layout_set_text (layout, "Text", -1);
25 desc = pango_font_description_from_string (FONT);
26 pango_layout_set_font_description (layout, desc);
27 pango_font_description_free (desc);
29 /* Draw the layout N_WORDS times in a circle */
30 for (i = 0; i < N_WORDS; i++)
33 double angle = (360. * i) / N_WORDS;
38 /* Gradient from red at angle == 60 to blue at angle == 240 */
39 red = (1 + cos ((angle - 60) * G_PI / 180.)) / 2;
40 cairo_set_source_rgb (cr, red, 0, 1.0 - red);
42 cairo_rotate (cr, angle * G_PI / 180.);
44 /* Inform Pango to re-layout the text with the new transformation */
45 pango_cairo_update_layout (cr, layout);
47 pango_layout_get_size (layout, &width, &height);
48 cairo_move_to (cr, - ((double)width / PANGO_SCALE) / 2, - RADIUS);
49 pango_cairo_show_layout (cr, layout);
54 /* free the layout object */
55 g_object_unref (layout);
58 int main (int argc, char **argv)
62 cairo_status_t status;
63 cairo_surface_t *surface;
67 g_printerr ("Usage: cairosimple OUTPUT_FILENAME\n");
73 surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
74 2 * RADIUS, 2 * RADIUS);
75 cr = cairo_create (surface);
78 cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
83 status = cairo_surface_write_to_png (surface, filename);
84 cairo_surface_destroy (surface);
86 if (status != CAIRO_STATUS_SUCCESS)
88 g_printerr ("Could not save png to '%s'\n", filename);