Re: Text rendering with pango and gtkpixbuf (Gonzalo Aguilar Delgado)
- From: Gonzalo Aguilar Delgado <gad aguilardelgado com>
- To: GTK desarrollo <gtk-app-devel-list gnome org>
- Subject: Re: Text rendering with pango and gtkpixbuf (Gonzalo Aguilar Delgado)
- Date: Sun, 15 Feb 2004 13:20:44 +0100
Not enough luck!!!
Don't know what is the problem because the map I draw uses 8bit depth.
But the colormap is RGB so PANGO or GDK_GC should do the work...
I don't know if I have to set up colors used in pango-rendering-text
functions on my gc but nothing I tried works...
The question is:
Must I do something special with pango to render text with colors on a
GDK_DRAWABLE?
This is what I currently do:
----------------------------- Cut Here ---------------------
...
GdkColor fore = { 255, 0, 0, 0x00 };
...
playout = gtk_widget_create_pango_layout(GTK_WIDGET (map),"Hello");
pfontdesc = pango_font_description_from_string ("Sans 8");
pango_layout_set_font_description (playout, pfontdesc);
pango_layout_get_pixel_size (playout, &text_width, &text_height);
patcolor = pango_attr_foreground_new(255,0,0);
pattrlist = pango_layout_get_attributes(playout);
if(pattrlist) {
pango_attr_list_insert(pattrlist,patcolor);
}else{
pattrlist=pango_attr_list_new();
pango_attr_list_insert(pattrlist,patcolor);
}
pango_layout_set_attributes(playout,pattrlist);
Gc = gdk_gc_new(GTK_WIDGET (map)->window);
if(!gdk_colormap_alloc_color(gdk_rgb_get_cmap (),&fore,TRUE,TRUE)){
g_print("No color allocated\n"); /* Thanks to Kaesar */
}
gdk_draw_layout_with_colors(GTK_WIDGET(map)->window,
Gc,(gint)winx-(text_width/2),
(gint)(winy-(text_height/2)),playout,&fore,NULL);
gdk_gc_unref(Gc);
g_object_unref(G_OBJECT(playout));
pango_font_description_free(pfontdesc);
pango_attribute_destroy(patcolor);
------------------------------ CUT HERE -------------------------
But this leads to a colored 8 bit map on the back and a black text on
the front and NO ERRORS!!!
You need allocate the color before use it.
You can try:
...
Gc = gdk_gc_new(GTK_WIDGET (map)->window);
/*BEGIN NEW*/
/*View:
http://developer.gnome.org/doc/API/2.0/gdk/gdk-Colormaps-and-Colors.html*/
if (!gdk_colormap_alloc_color(
gdk_colormap_get_system (),
&fore, TRUE, TRUE)
) {/*ERROR: NO gdk_colormap_alloc_color*/}
/*END NEW*/
/* I use this because without colors does not work,
nor with this... */
gdk_draw_layout_with_colors(GTK_WIDGET(map)->window,Gc,(gint)winx,(gint)winy,
playout,&fore,NULL);
...
Lucky!
___________________________________________________
Yahoo! Messenger - Nueva versiÃn GRATIS
Super Webcam, voz, caritas animadas, y mÃs...
http://messenger.yahoo.es
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
--
--
Ingeniero en Informatica
Gonzalo Aguilar Delgado <a
href="gad aguilardelgado com">gad aguilardelgado com</a>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]