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  * Conversion parameters:
26  * inFile  = 
27  * outPack = pango
28  * outFile = PgCairo
29  * strct   = 
30  * realStrct=
31  * ctorStrct=
32  * clss    = PgCairo
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- pango_cairo_
41  * omit structs:
42  * omit prefixes:
43  * 	- pango_cairo_font_map_
44  * omit code:
45  * omit signals:
46  * imports:
47  * 	- glib.Str
48  * 	- cairo.Context
49  * 	- cairo.ScaledFont
50  * 	- cairo.FontOption
51  * 	- pango.PgContext
52  * 	- pango.PgFont
53  * 	- pango.PgGlyphItem
54  * 	- pango.PgGlyphString
55  * 	- pango.PgLayout
56  * 	- pango.PgLayoutLine
57  * structWrap:
58  * 	- PangoContext* -> PgContext
59  * 	- PangoFont* -> PgFont
60  * 	- PangoGlyphItem* -> PgGlyphItem
61  * 	- PangoGlyphString* -> PgGlyphString
62  * 	- PangoLayout* -> PgLayout
63  * 	- PangoLayoutLine* -> PgLayoutLine
64  * 	- cairo_font_options_t* -> FontOption
65  * 	- cairo_scaled_font_t* -> ScaledFont
66  * 	- cairo_t* -> Context
67  * module aliases:
68  * local aliases:
69  * overrides:
70  */
71 
72 module pango.PgCairo;
73 
74 public  import gtkc.pangotypes;
75 
76 private import gtkc.pango;
77 private import glib.ConstructionException;
78 private import gobject.ObjectG;
79 
80 private import glib.Str;
81 private import cairo.Context;
82 private import cairo.ScaledFont;
83 private import cairo.FontOption;
84 private import pango.PgContext;
85 private import pango.PgFont;
86 private import pango.PgGlyphItem;
87 private import pango.PgGlyphString;
88 private import pango.PgLayout;
89 private import pango.PgLayoutLine;
90 
91 
92 
93 /**
94  * The Cairo library is a
95  * vector graphics library with a powerful rendering model. It has such
96  * features as anti-aliased primitives, alpha-compositing, and
97  * gradients. Multiple backends for Cairo are available, to allow
98  * rendering to images, to PDF files, and to the screen on X and on other
99  * windowing systems. The functions in this section allow using Pango
100  * to render to Cairo surfaces.
101  *
102  * Using Pango with Cairo is straightforward. A PangoContext created
103  * with pango_cairo_font_map_create_context() can be used on any
104  * Cairo context (cairo_t), but needs to be updated to match the
105  * current transformation matrix and target surface of the Cairo context
106  * using pango_cairo_update_context(). The convenience functions
107  * pango_cairo_create_layout() and pango_cairo_update_layout() handle
108  * the common case where the program doesn't need to manipulate the
109  * properties of the PangoContext.
110  *
111  * When you get the metrics of a layout or of a piece of a layout using
112  * functions such as pango_layout_get_extents(), the reported metrics
113  * are in user-space coordinates. If a piece of text is 10 units long,
114  * and you call cairo_scale (cr, 2.0), it still is more-or-less 10
115  * units long. However, the results will be affected by hinting
116  * (that is, the process of adjusting the text to look good on the
117  * pixel grid), so you shouldn't assume they are completely independent
118  * of the current transformation matrix. Note that the basic metrics
119  * functions in Pango report results in integer Pango units. To get
120  * to the floating point units used in Cairo divide by PANGO_SCALE.
121  *
122  * $(DDOC_COMMENT example)
123  *
124  * Figure 2. Output of Example 1, “Using Pango with Cairo”
125  */
126 public class PgCairo
127 {
128 	
129 	/**
130 	 */
131 	
132 	/**
133 	 * Gets the cairo_scaled_font_t used by font.
134 	 * The scaled font can be referenced and kept using
135 	 * cairo_scaled_font_reference().
136 	 * Since 1.18
137 	 * Params:
138 	 * font = a PangoFont from a PangoCairoFontMap
139 	 * Returns: the cairo_scaled_font_t used by font, or NULL if font is NULL.
140 	 */
141 	public static ScaledFont fontGetScaledFont(PangoCairoFont* font)
142 	{
143 		// cairo_scaled_font_t * pango_cairo_font_get_scaled_font (PangoCairoFont *font);
144 		auto p = pango_cairo_font_get_scaled_font(font);
145 		
146 		if(p is null)
147 		{
148 			return null;
149 		}
150 		
151 		return ObjectG.getDObject!(ScaledFont)(cast(cairo_scaled_font_t*) p);
152 	}
153 	
154 	/**
155 	 * Sets the resolution for the context. This is a scale factor between
156 	 * points specified in a PangoFontDescription and Cairo units. The
157 	 * default value is 96, meaning that a 10 point font will be 13
158 	 * units high. (10 * 96. / 72. = 13.3).
159 	 * Since 1.10
160 	 * Params:
161 	 * context = a PangoContext, from a pangocairo font map
162 	 * dpi = the resolution in "dots per inch". (Physical inches aren't actually
163 	 * involved; the terminology is conventional.) A 0 or negative value
164 	 * means to use the resolution from the font map.
165 	 */
166 	public static void contextSetResolution(PgContext context, double dpi)
167 	{
168 		// void pango_cairo_context_set_resolution (PangoContext *context,  double dpi);
169 		pango_cairo_context_set_resolution((context is null) ? null : context.getPgContextStruct(), dpi);
170 	}
171 	
172 	/**
173 	 * Gets the resolution for the context. See pango_cairo_context_set_resolution()
174 	 * Since 1.10
175 	 * Params:
176 	 * context = a PangoContext, from a pangocairo font map
177 	 * Returns: the resolution in "dots per inch". A negative value will be returned if no resolution has previously been set.
178 	 */
179 	public static double contextGetResolution(PgContext context)
180 	{
181 		// double pango_cairo_context_get_resolution (PangoContext *context);
182 		return pango_cairo_context_get_resolution((context is null) ? null : context.getPgContextStruct());
183 	}
184 	
185 	/**
186 	 * Sets the font options used when rendering text with this context.
187 	 * These options override any options that pango_cairo_update_context()
188 	 * derives from the target surface.
189 	 * Since 1.10
190 	 * Params:
191 	 * context = a PangoContext, from a pangocairo font map
192 	 * options = a cairo_font_options_t, or NULL to unset any previously set
193 	 * options. A copy is made.
194 	 */
195 	public static void contextSetFontOptions(PgContext context, FontOption options)
196 	{
197 		// void pango_cairo_context_set_font_options  (PangoContext *context,  const cairo_font_options_t *options);
198 		pango_cairo_context_set_font_options((context is null) ? null : context.getPgContextStruct(), (options is null) ? null : options.getFontOptionStruct());
199 	}
200 	
201 	/**
202 	 * Retrieves any font rendering options previously set with
203 	 * pango_cairo_font_map_set_font_options(). This function does not report options
204 	 * that are derived from the target surface by pango_cairo_update_context()
205 	 * Since 1.10
206 	 * Params:
207 	 * context = a PangoContext, from a pangocairo font map
208 	 * Returns: the font options previously set on the context, or NULL if no options have been set. This value is owned by the context and must not be modified or freed.
209 	 */
210 	public static FontOption contextGetFontOptions(PgContext context)
211 	{
212 		// const cairo_font_options_t * pango_cairo_context_get_font_options  (PangoContext *context);
213 		auto p = pango_cairo_context_get_font_options((context is null) ? null : context.getPgContextStruct());
214 		
215 		if(p is null)
216 		{
217 			return null;
218 		}
219 		
220 		return ObjectG.getDObject!(FontOption)(cast(cairo_font_options_t*) p);
221 	}
222 	
223 	/**
224 	 * Sets callback function for context to use for rendering attributes
225 	 * of type PANGO_ATTR_SHAPE. See PangoCairoShapeRendererFunc for
226 	 * details.
227 	 * Since 1.18
228 	 * Params:
229 	 * context = a PangoContext, from a pangocairo font map
230 	 * func = Callback function for rendering attributes of type
231 	 * PANGO_ATTR_SHAPE, or NULL to disable shape rendering.
232 	 * data = User data that will be passed to func.
233 	 * dnotify = Callback that will be called when the
234 	 * context is freed to release data, or NULL.
235 	 */
236 	public static void contextSetShapeRenderer(PgContext context, PangoCairoShapeRendererFunc func, void* data, GDestroyNotify dnotify)
237 	{
238 		// void pango_cairo_context_set_shape_renderer  (PangoContext *context,  PangoCairoShapeRendererFunc func,  gpointer data,  GDestroyNotify dnotify);
239 		pango_cairo_context_set_shape_renderer((context is null) ? null : context.getPgContextStruct(), func, data, dnotify);
240 	}
241 	
242 	/**
243 	 * Sets callback function for context to use for rendering attributes
244 	 * of type PANGO_ATTR_SHAPE. See PangoCairoShapeRendererFunc for
245 	 * details.
246 	 * Retrieves callback function and associated user data for rendering
247 	 * attributes of type PANGO_ATTR_SHAPE as set by
248 	 * pango_cairo_context_set_shape_renderer(), if any.
249 	 * Since 1.18
250 	 * Params:
251 	 * context = a PangoContext, from a pangocairo font map
252 	 * data = Pointer to gpointer to return user data
253 	 * Returns: the shape rendering callback previously set on the context, or NULL if no shape rendering callback have been set.
254 	 */
255 	public static PangoCairoShapeRendererFunc contextGetShapeRenderer(PgContext context, void** data)
256 	{
257 		// PangoCairoShapeRendererFunc pango_cairo_context_get_shape_renderer  (PangoContext *context,  gpointer *data);
258 		return pango_cairo_context_get_shape_renderer((context is null) ? null : context.getPgContextStruct(), data);
259 	}
260 	
261 	/**
262 	 * Creates a context object set up to match the current transformation
263 	 * and target surface of the Cairo context. This context can then be
264 	 * used to create a layout using pango_layout_new().
265 	 * This function is a convenience function that creates a context using
266 	 * the default font map, then updates it to cr. If you just need to
267 	 * create a layout for use with cr and do not need to access PangoContext
268 	 * directly, you can use pango_cairo_create_layout() instead.
269 	 * Since 1.22
270 	 * Params:
271 	 * cr = a Cairo context
272 	 * Returns: the newly created PangoContext. Free with g_object_unref(). [transfer full]
273 	 */
274 	public static PgContext createContext(Context cr)
275 	{
276 		// PangoContext * pango_cairo_create_context (cairo_t *cr);
277 		auto p = pango_cairo_create_context((cr is null) ? null : cr.getContextStruct());
278 		
279 		if(p is null)
280 		{
281 			return null;
282 		}
283 		
284 		return ObjectG.getDObject!(PgContext)(cast(PangoContext*) p);
285 	}
286 	
287 	/**
288 	 * Updates a PangoContext previously created for use with Cairo to
289 	 * match the current transformation and target surface of a Cairo
290 	 * context. If any layouts have been created for the context,
291 	 * it's necessary to call pango_layout_context_changed() on those
292 	 * layouts.
293 	 * Since 1.10
294 	 * Params:
295 	 * cr = a Cairo context
296 	 * context = a PangoContext, from a pangocairo font map
297 	 */
298 	public static void updateContext(Context cr, PgContext context)
299 	{
300 		// void pango_cairo_update_context (cairo_t *cr,  PangoContext *context);
301 		pango_cairo_update_context((cr is null) ? null : cr.getContextStruct(), (context is null) ? null : context.getPgContextStruct());
302 	}
303 	
304 	/**
305 	 * Creates a layout object set up to match the current transformation
306 	 * and target surface of the Cairo context. This layout can then be
307 	 * used for text measurement with functions like
308 	 * pango_layout_get_size() or drawing with functions like
309 	 * pango_cairo_show_layout(). If you change the transformation
310 	 * or target surface for cr, you need to call pango_cairo_update_layout()
311 	 * This function is the most convenient way to use Cairo with Pango,
312 	 * however it is slightly inefficient since it creates a separate
313 	 * PangoContext object for each layout. This might matter in an
314 	 * application that was laying out large amounts of text.
315 	 * Since 1.10
316 	 * Params:
317 	 * cr = a Cairo context
318 	 * Returns: the newly created PangoLayout. Free with g_object_unref(). [transfer full]
319 	 */
320 	public static PgLayout createLayout(Context cr)
321 	{
322 		// PangoLayout * pango_cairo_create_layout (cairo_t *cr);
323 		auto p = pango_cairo_create_layout((cr is null) ? null : cr.getContextStruct());
324 		
325 		if(p is null)
326 		{
327 			return null;
328 		}
329 		
330 		return ObjectG.getDObject!(PgLayout)(cast(PangoLayout*) p);
331 	}
332 	
333 	/**
334 	 * Updates the private PangoContext of a PangoLayout created with
335 	 * pango_cairo_create_layout() to match the current transformation
336 	 * and target surface of a Cairo context.
337 	 * Since 1.10
338 	 * Params:
339 	 * cr = a Cairo context
340 	 * layout = a PangoLayout, from pango_cairo_create_layout()
341 	 */
342 	public static void updateLayout(Context cr, PgLayout layout)
343 	{
344 		// void pango_cairo_update_layout (cairo_t *cr,  PangoLayout *layout);
345 		pango_cairo_update_layout((cr is null) ? null : cr.getContextStruct(), (layout is null) ? null : layout.getPgLayoutStruct());
346 	}
347 	
348 	/**
349 	 * Draws the glyphs in glyphs in the specified cairo context.
350 	 * The origin of the glyphs (the left edge of the baseline) will
351 	 * be drawn at the current point of the cairo context.
352 	 * Since 1.10
353 	 * Params:
354 	 * cr = a Cairo context
355 	 * font = a PangoFont from a PangoCairoFontMap
356 	 * glyphs = a PangoGlyphString
357 	 */
358 	public static void showGlyphString(Context cr, PgFont font, PgGlyphString glyphs)
359 	{
360 		// void pango_cairo_show_glyph_string (cairo_t *cr,  PangoFont *font,  PangoGlyphString *glyphs);
361 		pango_cairo_show_glyph_string((cr is null) ? null : cr.getContextStruct(), (font is null) ? null : font.getPgFontStruct(), (glyphs is null) ? null : glyphs.getPgGlyphStringStruct());
362 	}
363 	
364 	/**
365 	 * Draws the glyphs in glyph_item in the specified cairo context,
366 	 * embedding the text associated with the glyphs in the output if the
367 	 * output format supports it (PDF for example), otherwise it acts
368 	 * similar to pango_cairo_show_glyph_string().
369 	 * The origin of the glyphs (the left edge of the baseline) will
370 	 * be drawn at the current point of the cairo context.
371 	 * Note that text is the start of the text for layout, which is then
372 	 * indexed by glyph_item->item->offset.
373 	 * Since 1.22
374 	 * Params:
375 	 * cr = a Cairo context
376 	 * text = the UTF-8 text that glyph_item refers to
377 	 * glyphItem = a PangoGlyphItem
378 	 */
379 	public static void showGlyphItem(Context cr, string text, PgGlyphItem glyphItem)
380 	{
381 		// void pango_cairo_show_glyph_item (cairo_t *cr,  const char *text,  PangoGlyphItem *glyph_item);
382 		pango_cairo_show_glyph_item((cr is null) ? null : cr.getContextStruct(), Str.toStringz(text), (glyphItem is null) ? null : glyphItem.getPgGlyphItemStruct());
383 	}
384 	
385 	/**
386 	 * Draws a PangoLayoutLine in the specified cairo context.
387 	 * The origin of the glyphs (the left edge of the line) will
388 	 * be drawn at the current point of the cairo context.
389 	 * Since 1.10
390 	 * Params:
391 	 * cr = a Cairo context
392 	 * line = a PangoLayoutLine
393 	 */
394 	public static void showLayoutLine(Context cr, PgLayoutLine line)
395 	{
396 		// void pango_cairo_show_layout_line (cairo_t *cr,  PangoLayoutLine *line);
397 		pango_cairo_show_layout_line((cr is null) ? null : cr.getContextStruct(), (line is null) ? null : line.getPgLayoutLineStruct());
398 	}
399 	
400 	/**
401 	 * Draws a PangoLayout in the specified cairo context.
402 	 * The top-left corner of the PangoLayout will be drawn
403 	 * at the current point of the cairo context.
404 	 * Since 1.10
405 	 * Params:
406 	 * cr = a Cairo context
407 	 * layout = a Pango layout
408 	 */
409 	public static void showLayout(Context cr, PgLayout layout)
410 	{
411 		// void pango_cairo_show_layout (cairo_t *cr,  PangoLayout *layout);
412 		pango_cairo_show_layout((cr is null) ? null : cr.getContextStruct(), (layout is null) ? null : layout.getPgLayoutStruct());
413 	}
414 	
415 	/**
416 	 * Draw a squiggly line in the specified cairo context that approximately
417 	 * covers the given rectangle in the style of an underline used to indicate a
418 	 * spelling error. (The width of the underline is rounded to an integer
419 	 * number of up/down segments and the resulting rectangle is centered in the
420 	 * original rectangle)
421 	 * Since 1.14
422 	 * Params:
423 	 * cr = a Cairo context
424 	 * x = The X coordinate of one corner of the rectangle
425 	 * y = The Y coordinate of one corner of the rectangle
426 	 * width = Non-negative width of the rectangle
427 	 * height = Non-negative height of the rectangle
428 	 */
429 	public static void showErrorUnderline(Context cr, double x, double y, double width, double height)
430 	{
431 		// void pango_cairo_show_error_underline (cairo_t *cr,  double x,  double y,  double width,  double height);
432 		pango_cairo_show_error_underline((cr is null) ? null : cr.getContextStruct(), x, y, width, height);
433 	}
434 	
435 	/**
436 	 * Adds the glyphs in glyphs to the current path in the specified
437 	 * cairo context. The origin of the glyphs (the left edge of the baseline)
438 	 * will be at the current point of the cairo context.
439 	 * Since 1.10
440 	 * Params:
441 	 * cr = a Cairo context
442 	 * font = a PangoFont from a PangoCairoFontMap
443 	 * glyphs = a PangoGlyphString
444 	 */
445 	public static void glyphStringPath(Context cr, PgFont font, PgGlyphString glyphs)
446 	{
447 		// void pango_cairo_glyph_string_path (cairo_t *cr,  PangoFont *font,  PangoGlyphString *glyphs);
448 		pango_cairo_glyph_string_path((cr is null) ? null : cr.getContextStruct(), (font is null) ? null : font.getPgFontStruct(), (glyphs is null) ? null : glyphs.getPgGlyphStringStruct());
449 	}
450 	
451 	/**
452 	 * Adds the text in PangoLayoutLine to the current path in the
453 	 * specified cairo context. The origin of the glyphs (the left edge
454 	 * of the line) will be at the current point of the cairo context.
455 	 * Since 1.10
456 	 * Params:
457 	 * cr = a Cairo context
458 	 * line = a PangoLayoutLine
459 	 */
460 	public static void layoutLinePath(Context cr, PgLayoutLine line)
461 	{
462 		// void pango_cairo_layout_line_path (cairo_t *cr,  PangoLayoutLine *line);
463 		pango_cairo_layout_line_path((cr is null) ? null : cr.getContextStruct(), (line is null) ? null : line.getPgLayoutLineStruct());
464 	}
465 	
466 	/**
467 	 * Adds the text in a PangoLayout to the current path in the
468 	 * specified cairo context. The top-left corner of the PangoLayout
469 	 * will be at the current point of the cairo context.
470 	 * Since 1.10
471 	 * Params:
472 	 * cr = a Cairo context
473 	 * layout = a Pango layout
474 	 */
475 	public static void layoutPath(Context cr, PgLayout layout)
476 	{
477 		// void pango_cairo_layout_path (cairo_t *cr,  PangoLayout *layout);
478 		pango_cairo_layout_path((cr is null) ? null : cr.getContextStruct(), (layout is null) ? null : layout.getPgLayoutStruct());
479 	}
480 	
481 	/**
482 	 * Add a squiggly line to the current path in the specified cairo context that
483 	 * approximately covers the given rectangle in the style of an underline used
484 	 * to indicate a spelling error. (The width of the underline is rounded to an
485 	 * integer number of up/down segments and the resulting rectangle is centered
486 	 * in the original rectangle)
487 	 * Since 1.14
488 	 * Params:
489 	 * cr = a Cairo context
490 	 * x = The X coordinate of one corner of the rectangle
491 	 * y = The Y coordinate of one corner of the rectangle
492 	 * width = Non-negative width of the rectangle
493 	 * height = Non-negative height of the rectangle
494 	 */
495 	public static void errorUnderlinePath(Context cr, double x, double y, double width, double height)
496 	{
497 		// void pango_cairo_error_underline_path (cairo_t *cr,  double x,  double y,  double width,  double height);
498 		pango_cairo_error_underline_path((cr is null) ? null : cr.getContextStruct(), x, y, width, height);
499 	}
500 }