/* Compiled with: gcc -o bugtext bugtext.c -I../../include/cairo -L../../lib -lcairo -g */ #include #include void draw_text(cairo_t* cr) { cairo_text_extents_t te; cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); cairo_select_font_face (cr, "Arial", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD); cairo_set_font_size (cr, 1.2); cairo_text_extents (cr, "a", &te); cairo_move_to (cr, 0.5 - te.width / 2 - te.x_bearing, 0.5 - te.height / 2 - te.y_bearing); cairo_show_text (cr, "a"); /* Note: bug doesn't show up if get_font_face() is called { cairo_font_face_t* ff = cairo_get_font_face(cr); cairo_font_face_reference(ff); } */ } int main(int argc, char* argv[]) { cairo_surface_t* surface; cairo_t* cr; /* Note: bug doesn't show up with write_to_png(), only with svg surface */ surface = cairo_svg_surface_create ("bugtext.svg", 120, 120); cr = cairo_create (surface); /* Examples are in 1.0 x 1.0 coordinate space */ cairo_scale (cr, 120, 120); /* Drawing code goes here */ /* Note: bug doesn't show up without save/restore */ cairo_save(cr); draw_text(cr); cairo_restore(cr); /* Write output and clean up */ cairo_show_page(cr); cairo_destroy (cr); /*cairo_surface_write_to_png (surface, "bugtext.png");*/ cairo_surface_destroy (surface); return 0; }