]> Pileus Git - ~andy/gtk/blob - docs/reference/gtk/tmpl/gtkprintcontext.sgml
2.9.2
[~andy/gtk] / docs / reference / gtk / tmpl / gtkprintcontext.sgml
1 <!-- ##### SECTION Title ##### -->
2 GtkPrintContext
3
4 <!-- ##### SECTION Short_Description ##### -->
5 Encapsulates context for drawing pages
6
7 <!-- ##### SECTION Long_Description ##### -->
8 <para>
9 A GtkPrintContext encapsulates context information that is required when
10 drawing pages for printing, such as the cairo context and important 
11 parameters like page size and resolution. It also lets you easily
12 create #PangoLayout and #PangoContext objects that match the font metrics 
13 of the cairo surface.
14 </para>
15 <para>
16 GtkPrintContext objects gets passed to the ::begin-print, ::end-print, 
17 ::request-page-setup and ::draw-page signals on the #GtkPrintOperation.
18 </para>
19
20 <example>
21 <title>Using GtkPrintContext in a ::draw-page callback</title>
22 <programlisting>
23 static void
24 draw_page (GtkPrintOperation *operation,
25            GtkPrintContext   *context,
26            int                page_nr)
27 {
28   cairo_t *cr;
29   PangoLayout *layout;
30   PangoFontDescription *desc;
31   
32   cr = gtk_print_context_get_cairo (context);
33
34   /* Draw a red rectangle, as wide as the paper (inside the margins) */
35   cairo_set_source_rgb (cr, 1.0, 0, 0);
36   cairo_rectangle (cr, 0, 0, gtk_print_context_get_width (context), 50);
37   
38   cairo_fill (cr);
39
40   /* Draw some lines */
41   cairo_move_to (cr, 20, 10);
42   cairo_line_to (cr, 40, 20);
43   cairo_arc (cr, 60, 60, 20, 0, M_PI);
44   cairo_line_to (cr, 80, 20);
45   
46   cairo_set_source_rgb (cr, 0, 0, 0);
47   cairo_set_line_width (cr, 5);
48   cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
49   cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
50   
51   cairo_stroke (cr);
52
53   /* Draw some text */ 
54   layout = gtk_print_context_create_layout (context);
55   pango_layout_set_text (layout, "Hello World! Printing is easy", -1);
56   desc = pango_font_description_from_string ("sans 28");
57   pango_layout_set_font_description (layout, desc);
58   pango_font_description_free (desc);
59
60   cairo_move_to (cr, 30, 20);
61   pango_cairo_layout_path (cr, layout);
62
63   /* Font Outline */
64   cairo_set_source_rgb (cr, 0.93, 1.0, 0.47);
65   cairo_set_line_width (cr, 0.5);
66   cairo_stroke_preserve (cr);
67
68   /* Font Fill */
69   cairo_set_source_rgb (cr, 0, 0.0, 1.0);
70   cairo_fill (cr);
71   
72   g_object_unref (layout);
73 }
74 </programlisting>
75 </example>
76
77 <para>
78 Printing support was added in GTK+ 2.10.
79 </para>
80
81 <!-- ##### SECTION See_Also ##### -->
82 <para>
83
84 </para>
85
86 <!-- ##### SECTION Stability_Level ##### -->
87
88
89 <!-- ##### STRUCT GtkPrintContext ##### -->
90 <para>
91
92 </para>
93
94
95 <!-- ##### FUNCTION gtk_print_context_get_cairo_context ##### -->
96 <para>
97
98 </para>
99
100 @context: 
101 @Returns: 
102
103
104 <!-- ##### FUNCTION gtk_print_context_get_page_setup ##### -->
105 <para>
106
107 </para>
108
109 @context: 
110 @Returns: 
111
112
113 <!-- ##### FUNCTION gtk_print_context_get_width ##### -->
114 <para>
115
116 </para>
117
118 @context: 
119 @Returns: 
120
121
122 <!-- ##### FUNCTION gtk_print_context_get_height ##### -->
123 <para>
124
125 </para>
126
127 @context: 
128 @Returns: 
129
130
131 <!-- ##### FUNCTION gtk_print_context_get_dpi_x ##### -->
132 <para>
133
134 </para>
135
136 @context: 
137 @Returns: 
138
139
140 <!-- ##### FUNCTION gtk_print_context_get_dpi_y ##### -->
141 <para>
142
143 </para>
144
145 @context: 
146 @Returns: 
147
148
149 <!-- ##### FUNCTION gtk_print_context_get_pango_fontmap ##### -->
150 <para>
151
152 </para>
153
154 @context: 
155 @Returns: 
156
157
158 <!-- ##### FUNCTION gtk_print_context_create_pango_context ##### -->
159 <para>
160
161 </para>
162
163 @context: 
164 @Returns: 
165
166
167 <!-- ##### FUNCTION gtk_print_context_create_pango_layout ##### -->
168 <para>
169
170 </para>
171
172 @context: 
173 @Returns: 
174
175