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()
113 	{
114 		return gtkPrintContext;
115 	}
116 
117 	/** the main Gtk struct as a void* */
118 	protected override void* getStruct()
119 	{
120 		return cast(void*)gtkPrintContext;
121 	}
122 
123 	protected override void setStruct(GObject* obj)
124 	{
125 		gtkPrintContext = cast(GtkPrintContext*)obj;
126 		super.setStruct(obj);
127 	}
128 
129 	/**
130 	 * Sets our main struct and passes it to the parent class.
131 	 */
132 	public this (GtkPrintContext* gtkPrintContext, bool ownedRef = false)
133 	{
134 		this.gtkPrintContext = gtkPrintContext;
135 		super(cast(GObject*)gtkPrintContext, ownedRef);
136 	}
137 
138 
139 	/** */
140 	public static GType getType()
141 	{
142 		return gtk_print_context_get_type();
143 	}
144 
145 	/**
146 	 * Creates a new #PangoContext that can be used with the
147 	 * #GtkPrintContext.
148 	 *
149 	 * Return: a new Pango context for @context
150 	 *
151 	 * Since: 2.10
152 	 */
153 	public PgContext createPangoContext()
154 	{
155 		auto p = gtk_print_context_create_pango_context(gtkPrintContext);
156 		
157 		if(p is null)
158 		{
159 			return null;
160 		}
161 		
162 		return ObjectG.getDObject!(PgContext)(cast(PangoContext*) p, true);
163 	}
164 
165 	/**
166 	 * Creates a new #PangoLayout that is suitable for use
167 	 * with the #GtkPrintContext.
168 	 *
169 	 * Return: a new Pango layout for @context
170 	 *
171 	 * Since: 2.10
172 	 */
173 	public PgLayout createPangoLayout()
174 	{
175 		auto p = gtk_print_context_create_pango_layout(gtkPrintContext);
176 		
177 		if(p is null)
178 		{
179 			return null;
180 		}
181 		
182 		return ObjectG.getDObject!(PgLayout)(cast(PangoLayout*) p, true);
183 	}
184 
185 	/**
186 	 * Obtains the cairo context that is associated with the
187 	 * #GtkPrintContext.
188 	 *
189 	 * Return: the cairo context of @context
190 	 *
191 	 * Since: 2.10
192 	 */
193 	public Context getCairoContext()
194 	{
195 		auto p = gtk_print_context_get_cairo_context(gtkPrintContext);
196 		
197 		if(p is null)
198 		{
199 			return null;
200 		}
201 		
202 		return new Context(cast(cairo_t*) p);
203 	}
204 
205 	/**
206 	 * Obtains the horizontal resolution of the #GtkPrintContext,
207 	 * in dots per inch.
208 	 *
209 	 * Return: the horizontal resolution of @context
210 	 *
211 	 * Since: 2.10
212 	 */
213 	public double getDpiX()
214 	{
215 		return gtk_print_context_get_dpi_x(gtkPrintContext);
216 	}
217 
218 	/**
219 	 * Obtains the vertical resolution of the #GtkPrintContext,
220 	 * in dots per inch.
221 	 *
222 	 * Return: the vertical resolution of @context
223 	 *
224 	 * Since: 2.10
225 	 */
226 	public double getDpiY()
227 	{
228 		return gtk_print_context_get_dpi_y(gtkPrintContext);
229 	}
230 
231 	/**
232 	 * Obtains the hardware printer margins of the #GtkPrintContext, in units.
233 	 *
234 	 * Params:
235 	 *     top = top hardware printer margin
236 	 *     bottom = bottom hardware printer margin
237 	 *     left = left hardware printer margin
238 	 *     right = right hardware printer margin
239 	 *
240 	 * Return: %TRUE if the hard margins were retrieved
241 	 *
242 	 * Since: 2.20
243 	 */
244 	public bool getHardMargins(out double top, out double bottom, out double left, out double right)
245 	{
246 		return gtk_print_context_get_hard_margins(gtkPrintContext, &top, &bottom, &left, &right) != 0;
247 	}
248 
249 	/**
250 	 * Obtains the height of the #GtkPrintContext, in pixels.
251 	 *
252 	 * Return: the height of @context
253 	 *
254 	 * Since: 2.10
255 	 */
256 	public double getHeight()
257 	{
258 		return gtk_print_context_get_height(gtkPrintContext);
259 	}
260 
261 	/**
262 	 * Obtains the #GtkPageSetup that determines the page
263 	 * dimensions of the #GtkPrintContext.
264 	 *
265 	 * Return: the page setup of @context
266 	 *
267 	 * Since: 2.10
268 	 */
269 	public PageSetup getPageSetup()
270 	{
271 		auto p = gtk_print_context_get_page_setup(gtkPrintContext);
272 		
273 		if(p is null)
274 		{
275 			return null;
276 		}
277 		
278 		return ObjectG.getDObject!(PageSetup)(cast(GtkPageSetup*) p);
279 	}
280 
281 	/**
282 	 * Returns a #PangoFontMap that is suitable for use
283 	 * with the #GtkPrintContext.
284 	 *
285 	 * Return: the font map of @context
286 	 *
287 	 * Since: 2.10
288 	 */
289 	public PgFontMap getPangoFontmap()
290 	{
291 		auto p = gtk_print_context_get_pango_fontmap(gtkPrintContext);
292 		
293 		if(p is null)
294 		{
295 			return null;
296 		}
297 		
298 		return ObjectG.getDObject!(PgFontMap)(cast(PangoFontMap*) p);
299 	}
300 
301 	/**
302 	 * Obtains the width of the #GtkPrintContext, in pixels.
303 	 *
304 	 * Return: the width of @context
305 	 *
306 	 * Since: 2.10
307 	 */
308 	public double getWidth()
309 	{
310 		return gtk_print_context_get_width(gtkPrintContext);
311 	}
312 
313 	/**
314 	 * Sets a new cairo context on a print context.
315 	 *
316 	 * This function is intended to be used when implementing
317 	 * an internal print preview, it is not needed for printing,
318 	 * since GTK+ itself creates a suitable cairo context in that
319 	 * case.
320 	 *
321 	 * Params:
322 	 *     cr = the cairo context
323 	 *     dpiX = the horizontal resolution to use with @cr
324 	 *     dpiY = the vertical resolution to use with @cr
325 	 *
326 	 * Since: 2.10
327 	 */
328 	public void setCairoContext(Context cr, double dpiX, double dpiY)
329 	{
330 		gtk_print_context_set_cairo_context(gtkPrintContext, (cr is null) ? null : cr.getContextStruct(), dpiX, dpiY);
331 	}
332 }