1 /* -*- Mode: C; c-basic-offset: 2; -*- */
2 /* Gtk+ - non-ui printing
4 * Copyright (C) 2006 Alexander Larsson <alexl@redhat.com>
6 * This library is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
11 * This library 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 Lesser General Public License for more details.
16 * You should have received a copy of the GNU General Public Lesser
17 * License along with this program. If not, see <http://www.gnu.org/licenses/>.
25 draw_page (GtkPrintOperation *operation,
26 GtkPrintContext *context,
31 PangoFontDescription *desc;
33 cr = gtk_print_context_get_cairo_context (context);
35 /* Draw a red rectangle, as wide as the paper (inside the margins) */
36 cairo_set_source_rgb (cr, 1.0, 0, 0);
37 cairo_rectangle (cr, 0, 0, gtk_print_context_get_width (context), 50);
42 cairo_move_to (cr, 20, 10);
43 cairo_line_to (cr, 40, 20);
44 cairo_arc (cr, 60, 60, 20, 0, G_PI);
45 cairo_line_to (cr, 80, 20);
47 cairo_set_source_rgb (cr, 0, 0, 0);
48 cairo_set_line_width (cr, 5);
49 cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
50 cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
56 layout = gtk_print_context_create_pango_layout (context);
57 pango_layout_set_text (layout, "Hello World! Printing is easy", -1);
58 desc = pango_font_description_from_string ("sans 28");
59 pango_layout_set_font_description (layout, desc);
60 pango_font_description_free (desc);
62 cairo_move_to (cr, 30, 20);
63 pango_cairo_layout_path (cr, layout);
66 cairo_set_source_rgb (cr, 0.93, 1.0, 0.47);
67 cairo_set_line_width (cr, 0.5);
68 cairo_stroke_preserve (cr);
71 cairo_set_source_rgb (cr, 0, 0.0, 1.0);
74 g_object_unref (layout);
79 main (int argc, char **argv)
81 GtkPrintOperation *print;
82 GtkPrintSettings *settings;
84 settings = gtk_print_settings_new ();
85 /* gtk_print_settings_set_printer (settings, "printer"); */
87 print = gtk_print_operation_new ();
88 gtk_print_operation_set_print_settings (print, settings);
89 gtk_print_operation_set_n_pages (print, 1);
90 gtk_print_operation_set_unit (print, GTK_UNIT_MM);
91 g_signal_connect (print, "draw_page", G_CALLBACK (draw_page), NULL);
92 gtk_print_operation_run (print, GTK_PRINT_OPERATION_ACTION_PRINT, NULL, NULL);