I am new to cairo and I have read the tutorials/documentation on its website. Now I can make lines, rectangles, and basically I can render images but not text.
I am using the following code
cairo_select_font_face (cr, "monospace", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAl);
cairo_set_font_size (cr, 14);
cairo_set_source_rgb (cr, 1, 1, 1);
cairo_move_to (cr, 50, 50);
cairo_show_text (cr, "Print Something");
Can anyone please point to my mistake?
Same answer as on the cairo mailing list (where it seems to have been lost somewhere):
You aren't doing anything wrong (well, perhaps using the toy text API, but that should still work) and your code works fine for me. Here is the full code that I tested with:
#include <cairo.h>
int main()
{
cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 200, 200);
cairo_t *cr = cairo_create(surface);
cairo_surface_destroy(surface);
/* Fill everything with white */
cairo_set_source_rgb(cr, 1, 1, 1);
cairo_paint(cr);
/* Draw some text */
cairo_select_font_face (cr, "monospace", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size (cr, 14);
cairo_set_source_rgb (cr, 0, 0, 0);
cairo_move_to (cr, 0, 50);
cairo_show_text (cr, "Print Something");
cairo_surface_write_to_png(cairo_get_target(cr), "out.png");
cairo_destroy(cr);
return 0;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With