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