#include #include #include GtkWidget* drawingArea; static void draw_title (GtkWidget * widget, cairo_t * cr) { GtkAllocation alloc; gtk_widget_get_allocation (drawingArea, & alloc); gint x = 64 + 50 * 2; gint width = alloc.width - x; gchar *str = "Some long and meaningless text\0"; cairo_move_to(cr, 10, 40); cairo_set_operator(cr, CAIRO_OPERATOR_ATOP); cairo_set_source_rgba(cr, 0, 0, 0, 1); PangoFontDescription * desc = pango_font_description_from_string ("Sans 18"); PangoLayout * pl = gtk_widget_create_pango_layout (drawingArea, NULL); pango_layout_set_markup(pl, str, -1); pango_layout_set_font_description(pl, desc); pango_font_description_free(desc); pango_layout_set_width (pl, width * PANGO_SCALE); pango_cairo_show_layout(cr, pl); g_object_unref(pl); } int main( int argc, char *argv[] ) { GtkWidget *window; gtk_init (&argc, &argv); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); drawingArea = gtk_drawing_area_new (); gtk_widget_set_size_request (drawingArea, 64 + 2 * 64, 200); g_signal_connect (drawingArea, "draw", (GCallback) draw_title, NULL); gtk_container_add (GTK_CONTAINER (window), drawingArea); gtk_widget_show (drawingArea); gtk_widget_show (window); gtk_main (); return 0; }