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 public  import gtkc.gtktypes;
33 private import pango.PgContext;
34 private import pango.PgFontMap;
35 private import pango.PgLayout;
36 
37 
38 /**
39  * A GtkPrintContext encapsulates context information that is required when
40  * drawing pages for printing, such as the cairo context and important
41  * parameters like page size and resolution. It also lets you easily
42  * create #PangoLayout and #PangoContext objects that match the font metrics
43  * of the cairo surface.
44  * 
45  * GtkPrintContext objects gets passed to the #GtkPrintOperation::begin-print,
46  * #GtkPrintOperation::end-print, #GtkPrintOperation::request-page-setup and
47  * #GtkPrintOperation::draw-page signals on the #GtkPrintOperation.
48  * 
49  * ## Using GtkPrintContext in a #GtkPrintOperation::draw-page callback
50  * 
51  * |[<!-- language="C" -->
52  * static void
53  * draw_page (GtkPrintOperation *operation,
54  * GtkPrintContext   *context,
55  * int                page_nr)
56  * {
57  * cairo_t *cr;
58  * PangoLayout *layout;
59  * PangoFontDescription *desc;
60  * 
61  * cr = gtk_print_context_get_cairo_context (context);
62  * 
63  * // Draw a red rectangle, as wide as the paper (inside the margins)
64  * cairo_set_source_rgb (cr, 1.0, 0, 0);
65  * cairo_rectangle (cr, 0, 0, gtk_print_context_get_width (context), 50);
66  * 
67  * cairo_fill (cr);
68  * 
69  * // Draw some lines
70  * cairo_move_to (cr, 20, 10);
71  * cairo_line_to (cr, 40, 20);
72  * cairo_arc (cr, 60, 60, 20, 0, M_PI);
73  * cairo_line_to (cr, 80, 20);
74  * 
75  * cairo_set_source_rgb (cr, 0, 0, 0);
76  * cairo_set_line_width (cr, 5);
77  * cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
78  * cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
79  * 
80  * cairo_stroke (cr);
81  * 
82  * // Draw some text
83  * layout = gtk_print_context_create_pango_layout (context);
84  * pango_layout_set_text (layout, "Hello World! Printing is easy", -1);
85  * desc = pango_font_description_from_string ("sans 28");
86  * pango_layout_set_font_description (layout, desc);
87  * pango_font_description_free (desc);
88  * 
89  * cairo_move_to (cr, 30, 20);
90  * pango_cairo_layout_path (cr, layout);
91  * 
92  * // Font Outline
93  * cairo_set_source_rgb (cr, 0.93, 1.0, 0.47);
94  * cairo_set_line_width (cr, 0.5);
95  * cairo_stroke_preserve (cr);
96  * 
97  * // Font Fill
98  * cairo_set_source_rgb (cr, 0, 0.0, 1.0);
99  * cairo_fill (cr);
100  * 
101  * g_object_unref (layout);
102  * }
103  * ]|
104  * 
105  * Printing support was added in GTK+ 2.10.
106  */
107 public class PrintContext : ObjectG
108 {
109 	/** the main Gtk struct */
110 	protected GtkPrintContext* gtkPrintContext;
111 
112 	/** Get the main Gtk struct */
113 	public GtkPrintContext* getPrintContextStruct(bool transferOwnership = false)
114 	{
115 		if (transferOwnership)
116 			ownedRef = false;
117 		return gtkPrintContext;
118 	}
119 
120 	/** the main Gtk struct as a void* */
121 	protected override void* getStruct()
122 	{
123 		return cast(void*)gtkPrintContext;
124 	}
125 
126 	/**
127 	 * Sets our main struct and passes it to the parent class.
128 	 */
129 	public this (GtkPrintContext* gtkPrintContext, bool ownedRef = false)
130 	{
131 		this.gtkPrintContext = gtkPrintContext;
132 		super(cast(GObject*)gtkPrintContext, ownedRef);
133 	}
134 
135 
136 	/** */
137 	public static GType getType()
138 	{
139 		return gtk_print_context_get_type();
140 	}
141 
142 	/**
143 	 * Creates a new #PangoContext that can be used with the
144 	 * #GtkPrintContext.
145 	 *
146 	 * Returns: a new Pango context for @context
147 	 *
148 	 * Since: 2.10
149 	 */
150 	public PgContext createPangoContext()
151 	{
152 		auto p = gtk_print_context_create_pango_context(gtkPrintContext);
153 
154 		if(p is null)
155 		{
156 			return null;
157 		}
158 
159 		return ObjectG.getDObject!(PgContext)(cast(PangoContext*) p, true);
160 	}
161 
162 	/**
163 	 * Creates a new #PangoLayout that is suitable for use
164 	 * with the #GtkPrintContext.
165 	 *
166 	 * Returns: a new Pango layout for @context
167 	 *
168 	 * Since: 2.10
169 	 */
170 	public PgLayout createPangoLayout()
171 	{
172 		auto p = gtk_print_context_create_pango_layout(gtkPrintContext);
173 
174 		if(p is null)
175 		{
176 			return null;
177 		}
178 
179 		return ObjectG.getDObject!(PgLayout)(cast(PangoLayout*) p, true);
180 	}
181 
182 	/**
183 	 * Obtains the cairo context that is associated with the
184 	 * #GtkPrintContext.
185 	 *
186 	 * Returns: the cairo context of @context
187 	 *
188 	 * Since: 2.10
189 	 */
190 	public Context getCairoContext()
191 	{
192 		auto p = gtk_print_context_get_cairo_context(gtkPrintContext);
193 
194 		if(p is null)
195 		{
196 			return null;
197 		}
198 
199 		return new Context(cast(cairo_t*) p);
200 	}
201 
202 	/**
203 	 * Obtains the horizontal resolution of the #GtkPrintContext,
204 	 * in dots per inch.
205 	 *
206 	 * Returns: the horizontal resolution of @context
207 	 *
208 	 * Since: 2.10
209 	 */
210 	public double getDpiX()
211 	{
212 		return gtk_print_context_get_dpi_x(gtkPrintContext);
213 	}
214 
215 	/**
216 	 * Obtains the vertical resolution of the #GtkPrintContext,
217 	 * in dots per inch.
218 	 *
219 	 * Returns: the vertical resolution of @context
220 	 *
221 	 * Since: 2.10
222 	 */
223 	public double getDpiY()
224 	{
225 		return gtk_print_context_get_dpi_y(gtkPrintContext);
226 	}
227 
228 	/**
229 	 * Obtains the hardware printer margins of the #GtkPrintContext, in units.
230 	 *
231 	 * Params:
232 	 *     top = top hardware printer margin
233 	 *     bottom = bottom hardware printer margin
234 	 *     left = left hardware printer margin
235 	 *     right = right hardware printer margin
236 	 *
237 	 * Returns: %TRUE if the hard margins were retrieved
238 	 *
239 	 * Since: 2.20
240 	 */
241 	public bool getHardMargins(out double top, out double bottom, out double left, out double right)
242 	{
243 		return gtk_print_context_get_hard_margins(gtkPrintContext, &top, &bottom, &left, &right) != 0;
244 	}
245 
246 	/**
247 	 * Obtains the height of the #GtkPrintContext, in pixels.
248 	 *
249 	 * Returns: the height of @context
250 	 *
251 	 * Since: 2.10
252 	 */
253 	public double getHeight()
254 	{
255 		return gtk_print_context_get_height(gtkPrintContext);
256 	}
257 
258 	/**
259 	 * Obtains the #GtkPageSetup that determines the page
260 	 * dimensions of the #GtkPrintContext.
261 	 *
262 	 * Returns: the page setup of @context
263 	 *
264 	 * Since: 2.10
265 	 */
266 	public PageSetup getPageSetup()
267 	{
268 		auto p = gtk_print_context_get_page_setup(gtkPrintContext);
269 
270 		if(p is null)
271 		{
272 			return null;
273 		}
274 
275 		return ObjectG.getDObject!(PageSetup)(cast(GtkPageSetup*) p);
276 	}
277 
278 	/**
279 	 * Returns a #PangoFontMap that is suitable for use
280 	 * with the #GtkPrintContext.
281 	 *
282 	 * Returns: the font map of @context
283 	 *
284 	 * Since: 2.10
285 	 */
286 	public PgFontMap getPangoFontmap()
287 	{
288 		auto p = gtk_print_context_get_pango_fontmap(gtkPrintContext);
289 
290 		if(p is null)
291 		{
292 			return null;
293 		}
294 
295 		return ObjectG.getDObject!(PgFontMap)(cast(PangoFontMap*) p);
296 	}
297 
298 	/**
299 	 * Obtains the width of the #GtkPrintContext, in pixels.
300 	 *
301 	 * Returns: the width of @context
302 	 *
303 	 * Since: 2.10
304 	 */
305 	public double getWidth()
306 	{
307 		return gtk_print_context_get_width(gtkPrintContext);
308 	}
309 
310 	/**
311 	 * Sets a new cairo context on a print context.
312 	 *
313 	 * This function is intended to be used when implementing
314 	 * an internal print preview, it is not needed for printing,
315 	 * since GTK+ itself creates a suitable cairo context in that
316 	 * case.
317 	 *
318 	 * Params:
319 	 *     cr = the cairo context
320 	 *     dpiX = the horizontal resolution to use with @cr
321 	 *     dpiY = the vertical resolution to use with @cr
322 	 *
323 	 * Since: 2.10
324 	 */
325 	public void setCairoContext(Context cr, double dpiX, double dpiY)
326 	{
327 		gtk_print_context_set_cairo_context(gtkPrintContext, (cr is null) ? null : cr.getContextStruct(), dpiX, dpiY);
328 	}
329 }