]> Pileus Git - ~andy/gtk/blob - tests/testnouiprint.c
stylecontext: Do invalidation on first resize container
[~andy/gtk] / tests / testnouiprint.c
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
24 static void
25 draw_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, 1.0, 0, 0);
37   cairo_rectangle (cr, 0, 0, gtk_print_context_get_width (context), 50);
38   
39   cairo_fill (cr);
40
41   /* Draw some lines */
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);
46   
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);
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, "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);
61
62   cairo_move_to (cr, 30, 20);
63   pango_cairo_layout_path (cr, layout);
64
65   /* Font Outline */
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);
69
70   /* Font Fill */
71   cairo_set_source_rgb (cr, 0, 0.0, 1.0);
72   cairo_fill (cr);
73
74   g_object_unref (layout);
75 }
76
77
78 int
79 main (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 (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);
93
94   return 0;
95 }