Re: Trying to draw text on a pixbuf



hi,

not sure if i've gotten the wrong end of the stick, here, but i've solved
this with the following logic:

renderer = gdk_pango_renderer_get_default();
gdk_pango_renderer_set_drawable(renderer, window);
gdk_pango_renderer_set_gc(GC);

context = gtk_widget_create_pango_context();
desc = pango_font_description_from_string();

layout = pango_layout_new(context);
pango_layout_set_text(layout, "string to display", -1);
pagno_layout_set_font_description(layout, desc);

gdk_draw_layout(pixmap, gc, xpos, ypos, layout);
g_object_unref(layout);

the original poster essentially said the same thing (render to a pixmap
first), except i don't have a problem with the background, it's correct
(settable by the user, so no hard-codedness).

cheers,

richard boaz

>
>
> ------- Forwarded message -------
> From: "Chris Seaton" <chris chrisseaton com>
> To: Frédéric Terraza <fterraza free fr>, gtk-list gnome org
> Subject: Re: Trying to draw text on a pixbuf
> Date: Sat, 10 Sep 2005 18:02:47 +0100
>
> I was doing this a while ago.
>
> Specifically, I was using Pango to create text for OpenGL textures, but
> I needed to have rendered text with an alpha channel to do that, just
> like you do.
>
> Pango is pretty shit in that it won't (as far as I can tell) render an
> alpha channel. I mean how basic is that?
>
> You can't just render onto a black background and then set black to be
> transparent, as remember that the text could be antialised.
>
> What I did was to render white text on a black background into a pixbuf,
> add an alpha channel (there's a function for that) then itterate through
> each pixel in the pixbuf, copying the red channel into the alpha channel
> (remember we rendered white on black, so the text will be opaque and the
> background transparent), and then setting the red green and blue
> channels to be whatever colour I wanted.
>
> You can then render that pixbuf.
>
> There will be some very slight artifacts does to sub pixel
> antialisiaing, so I wouldn'e be writing GIMP's text tool using this.
> Anyone not knowledgeable about antialiasing will probably not notice it
> though.
>
> Chris
>
> Frédéric Terraza wrote:
>> Hello,
>>  this is my first post ever on a mailing-list, I hope I'm doing it the
>> right way. My apologies if not so.
>>  I'd like to draw text on a pixbuf. I first tried :
>> - to write text in a PangoLayout
>> - to render the layout in a pixmap
>> - to copy the pixmap in the pixbuf
>>  It worked, but the text has a black background that overlap the
>> previously drawn things on the pixbuf. And I can't change the background
>> color (with a gdk_gc_set_background for example).
>>  So, I tried :
>> - to render the pixmap in a temporary pixbuf
>> - to add alpha to this pixbuf, making black become transparent
>> - to copy this temporary pixbuf in my final pixbuf.
>>  Same results. And I don't know why.
>>  Maybe alpha isn't taken into account by gdk_pixbuf_copy_area ? If so, I
>> suppose it's not too hard to make another version of this primitive
>> doing that (but slow).
>> And since it bothers me to have black as background color (what will I
>> do if the foreground color is also black ? It may happen with text), do
>> you have an idea for how to change the background color ?
>>  Thanks in advance. And excuse my english, school is far away now...
>>  Fred
>> _______________________________________________
>> gtk-list mailing list
>> gtk-list gnome org
>> http://mail.gnome.org/mailman/listinfo/gtk-list
>>
>
> _______________________________________________
> gtk-list mailing list
> gtk-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtk-list
>
>
>
> --
> Richard Boaz
> riboaz xs4all nl
> +31.(0)648.792.484
> http://www.boazconsultancy.com
>





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]