Re: render texts to a buffer/drawable
- From: John Cupitt <john cupitt ng-london org uk>
- To: Ronald Bultje <rbultje ronald bitfreak net>
- Cc: GTK Mailing List <gtk-list gnome org>
- Subject: Re: render texts to a buffer/drawable
- Date: Mon, 25 Jun 2001 12:08:40 +0100
Ronald Bultje wrote:
> does Gtk or any other lib offer the option to render texts to a drawable
> or a RGB-buffer (in the best case: a gdk-pixbuf)? In the best case, it
> would work something like some_function(char *font, char *text) (font
> being the font as provided by the gtk-font-selection-dialog
> (-courier-new-bla--bla-*-*-*-*-) and text being the string to be
> rendered) and render the text to a gdk-pixbuf :-)
Hi Ronald, you can do this with a bunch of gdk:
- gdk_font_load() the font you want
- gdk_text_extents() to work out how big your string will be (in pixels)
- gdk_pixmap_new() to make a pixmap large enough to hold rendered text
- make a black/white GC to render with
- clear the pixmap to the background colour
- gdk_draw_string() to draw the text into the pixmap
- gdk_image_get() to read the image from the server as a GdkImage*
- malloc yor RGB buffer, and unpack the GdkImage into that
About 4 pages of code :-( I believe this is what gimp does (or it did
last time I looked).
I'm sure you can link against freetype or something and do the rendering
on the client side, but I've not tried that.
John
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]