[cairo] Question about cario example: text_align_center

Meryl Silverburgh silverburgh.meryl at gmail.com
Tue Jan 31 09:45:53 PST 2006


I am studing the cario example here
"http://cairographics.org/samples/snippets.html", and I have a few
question, i appreciate if you can help.

cairo_text_extents_t extents;

const char *utf8 = "cairo";
double x,y;

// Question:  What does 'snippet_normalize' do? where is the code?
snippet_normalize (cr, width, height);

cairo_select_font_face (cr, "Sans",
    CAIRO_FONT_SLANT_NORMAL,
    CAIRO_FONT_WEIGHT_NORMAL);

cairo_set_font_size (cr, 0.2);
cairo_text_extents (cr, utf8, &extents);

// Question: what does the 'x_bearing', 'y_bearing' mean?
x = 0.5-(extents.width/2 + extents.x_bearing);
y = 0.5-(extents.height/2 + extents.y_bearing);

cairo_move_to (cr, x, y);
//Question: how can I draw a Number (integer)?
cairo_show_text (cr, utf8);

/* draw helping lines */
cairo_set_source_rgba (cr, 1,0.2,0.2, 0.6);
cairo_arc (cr, x, y, 0.05, 0, 2*M_PI);
cairo_fill (cr);
cairo_move_to (cr, 0.5, 0);
cairo_rel_line_to (cr, 0, 1);
cairo_move_to (cr, 0, 0.5);
cairo_rel_line_to (cr, 1, 0);
cairo_stroke (cr);


More information about the cairo mailing list