/* gcc -o demo-printing `pkg-config --cflags --libs gtk+-2.0` demo-printing.c * * Copyright (C) 2007 Imendio AB * Contact: Carlos Garnacho * * This work is provided "as is"; redistribution and modification * in whole or in part, in any medium, physical or electronic is * permitted without restriction. * * This work is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * In no event shall the authors or contributors be liable for any * direct, indirect, incidental, special, exemplary, or consequential * damages (including, but not limited to, procurement of substitute * goods or services; loss of use, data, or profits; or business * interruption) however caused and on any theory of liability, whether * in contract, strict liability, or tort (including negligence or * otherwise) arising in any way out of the use of this software, even * if advised of the possibility of such damage. */ #include static void print_operation_begin (GtkPrintOperation *operation, GtkPrintContext *context, gpointer user_data) { /* inicializaciones varias */ gtk_print_operation_set_n_pages (operation, 1); } static void print_operation_draw (GtkPrintOperation *operation, GtkPrintContext *context, gint page_num, gpointer user_data) { gint width; cairo_t *cr; cr = gtk_print_context_get_cairo_context (context); width = gtk_print_context_get_width (context); cairo_set_line_width (cr, 22); cairo_arc (cr, width / 2, width / 2, width / 2, 0, 2 * G_PI); cairo_set_source_rgb (cr, 1., 1., 0.); cairo_fill_preserve (cr); cairo_set_source_rgb (cr, 0., 0., 0.); cairo_stroke (cr); cairo_set_source_rgb (cr, 0., 0., 0.); cairo_arc (cr, width / 3, width / 4, width / 8, 0, 2 * G_PI); cairo_fill (cr); cairo_stroke (cr); cairo_arc (cr, width - width / 3, width / 4, width / 8, 0, 2 * G_PI); cairo_fill (cr); cairo_stroke (cr); cairo_save (cr); cairo_translate (cr, width / 2, width - width / 3); cairo_scale (cr, 2., 1.); cairo_arc (cr, 0.,0., width / 8, 0, 2 * G_PI); cairo_fill (cr); cairo_stroke (cr); cairo_restore (cr); } gint main (gint argc, gchar *argv[]) { GtkPrintOperation *operation; GError *error = NULL; gtk_init (&argc, &argv); operation = gtk_print_operation_new (); g_signal_connect (operation, "begin-print", G_CALLBACK (print_operation_begin), NULL); g_signal_connect (operation, "draw-page", G_CALLBACK (print_operation_draw), NULL); gtk_print_operation_run (operation, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, NULL, &error); if (error) { GtkWidget *dialog; dialog = gtk_message_dialog_new (NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "Tururu"); gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), error->message); gtk_dialog_run (GTK_DIALOG (dialog)); g_error_free (error); } return 0; }