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