GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Fri Jul 25, 2014 5:38 pm

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Problem with Cairo and GtkDrawingArea
PostPosted: Fri Feb 28, 2014 1:51 pm 
Offline

Joined: Mon Feb 17, 2014 2:22 pm
Posts: 1
Hi all,
I'm going out of my mind with Cairo. I'm trying to display a page of a PDF file using GtkDrawingArea,poppler and cairo. I have connected the "draw" signal of GtkDrawingArea to draw_cb. At first I got a black drawing area when I open a PDF file. Some of my code in draw_cb looks like the following:
Code:
gboolean draw_cb(GtkWidget *widget,cairo_t *cr,GtkApplicationWindow *w)
{
....../* some codes*/
    poppler_page_render(page,cr);
    cairo_paint(cr);
    return FALSE;
}


I can't figure out why,but after I added lines of codes unintenationly,it worked. This is the modified version:
Code:
gboolean draw_cb(GtkWidget *widget,cairo_t *cr,GtkApplicationWindow *w)
{
....
    poppler_page_render(page,cr);
    surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
    gtk_widget_get_allocated_width(widget),
    gtk_widget_get_allocated_height(widget));
    poppler_page_render(page,cr);
    cairo_set_source_surface(cr,surface,0,0);
    cairo_paint(cr);
    return FALSE;
}


I can't understand this thing, so I read the Cairo reference manual again then I simply changed the cairo_surface_t * surface to NULL, and to my surprise it still showed the correct content on GtkDrawingArea, but there are warnings in the terminal like "Gtk-WARNING **: drawing failure for widget `GtkDrawingArea': NULL pointer".

Why this happened? Say,by calling poppler_page_render(page,cr),"cr" should get the needed source, why do I have to set "cr" with another irrelevant source and it then will work? Comments of a code example from gtk+ reference manual says
Code:
/* Redraw the screen from the surface. Note that the ::draw
* signal receives a ready-to-be-used cairo_t that is already
* clipped to only draw the exposed areas of the widget"


I don't know whether cairo questions are beyond the scrope of the forum. I can't find elsewhere to post,and I hope someone can help me with this, because I really can't find any more tutorials besides Cairo Tutorial and its manual.


Last edited by zerohour on Sat Mar 01, 2014 5:23 pm, edited 1 time in total.
Clearer wording/improper spacing


Top
 Profile  
 
 Post subject: Re: Problem with Cairo and GtkDrawingArea
PostPosted: Mon Mar 10, 2014 4:46 am 
Offline

Joined: Fri Mar 07, 2014 10:56 pm
Posts: 2
Have you tried removing cairo_paint(cr). It seems like calling popplar_render_page is already drawing what you need and cairo_paint is over writing it. Which is why creating a surface with no content or null and trying to paint it displays what you want because it is not the default black over writing your image.

Try just popplar_page_render and see what happens. I've never used poplar so I'm not sure but it seems like that is the issue to me.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users 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