1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| GdkPixbuf *gdk_pixbuf_new_from_text ( gchar *text, GtkWidget *widget ) {
GdkPixmap *temp_pixmap ;
GdkPixbuf *temp_pixbuf = NULL ;
PangoLayout *layout ;
GdkGC *gc ;
GdkColormap *cmap ;
GdkColor *fg, *bg ;
int sx, sy ;
/* foreground and background colors */
fg = gdk_color_new_from_RGB(255, 0, 0) ;
bg = gdk_color_new_from_RGB(0, 0, 0) ;
/* render layout to temp_pixmap */
layout = gtk_widget_create_pango_layout(widget, text) ;
pango_layout_get_pixel_size(layout, &sx, &sy) ;
temp_pixmap = gdk_pixmap_new(NULL, sx, sy, 24) ;
gc = gdk_gc_new(temp_pixmap) ;
gdk_gc_set_foreground(gc, fg) ;
gdk_gc_set_background(gc, bg) ;
gdk_draw_layout( temp_pixmap, gc, 0, 0, layout) ;
/* render temp_pixmap to temp_pixbuf */
cmap = gdk_colormap_get_system() ;
if (cmap==NULL) printf("cmap NULL\n") ;
if (temp_pixmap==NULL) printf("temp_pixmap NULL\n") ;
temp_pixbuf = gdk_pixbuf_get_from_drawable(NULL, temp_pixmap, cmap, 0, 0, 0, 0, sx, sy) ;
/* free */
g_object_free(layout) ;
g_object_free(cmap) ;
g_object_free(gc) ;
return temp_pixbuf ;
} |
Partager