gtk print for printing an image
- From: Nicolas Soubeiran <nicolas soubeiran gmail com>
- To: gtk-app-devel-list gnome org
- Subject: gtk print for printing an image
- Date: Thu, 30 Jun 2011 16:49:23 +0200
Hi all,
I try to use GtkPrintOperation for printing an image and there is
something I do not understand.
When I am in the draw-page callback, I get the cairo context from
GtkPrintContext which is at 72dpi and the "draw rectangle" is smaller
than 1000x1000 (for A4 sheet) and my image pixbuf is 2000x3200. So I
need to rescale it (and loose resolution) to have a "full image"
print.
I have understood that I should not change the resolution of the given
print context when printing so I do not know how I can avoid
rescaling.
sample code :
static void s_draw_page(GtkPrintOperation *operation,GtkPrintContext
*context, gint page_nr, GdkPixbuf* image)
{
GdkPixbuf* render;
GtkPrintSettings * settings;
cairo_t *cr;
gdouble width, height;
gint image_width, image_height;
settings = gtk_print_operation_get_print_settings(operation);
width = gtk_print_context_get_width (context);
height = gtk_print_context_get_height(context);
image_width = gdk_pixbuf_get_width(image);
image_height = gdk_pixbuf_get_height(image);
g_message("GtkPrintContext dpi : %f, setting dpi %d",
gtk_print_context_get_dpi_x(context),
gtk_print_settings_get_resolution(settings));
if(image_width > width || image_height > height )
{
g_warning("image is larger than printing zone : rescale");
render = gdk_pixbuf_scale_simple(image, (int) width , (int)height );
}
else
{
render = GDK_PIXBUF(g_object_ref( image));
}
cairo_rectangle (cr, 0, 0, width, height);
gdk_cairo_set_source_pixbuf(cr, render );
cairo_fill(cr),
g_object_unref(render);
}
output look likes:
message ** GtkPrintContext dpi : 72.000000, setting dpi 600
warning ** image is larger than printing zone : rescale
[
Date Prev][Date Next] [
Thread Prev][Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]