Cannot display text in cairo

I am new to cairo and I read the tutorials / documentation on my website. Now I can create lines, rectangles, and basically I can display 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 someone point out my mistake?

+4
source share
1 answer

The same answer as on the cairo mailing list (where it disappears somewhere):

You are not doing anything wrong (well, maybe using the text API for toys, but that should work anyway), and your code works fine for me. Here is the complete code I tested:

 #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; } 
+2
source

Source: https://habr.com/ru/post/1443269/


All Articles