1/* -*- Mode: C; c-basic-offset: 2; -*- */
2/* Gtk+ - non-ui printing
3 *
4 * Copyright (C) 2006 Alexander Larsson <alexl@redhat.com>
5 *
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.
10 *
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.
15 *
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/>.
18 */
19
20#include "config.h"
21#include <math.h>
22#include "gtk/gtk.h"
23
24static void
25draw_page (GtkPrintOperation *operation,
26 GtkPrintContext *context,
27 int page_nr)
28{
29 cairo_t *cr;
30 PangoLayout *layout;
31 PangoFontDescription *desc;
32
33 cr = gtk_print_context_get_cairo_context (context);
34
35 /* Draw a red rectangle, as wide as the paper (inside the margins) */
36 cairo_set_source_rgb (cr, red: 1.0, green: 0, blue: 0);
37 cairo_rectangle (cr, x: 0, y: 0, width: gtk_print_context_get_width (context), height: 50);
38
39 cairo_fill (cr);
40
41 /* Draw some lines */
42 cairo_move_to (cr, x: 20, y: 10);
43 cairo_line_to (cr, x: 40, y: 20);
44 cairo_arc (cr, xc: 60, yc: 60, radius: 20, angle1: 0, G_PI);
45 cairo_line_to (cr, x: 80, y: 20);
46
47 cairo_set_source_rgb (cr, red: 0, green: 0, blue: 0);
48 cairo_set_line_width (cr, width: 5);
49 cairo_set_line_cap (cr, line_cap: CAIRO_LINE_CAP_ROUND);
50 cairo_set_line_join (cr, line_join: CAIRO_LINE_JOIN_ROUND);
51
52 cairo_stroke (cr);
53
54 /* Draw some text */
55
56 layout = gtk_print_context_create_pango_layout (context);
57 pango_layout_set_text (layout, text: "Hello World! Printing is easy", length: -1);
58 desc = pango_font_description_from_string (str: "sans 28");
59 pango_layout_set_font_description (layout, desc);
60 pango_font_description_free (desc);
61
62 cairo_move_to (cr, x: 30, y: 20);
63 pango_cairo_layout_path (cr, layout);
64
65 /* Font Outline */
66 cairo_set_source_rgb (cr, red: 0.93, green: 1.0, blue: 0.47);
67 cairo_set_line_width (cr, width: 0.5);
68 cairo_stroke_preserve (cr);
69
70 /* Font Fill */
71 cairo_set_source_rgb (cr, red: 0, green: 0.0, blue: 1.0);
72 cairo_fill (cr);
73
74 g_object_unref (object: layout);
75}
76
77
78int
79main (int argc, char **argv)
80{
81 GtkPrintOperation *print;
82 GtkPrintSettings *settings;
83
84 settings = gtk_print_settings_new ();
85 /* gtk_print_settings_set_printer (settings, "printer"); */
86
87 print = gtk_print_operation_new ();
88 gtk_print_operation_set_print_settings (op: print, print_settings: settings);
89 gtk_print_operation_set_n_pages (op: print, n_pages: 1);
90 gtk_print_operation_set_unit (op: print, unit: GTK_UNIT_MM);
91 g_signal_connect (print, "draw_page", G_CALLBACK (draw_page), NULL);
92 gtk_print_operation_run (op: print, action: GTK_PRINT_OPERATION_ACTION_PRINT, NULL, NULL);
93
94 return 0;
95}
96

source code of gtk/tests/testnouiprint.c