1 /* -*- Mode: C; c-basic-offset: 2; -*- */
2 /* Gtk+ - non-ui printing
4 * Copyright (C) 2006 Alexander Larsson <alexl@redhat.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22 #include "gtk/gtkprintoperation.h"
26 draw_page (GtkPrintOperation *operation,
27 GtkPrintContext *context,
32 PangoFontDescription *desc;
34 cr = gtk_print_context_get_cairo_context (context);
36 /* Draw a red rectangle, as wide as the paper (inside the margins) */
37 cairo_set_source_rgb (cr, 1.0, 0, 0);
38 cairo_rectangle (cr, 0, 0, gtk_print_context_get_width (context), 50);
43 cairo_move_to (cr, 20, 10);
44 cairo_line_to (cr, 40, 20);
45 cairo_arc (cr, 60, 60, 20, 0, G_PI);
46 cairo_line_to (cr, 80, 20);
48 cairo_set_source_rgb (cr, 0, 0, 0);
49 cairo_set_line_width (cr, 5);
50 cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
51 cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
57 layout = gtk_print_context_create_pango_layout (context);
58 pango_layout_set_text (layout, "Hello World! Printing is easy", -1);
59 desc = pango_font_description_from_string ("sans 28");
60 pango_layout_set_font_description (layout, desc);
61 pango_font_description_free (desc);
63 cairo_move_to (cr, 30, 20);
64 pango_cairo_layout_path (cr, layout);
67 cairo_set_source_rgb (cr, 0.93, 1.0, 0.47);
68 cairo_set_line_width (cr, 0.5);
69 cairo_stroke_preserve (cr);
72 cairo_set_source_rgb (cr, 0, 0.0, 1.0);
75 g_object_unref (layout);
80 main (int argc, char **argv)
83 GtkPrintOperation *print;
84 GtkPrintOperationResult res;
85 GtkPrintSettings *settings;
89 loop = g_main_loop_new (NULL, TRUE);
91 settings = gtk_print_settings_new ();
92 /* gtk_print_settings_set_printer (settings, "printer"); */
94 print = gtk_print_operation_new ();
95 gtk_print_operation_set_print_settings (print, settings);
96 gtk_print_operation_set_n_pages (print, 1);
97 gtk_print_operation_set_unit (print, GTK_UNIT_MM);
98 g_signal_connect (print, "draw_page", G_CALLBACK (draw_page), NULL);
99 res = gtk_print_operation_run (print, GTK_PRINT_OPERATION_ACTION_PRINT, NULL, NULL);