On Wed, 2007-01-17 at 18:24 -0300, Alejandro Valdes Jimenez wrote:
>
> tienes algun ejemplo por ahi?
Para texto, gtk-demo tiene un ejemplo de un programa que se imprime a si
mismo. Para imágenes, revisa este programita hecho en cairo. Es más de
lo que necesitarías con GtkPrint, pero te da la idea. El archivo
shell/eog-window.c del EOG es un ejemplo más completo.
Claudio
--
Claudio Saavedra <[EMAIL PROTECTED]>
/** Author: Claudio Saavedra <[EMAIL PROTECTED]>
Public domain.
**/
#include <cairo.h>
#include <cairo-pdf.h>
#include <glib.h>
#include <gdk/gdk.h>
int
main (int argc, char **argv)
{
GdkPixbuf *pixbuf;
gint width, height;
gdouble p_width, p_height;
gdouble scale_factor;
GError *error = NULL;
cairo_surface_t *surface;
cairo_t *cr;
cairo_pattern_t *pattern;
if (argc < 2)
return 1;
g_type_init ();
pixbuf = gdk_pixbuf_new_from_file (argv[1], &error);
if (error != NULL) {
g_warning ("Couldn't load image: %s", error->message);
g_error_free (error);
return 1;
}
width = gdk_pixbuf_get_width (pixbuf);
height = gdk_pixbuf_get_height (pixbuf);
p_width = 72 * 8.50;
p_height = 72 * 11.0;
/* create a PDF surface of letter page size */
surface = cairo_pdf_surface_create ("output.pdf", p_width, p_height);
cr = cairo_create (surface);
if (p_width > width && p_height > height) {
cairo_translate (cr, (p_width - width)/2,
(p_height - height)/2);
} else if (width > height && width > p_width) {
scale_factor = ((gdouble)p_width)/width;
cairo_scale (cr, scale_factor, scale_factor);
cairo_translate (cr, 0, (p_height/scale_factor - height)/2);
} else {
scale_factor = ((gdouble)p_height)/height;
cairo_scale (cr, scale_factor, scale_factor);
cairo_translate (cr, (p_width/scale_factor - width)/2, 0);
}
/* this is a workaround for a bug in cairo's PDF backend */
cairo_rectangle (cr, 0, 0, width, height);
cairo_clip (cr);
gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
cairo_paint (cr);
cairo_show_page (cr);
cairo_surface_finish (surface);
g_object_unref (G_OBJECT (pixbuf));
return 0;
}