#include #include #include int main (int argc, char *argv[]) { cairo_surface_t *surface; cairo_t *cr; //char string[] = "Hello this is long text to be display at some angle"; char string[] = "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii"; cairo_text_extents_t size; double fontsize = 10.0; printf("Cairo version: %s\n",cairo_version_string()); surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 200, 200); cr = cairo_create (surface); cairo_set_antialias(cr, CAIRO_ANTIALIAS_GRAY); //white background cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 1); cairo_paint(cr); cairo_select_font_face (cr, "Serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); cairo_set_font_size (cr, fontsize); //font options { cairo_font_options_t *font_options; font_options = cairo_font_options_create (); cairo_get_font_options (cr, font_options); cairo_font_options_set_hint_metrics (font_options, CAIRO_HINT_METRICS_OFF); cairo_font_options_set_hint_style (font_options, CAIRO_HINT_STYLE_NONE); cairo_font_options_set_antialias(font_options, CAIRO_ANTIALIAS_GRAY); cairo_set_font_options (cr, font_options); cairo_font_options_destroy (font_options); } cairo_text_extents(cr, string, &size); { int angle = 330; //move to the center cairo_translate (cr, 100, 100); //rotate around text center cairo_rotate(cr, angle / 180.*3.1415926); //center the text cairo_translate(cr, -size.width/2, size.height/2); //line below the text if(1) { cairo_save(cr); cairo_move_to (cr, 0, 1.7); cairo_rel_line_to (cr, size.width, 0); cairo_set_source_rgba (cr, 0.0, 1.0, 0.0, 1); cairo_set_line_width(cr, 0.3); cairo_stroke(cr); cairo_restore(cr); } //text cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 1); cairo_show_text (cr, string); } cairo_surface_write_to_png (surface, "rotlabel2.png"); cairo_destroy (cr); cairo_surface_destroy (surface); return 0; }