1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module gtk.PrintContext;
26 
27 private import cairo.Context;
28 private import gobject.ObjectG;
29 private import gtk.PageSetup;
30 private import gtk.c.functions;
31 public  import gtk.c.types;
32 private import pango.PgContext;
33 private import pango.PgFontMap;
34 private import pango.PgLayout;
35 
36 
37 /**
38  * A `GtkPrintContext` encapsulates context information that is required when
39  * drawing pages for printing.
40  * 
41  * This includes the cairo context and important parameters like page size
42  * and resolution. It also lets you easily create [class@Pango.Layout] and
43  * [class@Pango.Context] objects that match the font metrics of the cairo surface.
44  * 
45  * `GtkPrintContext` objects get passed to the
46  * [signal@Gtk.PrintOperation::begin-print],
47  * [signal@Gtk.PrintOperation::end-print],
48  * [signal@Gtk.PrintOperation::request-page-setup] and
49  * [signal@Gtk.PrintOperation::draw-page] signals on the
50  * [class@Gtk.PrintOperation] object.
51  * 
52  * ## Using GtkPrintContext in a ::draw-page callback
53  * 
54  * ```c
55  * static void
56  * draw_page (GtkPrintOperation *operation,
57  * GtkPrintContext   *context,
58  * int                page_nr)
59  * {
60  * cairo_t *cr;
61  * PangoLayout *layout;
62  * PangoFontDescription *desc;
63  * 
64  * cr = gtk_print_context_get_cairo_context (context);
65  * 
66  * // Draw a red rectangle, as wide as the paper (inside the margins)
67  * cairo_set_source_rgb (cr, 1.0, 0, 0);
68  * cairo_rectangle (cr, 0, 0, gtk_print_context_get_width (context), 50);
69  * 
70  * cairo_fill (cr);
71  * 
72  * // Draw some lines
73  * cairo_move_to (cr, 20, 10);
74  * cairo_line_to (cr, 40, 20);
75  * cairo_arc (cr, 60, 60, 20, 0, M_PI);
76  * cairo_line_to (cr, 80, 20);
77  * 
78  * cairo_set_source_rgb (cr, 0, 0, 0);
79  * cairo_set_line_width (cr, 5);
80  * cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
81  * cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
82  * 
83  * cairo_stroke (cr);
84  * 
85  * // Draw some text
86  * layout = gtk_print_context_create_pango_layout (context);
87  * pango_layout_set_text (layout, "Hello World! Printing is easy", -1);
88  * desc = pango_font_description_from_string ("sans 28");
89  * pango_layout_set_font_description (layout, desc);
90  * pango_font_description_free (desc);
91  * 
92  * cairo_move_to (cr, 30, 20);
93  * pango_cairo_layout_path (cr, layout);
94  * 
95  * // Font Outline
96  * cairo_set_source_rgb (cr, 0.93, 1.0, 0.47);
97  * cairo_set_line_width (cr, 0.5);
98  * cairo_stroke_preserve (cr);
99  * 
100  * // Font Fill
101  * cairo_set_source_rgb (cr, 0, 0.0, 1.0);
102  * cairo_fill (cr);
103  * 
104  * g_object_unref (layout);
105  * }
106  * ```
107  */
108 public class PrintContext : ObjectG
109 {
110 	/** the main Gtk struct */
111 	protected GtkPrintContext* gtkPrintContext;
112 
113 	/** Get the main Gtk struct */
114 	public GtkPrintContext* getPrintContextStruct(bool transferOwnership = false)
115 	{
116 		if (transferOwnership)
117 			ownedRef = false;
118 		return gtkPrintContext;
119 	}
120 
121 	/** the main Gtk struct as a void* */
122 	protected override void* getStruct()
123 	{
124 		return cast(void*)gtkPrintContext;
125 	}
126 
127 	/**
128 	 * Sets our main struct and passes it to the parent class.
129 	 */
130 	public this (GtkPrintContext* gtkPrintContext, bool ownedRef = false)
131 	{
132 		this.gtkPrintContext = gtkPrintContext;
133 		super(cast(GObject*)gtkPrintContext, ownedRef);
134 	}
135 
136 
137 	/** */
138 	public static GType getType()
139 	{
140 		return gtk_print_context_get_type();
141 	}
142 
143 	/**
144 	 * Creates a new `PangoContext` that can be used with the
145 	 * `GtkPrintContext`.
146 	 *
147 	 * Returns: a new Pango context for @context
148 	 */
149 	public PgContext createPangoContext()
150 	{
151 		auto __p = gtk_print_context_create_pango_context(gtkPrintContext);
152 
153 		if(__p is null)
154 		{
155 			return null;
156 		}
157 
158 		return ObjectG.getDObject!(PgContext)(cast(PangoContext*) __p, true);
159 	}
160 
161 	/**
162 	 * Creates a new `PangoLayout` that is suitable for use
163 	 * with the `GtkPrintContext`.
164 	 *
165 	 * Returns: a new Pango layout for @context
166 	 */
167 	public PgLayout createPangoLayout()
168 	{
169 		auto __p = gtk_print_context_create_pango_layout(gtkPrintContext);
170 
171 		if(__p is null)
172 		{
173 			return null;
174 		}
175 
176 		return ObjectG.getDObject!(PgLayout)(cast(PangoLayout*) __p, true);
177 	}
178 
179 	/**
180 	 * Obtains the cairo context that is associated with the
181 	 * `GtkPrintContext`.
182 	 *
183 	 * Returns: the cairo context of @context
184 	 */
185 	public Context getCairoContext()
186 	{
187 		auto __p = gtk_print_context_get_cairo_context(gtkPrintContext);
188 
189 		if(__p is null)
190 		{
191 			return null;
192 		}
193 
194 		return new Context(cast(cairo_t*) __p);
195 	}
196 
197 	/**
198 	 * Obtains the horizontal resolution of the `GtkPrintContext`,
199 	 * in dots per inch.
200 	 *
201 	 * Returns: the horizontal resolution of @context
202 	 */
203 	public double getDpiX()
204 	{
205 		return gtk_print_context_get_dpi_x(gtkPrintContext);
206 	}
207 
208 	/**
209 	 * Obtains the vertical resolution of the `GtkPrintContext`,
210 	 * in dots per inch.
211 	 *
212 	 * Returns: the vertical resolution of @context
213 	 */
214 	public double getDpiY()
215 	{
216 		return gtk_print_context_get_dpi_y(gtkPrintContext);
217 	}
218 
219 	/**
220 	 * Obtains the hardware printer margins of the `GtkPrintContext`,
221 	 * in units.
222 	 *
223 	 * Params:
224 	 *     top = top hardware printer margin
225 	 *     bottom = bottom hardware printer margin
226 	 *     left = left hardware printer margin
227 	 *     right = right hardware printer margin
228 	 *
229 	 * Returns: %TRUE if the hard margins were retrieved
230 	 */
231 	public bool getHardMargins(out double top, out double bottom, out double left, out double right)
232 	{
233 		return gtk_print_context_get_hard_margins(gtkPrintContext, &top, &bottom, &left, &right) != 0;
234 	}
235 
236 	/**
237 	 * Obtains the height of the `GtkPrintContext`, in pixels.
238 	 *
239 	 * Returns: the height of @context
240 	 */
241 	public double getHeight()
242 	{
243 		return gtk_print_context_get_height(gtkPrintContext);
244 	}
245 
246 	/**
247 	 * Obtains the `GtkPageSetup` that determines the page
248 	 * dimensions of the `GtkPrintContext`.
249 	 *
250 	 * Returns: the page setup of @context
251 	 */
252 	public PageSetup getPageSetup()
253 	{
254 		auto __p = gtk_print_context_get_page_setup(gtkPrintContext);
255 
256 		if(__p is null)
257 		{
258 			return null;
259 		}
260 
261 		return ObjectG.getDObject!(PageSetup)(cast(GtkPageSetup*) __p);
262 	}
263 
264 	/**
265 	 * Returns a `PangoFontMap` that is suitable for use
266 	 * with the `GtkPrintContext`.
267 	 *
268 	 * Returns: the font map of @context
269 	 */
270 	public PgFontMap getPangoFontmap()
271 	{
272 		auto __p = gtk_print_context_get_pango_fontmap(gtkPrintContext);
273 
274 		if(__p is null)
275 		{
276 			return null;
277 		}
278 
279 		return ObjectG.getDObject!(PgFontMap)(cast(PangoFontMap*) __p);
280 	}
281 
282 	/**
283 	 * Obtains the width of the `GtkPrintContext`, in pixels.
284 	 *
285 	 * Returns: the width of @context
286 	 */
287 	public double getWidth()
288 	{
289 		return gtk_print_context_get_width(gtkPrintContext);
290 	}
291 
292 	/**
293 	 * Sets a new cairo context on a print context.
294 	 *
295 	 * This function is intended to be used when implementing
296 	 * an internal print preview, it is not needed for printing,
297 	 * since GTK itself creates a suitable cairo context in that
298 	 * case.
299 	 *
300 	 * Params:
301 	 *     cr = the cairo context
302 	 *     dpiX = the horizontal resolution to use with @cr
303 	 *     dpiY = the vertical resolution to use with @cr
304 	 */
305 	public void setCairoContext(Context cr, double dpiX, double dpiY)
306 	{
307 		gtk_print_context_set_cairo_context(gtkPrintContext, (cr is null) ? null : cr.getContextStruct(), dpiX, dpiY);
308 	}
309 }