GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Tue Aug 30, 2016 9:07 am

All times are UTC

Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: pixbufs and text
PostPosted: Tue Dec 27, 2011 7:46 pm 

Joined: Mon Dec 26, 2011 8:38 pm
Posts: 2
I am working on a video application. I currently have video data from a camera showing in a window using pixbufs. I now want to add text overlays on top of my video. The text will not be extensive nor very fancy--I do not need editing functionality. I just want to be able to display the text in real time, and by real time I mean overlay text dynamically on top of the video under program control. The only requirement for the text is to be able to select the font, size, type, aliasing, etc.

I already have the video over lay functionality working--I can over lay smaller RGB or YUV images on top of the real time video and move these small images around under program control.

Basically what I think I should do is use Gtk+ for the font generation. Then convert that font buffer into a video data format I can over lay with.
So, if I use the Text View widget like this:

textview = gtk_text_view_new();
buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview));
gtk_text_buffer_set_text(buffer, "text to display", -1);

At this point I would need to get access to the raw buffer. How do I get that? What format is that raw buffer in? Is there a different widget I should use?

Any help or suggestions?



 Post subject: Re: pixbufs and text
PostPosted: Thu Dec 29, 2011 11:02 am 
Familiar Face

Joined: Thu Dec 15, 2011 6:23 pm
Posts: 36
Location: Hrvatska
here is answer from GTK dummie ( that's me ).
use pango on cairo surface. it looks like this:
#include <stdio.h>
#include <pango/pangocairo.h>
void rendertext(cairo_t *cr);
int main(int argc, char* argv[])
    cairo_t *cr;
    cairo_status_t status;
    cairo_surface_t *surface;
    surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 300, 100);
    cairo_image_surface_create(pixelformat, width, height);
    cr = cairo_create(surface);
    // tell the cairo instance 'cr' to output to 'surface'
    cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
    // sets the drawing colour to white
    // fill the surface with the active colour (if you don't do this, you will
    // be given a surface with a transparent background to draw on)
    // do pango stuff here
    // free the cairo instance
    status = cairo_surface_write_to_png(surface, "out.png");
    // output the contents of 'surface' to the file "out.png"
    // free the surface
    if (status != CAIRO_STATUS_SUCCESS)
      // if 'status' was not set to indicate a successful operation when saving as a png, error
      printf("Could not save to png, \"out.png\"\n");
      return 1;
    return 0;

void rendertext(cairo_t *cr)
    PangoLayout *layout;
    // layout for a paragraph of text
    PangoFontDescription *desc;
    // this structure stores a description of the style of font you'd most like
    cairo_translate(cr, 10, 20);
    // set the origin of cairo instance 'cr' to (10,20) (i.e. this is where
    // drawing will start from).
    layout = pango_cairo_create_layout(cr);
    // init pango layout ready for use
    pango_layout_set_text(layout, "Hello World!", -1);
    // sets the text to be associated with the layout (final arg is length, -1
    // to calculate automatically when passing a nul-terminated string)
    desc = pango_font_description_from_string("Sans Bold 12");
    // specify the font that would be ideal for your particular use
    pango_layout_set_font_description(layout, desc);
    // assign the previous font description to the layout
    // free the description
    cairo_set_source_rgb(cr, 0.0, 0.0, 1.0);
    // set the colour to blue 
    pango_cairo_update_layout(cr, layout);
    // if the target surface or transformation properties of the cairo instance
    // have changed, update the pango layout to reflect this
    pango_cairo_show_layout(cr, layout);
    // draw the pango layout onto the cairo surface
    // free the layout

Here is good tutorial where you can see this code.

 Post subject: Re: pixbufs and text
PostPosted: Fri Dec 30, 2011 2:44 am 

Joined: Mon Dec 26, 2011 8:38 pm
Posts: 2
Thank you for your reply. The pango/cairo interface looks promising.


Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group