RE : GooCanvas : Clipboard copy



>That actually works for me, with the cairo_set_source_rgb() line. Note
that white is 1.0, 1.0, 1.0, but that won't affect this:
>http://library.gnome.org/devel/cairo/stable/cairo-context.html#cairo-se
t-source-rgb

>Also cairo_rectangle() takes x, y, width & height arguments:
http://library.gnome.org/devel/cairo/stable/cairo-paths.html#cairo-recta
ngle

>Can you try it again?

Thank you for your response,

I have tried with the following code (without drawing a cairo rectangle
=> the result is the same. My screenshot background is black and the
"Hello world" text is missing):

on_clipboard_copy(GtkWidget * widget, gpointer p)
{
	cairo_surface_t *surface;
	cairo_t *cr;
	GtkClipboard * pClipboard;
	GdkPixbuf * pPixbuf;
	gdouble left, top, right, bottom;

	pClipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
	goo_canvas_get_bounds(GOO_CANVAS (canvas), &left, &top, &right,
&bottom);
	surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
(int)right, (int)bottom);

	cr = cairo_create(surface);

	cairo_fill(cr);

	goo_canvas_render((GooCanvas *)canvas, cr, NULL, 1.0);

	cairo_show_page(cr);
	pPixbuf = cairo_convert_to_pixbuf(surface);
	cairo_surface_destroy(surface);
	cairo_destroy(cr);
	gtk_clipboard_set_image(pClipboard, pPixbuf);
	gdk_pixbuf_unref(pPixbuf);
}

I have also tried to draw a rectangle with white color (as you propose :
cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);) :

on_clipboard_copy(GtkWidget * widget, gpointer p)
{
	cairo_surface_t *surface;
	cairo_t *cr;
	GtkClipboard * pClipboard;
	GdkPixbuf * pPixbuf;
	gdouble left, top, right, bottom;

	pClipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
	goo_canvas_get_bounds(GOO_CANVAS (canvas), &left, &top, &right,
&bottom);
	surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
(int)right, (int)bottom);
	cr = cairo_create(surface);

	cairo_rectangle(cr, left, top, (int)right, (int)bottom);

	cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);

	cairo_fill(cr);

	goo_canvas_render((GooCanvas *)canvas, cr, NULL, 1.0);

	cairo_show_page(cr);

	pPixbuf = cairo_convert_to_pixbuf(surface);
	cairo_surface_destroy(surface);
	cairo_destroy(cr);
	gtk_clipboard_set_image(pClipboard, pPixbuf);
	gdk_pixbuf_unref(pPixbuf);
}

The result is a little bit better but the text "Hello world" (in the red
rectangle) is missing.

I think that the text is erased or not drawn correctly.

What do you think ?



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