1 <!-- ##### SECTION Title ##### -->
4 <!-- ##### SECTION Short_Description ##### -->
5 Encapsulates context for drawing pages
7 <!-- ##### SECTION Long_Description ##### -->
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
16 GtkPrintContext objects gets passed to the ::begin-print, ::end-print,
17 ::request-page-setup and ::draw-page signals on the #GtkPrintOperation.
21 <title>Using GtkPrintContext in a ::draw-page callback</title>
24 draw_page (GtkPrintOperation *operation,
25 GtkPrintContext *context,
30 PangoFontDescription *desc;
32 cr = gtk_print_context_get_cairo_context (context);
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);
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);
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);
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);
60 cairo_move_to (cr, 30, 20);
61 pango_cairo_layout_path (cr, layout);
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);
69 cairo_set_source_rgb (cr, 0, 0.0, 1.0);
72 g_object_unref (layout);
78 Printing support was added in GTK+ 2.10.
81 <!-- ##### SECTION See_Also ##### -->
86 <!-- ##### SECTION Stability_Level ##### -->
89 <!-- ##### SECTION Image ##### -->
92 <!-- ##### STRUCT GtkPrintContext ##### -->
98 <!-- ##### FUNCTION gtk_print_context_get_cairo_context ##### -->
107 <!-- ##### FUNCTION gtk_print_context_set_cairo_context ##### -->
118 <!-- ##### FUNCTION gtk_print_context_get_page_setup ##### -->
127 <!-- ##### FUNCTION gtk_print_context_get_width ##### -->
136 <!-- ##### FUNCTION gtk_print_context_get_height ##### -->
145 <!-- ##### FUNCTION gtk_print_context_get_dpi_x ##### -->
154 <!-- ##### FUNCTION gtk_print_context_get_dpi_y ##### -->
163 <!-- ##### FUNCTION gtk_print_context_get_pango_fontmap ##### -->
172 <!-- ##### FUNCTION gtk_print_context_create_pango_context ##### -->
181 <!-- ##### FUNCTION gtk_print_context_create_pango_layout ##### -->
190 <!-- ##### FUNCTION gtk_print_context_get_hard_margins ##### -->