与开罗邮件列表中的答案相同(似乎在某处丢失了):
你没有做错任何事(好吧,也许使用玩具文本 API,但这应该仍然有效)并且你的代码对我来说很好。这是我测试的完整代码:
#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;
}