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 = cairo-cairo-t.html 27 * outPack = cairo 28 * outFile = Context 29 * strct = cairo_t 30 * realStrct= 31 * ctorStrct= 32 * clss = Context 33 * interf = 34 * class Code: Yes 35 * interface Code: No 36 * template for: 37 * extend = 38 * implements: 39 * prefixes: 40 * - cairo_ 41 * omit structs: 42 * omit prefixes: 43 * omit code: 44 * - cairo_destroy 45 * - cairo_create 46 * omit signals: 47 * imports: 48 * - cairo.FontFace 49 * - cairo.FontOption 50 * - cairo.Matrix 51 * - cairo.ScaledFont 52 * - cairo.Surface 53 * - cairo.Pattern 54 * - glib.Str 55 * - gtkd.paths; 56 * - gtkd.Loader; 57 * structWrap: 58 * - cairo_font_face_t* -> FontFace 59 * - cairo_font_options_t* -> FontOption 60 * - cairo_matrix_t* -> Matrix 61 * - cairo_pattern_t* -> Pattern 62 * - cairo_scaled_font_t* -> ScaledFont 63 * - cairo_surface_t* -> Surface 64 * - cairo_t* -> Context 65 * module aliases: 66 * local aliases: 67 * overrides: 68 */ 69 70 module cairo.Context; 71 72 public import cairo.c.types; 73 74 private import cairo.c.functions; 75 private import glib.ConstructionException; 76 77 private import cairo.FontFace; 78 private import cairo.FontOption; 79 private import cairo.Matrix; 80 private import cairo.ScaledFont; 81 private import cairo.Surface; 82 private import cairo.Pattern; 83 private import glib.Str; 84 private import gtkd.Loader; 85 private import std.traits; 86 87 88 89 /** 90 * cairo_t is the main object used when drawing with cairo. To 91 * draw with cairo, you create a cairo_t, set the target surface, 92 * and drawing options for the cairo_t, create shapes with 93 * functions like cairo_move_to() and cairo_line_to(), and then 94 * draw shapes with cairo_stroke() or cairo_fill(). 95 * 96 * cairo_t's can be pushed to a stack via cairo_save(). 97 * They may then safely be changed, without losing the current state. 98 * Use cairo_restore() to restore to the saved state. 99 */ 100 public class Context 101 { 102 103 /** the main Gtk struct */ 104 protected cairo_t* cairo; 105 106 107 /** Get the main Gtk struct */ 108 public cairo_t* getContextStruct() 109 { 110 return cairo; 111 } 112 113 114 /** the main Gtk struct as a void* */ 115 protected void* getStruct() 116 { 117 return cast(void*)cairo; 118 } 119 120 121 /** 122 * Sets our main struct and passes it to the parent class 123 */ 124 public this (cairo_t* cairo, bool ownedRef = false) 125 { 126 this.cairo = cairo; 127 128 if ( !ownedRef ) 129 { 130 cairo_reference(this.cairo); 131 } 132 } 133 134 ~this () 135 { 136 static if ( isPointer!(typeof(cairo_get_reference_count)) ) 137 bool libLoaded = Linker.isLoaded(LIBRARY_CAIRO); 138 else 139 enum libLoaded = true; 140 141 if ( libLoaded && cairo !is null && cairo_get_reference_count(cairo) > 0 ) 142 { 143 cairo_destroy(cairo); 144 } 145 } 146 147 /** 148 * Allocates an array of cairo_glyph_t's. 149 * This function is only useful in implementations of 150 * cairo_user_scaled_font_text_to_glyphs_func_t where the user 151 * needs to allocate an array of glyphs that cairo will free. 152 * For all other uses, user can use their own allocation method 153 * for glyphs. 154 * This function returns NULL if num_glyphs is not positive, 155 * or if out of memory. That means, the NULL return value 156 * signals out-of-memory only if num_glyphs was positive. 157 * Since 1.8 158 * Params: 159 * numGlyphs = number of glyphs to allocate 160 * Returns: the newly allocated array of glyphs that should be freed using cairo_glyph_free() 161 */ 162 public static cairo_glyph_t[] glyphAllocate(int numGlyphs) 163 { 164 // cairo_glyph_t* cairo_glyph_allocate (int num_glyphs); 165 return cairo_glyph_allocate(numGlyphs)[0 .. numGlyphs]; 166 } 167 168 /** 169 * Allocates an array of cairo_text_cluster_t's. 170 * This function is only useful in implementations of 171 * cairo_user_scaled_font_text_to_glyphs_func_t where the user 172 * needs to allocate an array of text clusters that cairo will free. 173 * For all other uses, user can use their own allocation method 174 * for text clusters. 175 * This function returns NULL if num_clusters is not positive, 176 * or if out of memory. That means, the NULL return value 177 * signals out-of-memory only if num_clusters was positive. 178 * Since 1.8 179 * Params: 180 * numClusters = number of text_clusters to allocate 181 * Returns: the newly allocated array of text clusters that should be freed using cairo_text_cluster_free() 182 */ 183 public static cairo_text_cluster_t[] textClusterAllocate(int numClusters) 184 { 185 // cairo_text_cluster_t* cairo_text_cluster_allocate (int num_clusters); 186 return cairo_text_cluster_allocate(numClusters)[0 .. numClusters]; 187 } 188 189 /** 190 * Decreases the reference count on cr by one. If the result 191 * is zero, then cr and all associated resources are freed. 192 * See cairo_reference(). 193 */ 194 public void destroy() 195 { 196 uint refCount = cairo_get_reference_count(cairo); 197 198 // void cairo_destroy (cairo_t *cr); 199 cairo_destroy(cairo); 200 201 //if refCount is 1 the actual refCount after cairo_destroy is 0. 202 if ( refCount == 1 ) 203 cairo = null; 204 } 205 206 /** 207 * Creates a new context with all graphics state parameters set to 208 * default values and with target as a target surface. 209 * 210 * Since 1.0 211 * Params: 212 * target = target surface for the context 213 * 214 * Returns: 215 * a newly allocated context. This function never returns null. 216 * If memory cannot be allocated, a special context will be returned 217 * on which status() returns CairoStatus.NO_MEMORY. 218 * If you attempt to target a surface which does not support writing 219 * (such as cairo_mime_surface_t) then a CairoStatus.WRITE_ERROR will 220 * be raised. You can use this object normally, but no drawing will 221 * be done. 222 */ 223 public static Context create(Surface target) 224 { 225 // cairo_t * cairo_create (cairo_surface_t *target); 226 auto p = cairo_create((target is null) ? null : target.getSurfaceStruct()); 227 228 if(p is null) 229 { 230 return null; 231 } 232 233 return new Context(cast(cairo_t*) p, true); 234 } 235 236 /** 237 * Paths are the most basic drawing tools and are primarily used to implicitly 238 * generate simple masks. 239 */ 240 241 /** 242 * The current transformation matrix, ctm, is a 243 * two-dimensional affine transformation that maps all coordinates and other 244 * drawing instruments from the user space into the 245 * surface's canonical coordinate system, also known as the device 246 * space. 247 */ 248 249 /** 250 * The functions with text in their name form cairo's 251 * toy text API. The toy API takes UTF-8 encoded 252 * text and is limited in its functionality to rendering simple 253 * left-to-right text with no advanced features. That means for example 254 * that most complex scripts like Hebrew, Arabic, and Indic scripts are 255 * out of question. No kerning or correct positioning of diacritical marks 256 * either. The font selection is pretty limited too and doesn't handle the 257 * case that the selected font does not cover the characters in the text. 258 * This set of functions are really that, a toy text API, for testing and 259 * demonstration purposes. Any serious application should avoid them. 260 * 261 * The functions with glyphs in their name form cairo's 262 * low-level text API. The low-level API relies on 263 * the user to convert text to a set of glyph indexes and positions. This 264 * is a very hard problem and is best handled by external libraries, like 265 * the pangocairo that is part of the Pango text layout and rendering library. 266 * Pango is available from http://www.pango.org/. 267 */ 268 269 /** 270 * Increases the reference count on cr by one. This prevents 271 * cr from being destroyed until a matching call to cairo_destroy() 272 * is made. 273 * The number of references to a cairo_t can be get using 274 * cairo_get_reference_count(). 275 * Since 1.0 276 * Returns: the referenced cairo_t. 277 */ 278 public Context reference() 279 { 280 // cairo_t * cairo_reference (cairo_t *cr); 281 auto p = cairo_reference(cairo); 282 283 if(p is null) 284 { 285 return null; 286 } 287 288 return new Context(cast(cairo_t*) p); 289 } 290 291 /** 292 * Checks whether an error has previously occurred for this context. 293 * Since 1.0 294 * Returns: the current status of this context, see cairo_status_t 295 */ 296 public cairo_status_t status() 297 { 298 // cairo_status_t cairo_status (cairo_t *cr); 299 return cairo_status(cairo); 300 } 301 302 /** 303 * Makes a copy of the current state of cr and saves it 304 * on an internal stack of saved states for cr. When 305 * cairo_restore() is called, cr will be restored to 306 * the saved state. Multiple calls to cairo_save() and 307 * cairo_restore() can be nested; each call to cairo_restore() 308 * restores the state from the matching paired cairo_save(). 309 * It isn't necessary to clear all saved states before 310 * a cairo_t is freed. If the reference count of a cairo_t 311 * drops to zero in response to a call to cairo_destroy(), 312 * any saved states will be freed along with the cairo_t. 313 * Since 1.0 314 */ 315 public void save() 316 { 317 // void cairo_save (cairo_t *cr); 318 cairo_save(cairo); 319 } 320 321 /** 322 * Restores cr to the state saved by a preceding call to 323 * cairo_save() and removes that state from the stack of 324 * saved states. 325 * Since 1.0 326 */ 327 public void restore() 328 { 329 // void cairo_restore (cairo_t *cr); 330 cairo_restore(cairo); 331 } 332 333 /** 334 * Gets the target surface for the cairo context as passed to 335 * cairo_create(). 336 * This function will always return a valid pointer, but the result 337 * can be a "nil" surface if cr is already in an error state, 338 * (ie. cairo_status() != CAIRO_STATUS_SUCCESS). 339 * A nil surface is indicated by cairo_surface_status() 340 * != CAIRO_STATUS_SUCCESS. 341 * Since 1.0 342 * Returns: the target surface. This object is owned by cairo. To keep a reference to it, you must call cairo_surface_reference(). 343 */ 344 public Surface getTarget() 345 { 346 // cairo_surface_t * cairo_get_target (cairo_t *cr); 347 auto p = cairo_get_target(cairo); 348 349 if(p is null) 350 { 351 return null; 352 } 353 354 return new Surface(cast(cairo_surface_t*) p); 355 } 356 357 /** 358 * Temporarily redirects drawing to an intermediate surface known as a 359 * group. The redirection lasts until the group is completed by a call 360 * to cairo_pop_group() or cairo_pop_group_to_source(). These calls 361 * provide the result of any drawing to the group as a pattern, 362 * (either as an explicit object, or set as the source pattern). 363 * This group functionality can be convenient for performing 364 * intermediate compositing. One common use of a group is to render 365 * objects as opaque within the group, (so that they occlude each 366 * other), and then blend the result with translucence onto the 367 * destination. 368 * Groups can be nested arbitrarily deep by making balanced calls to 369 * cairo_push_group()/cairo_pop_group(). Each call pushes/pops the new 370 * target group onto/from a stack. 371 * The cairo_push_group() function calls cairo_save() so that any 372 * changes to the graphics state will not be visible outside the 373 * group, (the pop_group functions call cairo_restore()). 374 * By default the intermediate group will have a content type of 375 * CAIRO_CONTENT_COLOR_ALPHA. Other content types can be chosen for 376 * the group by using cairo_push_group_with_content() instead. 377 * As an example, here is how one might fill and stroke a path with 378 * translucence, but without any portion of the fill being visible 379 * Since 1.2 380 */ 381 public void pushGroup() 382 { 383 // void cairo_push_group (cairo_t *cr); 384 cairo_push_group(cairo); 385 } 386 387 /** 388 * Temporarily redirects drawing to an intermediate surface known as a 389 * group. The redirection lasts until the group is completed by a call 390 * to cairo_pop_group() or cairo_pop_group_to_source(). These calls 391 * provide the result of any drawing to the group as a pattern, 392 * (either as an explicit object, or set as the source pattern). 393 * The group will have a content type of content. The ability to 394 * control this content type is the only distinction between this 395 * function and cairo_push_group() which you should see for a more 396 * detailed description of group rendering. 397 * Since 1.2 398 * Params: 399 * content = a cairo_content_t indicating the type of group that 400 * will be created 401 */ 402 public void pushGroupWithContent(cairo_content_t content) 403 { 404 // void cairo_push_group_with_content (cairo_t *cr, cairo_content_t content); 405 cairo_push_group_with_content(cairo, content); 406 } 407 408 /** 409 * Terminates the redirection begun by a call to cairo_push_group() or 410 * cairo_push_group_with_content() and returns a new pattern 411 * containing the results of all drawing operations performed to the 412 * group. 413 * The cairo_pop_group() function calls cairo_restore(), (balancing a 414 * call to cairo_save() by the push_group function), so that any 415 * changes to the graphics state will not be visible outside the 416 * group. 417 * Since 1.2 418 * Returns: a newly created (surface) pattern containing the results of all drawing operations performed to the group. The caller owns the returned object and should call cairo_pattern_destroy() when finished with it. 419 */ 420 public Pattern popGroup() 421 { 422 // cairo_pattern_t * cairo_pop_group (cairo_t *cr); 423 auto p = cairo_pop_group(cairo); 424 425 if(p is null) 426 { 427 return null; 428 } 429 430 return new Pattern(cast(cairo_pattern_t*) p); 431 } 432 433 /** 434 * Terminates the redirection begun by a call to cairo_push_group() or 435 * cairo_push_group_with_content() and installs the resulting pattern 436 * as the source pattern in the given cairo context. 437 * The behavior of this function is equivalent to the sequence of 438 * Since 1.2 439 */ 440 public void popGroupToSource() 441 { 442 // void cairo_pop_group_to_source (cairo_t *cr); 443 cairo_pop_group_to_source(cairo); 444 } 445 446 /** 447 * Gets the current destination surface for the context. This is either 448 * the original target surface as passed to cairo_create() or the target 449 * surface for the current group as started by the most recent call to 450 * cairo_push_group() or cairo_push_group_with_content(). 451 * This function will always return a valid pointer, but the result 452 * can be a "nil" surface if cr is already in an error state, 453 * (ie. cairo_status() != CAIRO_STATUS_SUCCESS). 454 * A nil surface is indicated by cairo_surface_status() 455 * != CAIRO_STATUS_SUCCESS. 456 * Since 1.2 457 * Returns: the target surface. This object is owned by cairo. To keep a reference to it, you must call cairo_surface_reference(). 458 */ 459 public Surface getGroupTarget() 460 { 461 // cairo_surface_t * cairo_get_group_target (cairo_t *cr); 462 auto p = cairo_get_group_target(cairo); 463 464 if(p is null) 465 { 466 return null; 467 } 468 469 return new Surface(cast(cairo_surface_t*) p); 470 } 471 472 /** 473 * Sets the source pattern within cr to an opaque color. This opaque 474 * color will then be used for any subsequent drawing operation until 475 * a new source pattern is set. 476 * The color components are floating point numbers in the range 0 to 477 * 1. If the values passed in are outside that range, they will be 478 * clamped. 479 * The default source pattern is opaque black, (that is, it is 480 * equivalent to cairo_set_source_rgb(cr, 0.0, 0.0, 0.0)). 481 * Since 1.0 482 * Params: 483 * red = red component of color 484 * green = green component of color 485 * blue = blue component of color 486 */ 487 public void setSourceRgb(double red, double green, double blue) 488 { 489 // void cairo_set_source_rgb (cairo_t *cr, double red, double green, double blue); 490 cairo_set_source_rgb(cairo, red, green, blue); 491 } 492 493 /** 494 * Sets the source pattern within cr to a translucent color. This 495 * color will then be used for any subsequent drawing operation until 496 * a new source pattern is set. 497 * The color and alpha components are floating point numbers in the 498 * range 0 to 1. If the values passed in are outside that range, they 499 * will be clamped. 500 * The default source pattern is opaque black, (that is, it is 501 * equivalent to cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0)). 502 * Since 1.0 503 * Params: 504 * red = red component of color 505 * green = green component of color 506 * blue = blue component of color 507 * alpha = alpha component of color 508 */ 509 public void setSourceRgba(double red, double green, double blue, double alpha) 510 { 511 // void cairo_set_source_rgba (cairo_t *cr, double red, double green, double blue, double alpha); 512 cairo_set_source_rgba(cairo, red, green, blue, alpha); 513 } 514 515 /** 516 * Sets the source pattern within cr to source. This pattern 517 * will then be used for any subsequent drawing operation until a new 518 * source pattern is set. 519 * Note: The pattern's transformation matrix will be locked to the 520 * user space in effect at the time of cairo_set_source(). This means 521 * that further modifications of the current transformation matrix 522 * will not affect the source pattern. See cairo_pattern_set_matrix(). 523 * The default source pattern is a solid pattern that is opaque black, 524 * (that is, it is equivalent to cairo_set_source_rgb(cr, 0.0, 0.0, 525 * 0.0)). 526 * Since 1.0 527 * Params: 528 * source = a cairo_pattern_t to be used as the source for 529 * subsequent drawing operations. 530 */ 531 public void setSource(Pattern source) 532 { 533 // void cairo_set_source (cairo_t *cr, cairo_pattern_t *source); 534 cairo_set_source(cairo, (source is null) ? null : source.getPatternStruct()); 535 } 536 537 /** 538 * This is a convenience function for creating a pattern from surface 539 * and setting it as the source in cr with cairo_set_source(). 540 * The x and y parameters give the user-space coordinate at which 541 * the surface origin should appear. (The surface origin is its 542 * upper-left corner before any transformation has been applied.) The 543 * x and y parameters are negated and then set as translation values 544 * in the pattern matrix. 545 * Other than the initial translation pattern matrix, as described 546 * above, all other pattern attributes, (such as its extend mode), are 547 * set to the default values as in cairo_pattern_create_for_surface(). 548 * The resulting pattern can be queried with cairo_get_source() so 549 * that these attributes can be modified if desired, (eg. to create a 550 * repeating pattern with cairo_pattern_set_extend()). 551 * Since 1.0 552 * Params: 553 * surface = a surface to be used to set the source pattern 554 * x = User-space X coordinate for surface origin 555 * y = User-space Y coordinate for surface origin 556 */ 557 public void setSourceSurface(Surface surface, double x, double y) 558 { 559 // void cairo_set_source_surface (cairo_t *cr, cairo_surface_t *surface, double x, double y); 560 cairo_set_source_surface(cairo, (surface is null) ? null : surface.getSurfaceStruct(), x, y); 561 } 562 563 /** 564 * Gets the current source pattern for cr. 565 * Since 1.0 566 * Returns: the current source pattern. This object is owned by cairo. To keep a reference to it, you must call cairo_pattern_reference(). 567 */ 568 public Pattern getSource() 569 { 570 // cairo_pattern_t * cairo_get_source (cairo_t *cr); 571 auto p = cairo_get_source(cairo); 572 573 if(p is null) 574 { 575 return null; 576 } 577 578 return new Pattern(cast(cairo_pattern_t*) p); 579 } 580 581 /** 582 * Set the antialiasing mode of the rasterizer used for drawing shapes. 583 * This value is a hint, and a particular backend may or may not support 584 * a particular value. At the current time, no backend supports 585 * CAIRO_ANTIALIAS_SUBPIXEL when drawing shapes. 586 * Note that this option does not affect text rendering, instead see 587 * cairo_font_options_set_antialias(). 588 * Since 1.0 589 * Params: 590 * antialias = the new antialiasing mode 591 */ 592 public void setAntialias(cairo_antialias_t antialias) 593 { 594 // void cairo_set_antialias (cairo_t *cr, cairo_antialias_t antialias); 595 cairo_set_antialias(cairo, antialias); 596 } 597 598 /** 599 * Gets the current shape antialiasing mode, as set by 600 * cairo_set_antialias(). 601 * Since 1.0 602 * Returns: the current shape antialiasing mode. 603 */ 604 public cairo_antialias_t getAntialias() 605 { 606 // cairo_antialias_t cairo_get_antialias (cairo_t *cr); 607 return cairo_get_antialias(cairo); 608 } 609 610 /** 611 * Sets the dash pattern to be used by cairo_stroke(). A dash pattern 612 * is specified by dashes, an array of positive values. Each value 613 * provides the length of alternate "on" and "off" portions of the 614 * stroke. The offset specifies an offset into the pattern at which 615 * the stroke begins. 616 * Each "on" segment will have caps applied as if the segment were a 617 * separate sub-path. In particular, it is valid to use an "on" length 618 * of 0.0 with CAIRO_LINE_CAP_ROUND or CAIRO_LINE_CAP_SQUARE in order 619 * to distributed dots or squares along a path. 620 * Note: The length values are in user-space units as evaluated at the 621 * time of stroking. This is not necessarily the same as the user 622 * space at the time of cairo_set_dash(). 623 * If num_dashes is 0 dashing is disabled. 624 * If num_dashes is 1 a symmetric pattern is assumed with alternating 625 * on and off portions of the size specified by the single value in 626 * dashes. 627 * If any value in dashes is negative, or if all values are 0, then 628 * cr will be put into an error state with a status of 629 * CAIRO_STATUS_INVALID_DASH. 630 * Since 1.0 631 * Params: 632 * dashes = an array specifying alternate lengths of on and off stroke portions 633 * offset = an offset into the dash pattern at which the stroke should start 634 */ 635 public void setDash(double[] dashes, double offset) 636 { 637 // void cairo_set_dash (cairo_t *cr, const double *dashes, int num_dashes, double offset); 638 cairo_set_dash(cairo, dashes.ptr, cast(int) dashes.length, offset); 639 } 640 641 /** 642 * This function returns the length of the dash array in cr (0 if dashing 643 * is not currently in effect). 644 * See also cairo_set_dash() and cairo_get_dash(). 645 * Since 1.4 646 * Returns: the length of the dash array, or 0 if no dash array set. 647 */ 648 public int getDashCount() 649 { 650 // int cairo_get_dash_count (cairo_t *cr); 651 return cairo_get_dash_count(cairo); 652 } 653 654 /** 655 * Gets the current dash array. If not NULL, dashes should be big 656 * enough to hold at least the number of values returned by 657 * cairo_get_dash_count(). 658 * Since 1.4 659 * Params: 660 * dashes = return value for the dash array, or NULL 661 * offset = return value for the current dash offset, or NULL 662 */ 663 public void getDash(double* dashes, double* offset) 664 { 665 // void cairo_get_dash (cairo_t *cr, double *dashes, double *offset); 666 cairo_get_dash(cairo, dashes, offset); 667 } 668 669 /** 670 * Set the current fill rule within the cairo context. The fill rule 671 * is used to determine which regions are inside or outside a complex 672 * (potentially self-intersecting) path. The current fill rule affects 673 * both cairo_fill() and cairo_clip(). See cairo_fill_rule_t for details 674 * on the semantics of each available fill rule. 675 * The default fill rule is CAIRO_FILL_RULE_WINDING. 676 * Since 1.0 677 * Params: 678 * fillRule = a fill rule, specified as a cairo_fill_rule_t 679 */ 680 public void setFillRule(cairo_fill_rule_t fillRule) 681 { 682 // void cairo_set_fill_rule (cairo_t *cr, cairo_fill_rule_t fill_rule); 683 cairo_set_fill_rule(cairo, fillRule); 684 } 685 686 /** 687 * Gets the current fill rule, as set by cairo_set_fill_rule(). 688 * Since 1.0 689 * Returns: the current fill rule. 690 */ 691 public cairo_fill_rule_t getFillRule() 692 { 693 // cairo_fill_rule_t cairo_get_fill_rule (cairo_t *cr); 694 return cairo_get_fill_rule(cairo); 695 } 696 697 /** 698 * Sets the current line cap style within the cairo context. See 699 * cairo_line_cap_t for details about how the available line cap 700 * styles are drawn. 701 * As with the other stroke parameters, the current line cap style is 702 * examined by cairo_stroke(), cairo_stroke_extents(), and 703 * cairo_stroke_to_path(), but does not have any effect during path 704 * construction. 705 * The default line cap style is CAIRO_LINE_CAP_BUTT. 706 * Since 1.0 707 * Params: 708 * lineCap = a line cap style 709 */ 710 public void setLineCap(cairo_line_cap_t lineCap) 711 { 712 // void cairo_set_line_cap (cairo_t *cr, cairo_line_cap_t line_cap); 713 cairo_set_line_cap(cairo, lineCap); 714 } 715 716 /** 717 * Gets the current line cap style, as set by cairo_set_line_cap(). 718 * Since 1.0 719 * Returns: the current line cap style. 720 */ 721 public cairo_line_cap_t getLineCap() 722 { 723 // cairo_line_cap_t cairo_get_line_cap (cairo_t *cr); 724 return cairo_get_line_cap(cairo); 725 } 726 727 /** 728 * Sets the current line join style within the cairo context. See 729 * cairo_line_join_t for details about how the available line join 730 * styles are drawn. 731 * As with the other stroke parameters, the current line join style is 732 * examined by cairo_stroke(), cairo_stroke_extents(), and 733 * cairo_stroke_to_path(), but does not have any effect during path 734 * construction. 735 * The default line join style is CAIRO_LINE_JOIN_MITER. 736 * Since 1.0 737 * Params: 738 * lineJoin = a line join style 739 */ 740 public void setLineJoin(cairo_line_join_t lineJoin) 741 { 742 // void cairo_set_line_join (cairo_t *cr, cairo_line_join_t line_join); 743 cairo_set_line_join(cairo, lineJoin); 744 } 745 746 /** 747 * Gets the current line join style, as set by cairo_set_line_join(). 748 * Since 1.0 749 * Returns: the current line join style. 750 */ 751 public cairo_line_join_t getLineJoin() 752 { 753 // cairo_line_join_t cairo_get_line_join (cairo_t *cr); 754 return cairo_get_line_join(cairo); 755 } 756 757 /** 758 * Sets the current line width within the cairo context. The line 759 * width value specifies the diameter of a pen that is circular in 760 * user space, (though device-space pen may be an ellipse in general 761 * due to scaling/shear/rotation of the CTM). 762 * Note: When the description above refers to user space and CTM it 763 * refers to the user space and CTM in effect at the time of the 764 * stroking operation, not the user space and CTM in effect at the 765 * time of the call to cairo_set_line_width(). The simplest usage 766 * makes both of these spaces identical. That is, if there is no 767 * change to the CTM between a call to cairo_set_line_width() and the 768 * stroking operation, then one can just pass user-space values to 769 * cairo_set_line_width() and ignore this note. 770 * As with the other stroke parameters, the current line width is 771 * examined by cairo_stroke(), cairo_stroke_extents(), and 772 * cairo_stroke_to_path(), but does not have any effect during path 773 * construction. 774 * The default line width value is 2.0. 775 * Since 1.0 776 * Params: 777 * width = a line width 778 */ 779 public void setLineWidth(double width) 780 { 781 // void cairo_set_line_width (cairo_t *cr, double width); 782 cairo_set_line_width(cairo, width); 783 } 784 785 /** 786 * This function returns the current line width value exactly as set by 787 * cairo_set_line_width(). Note that the value is unchanged even if 788 * the CTM has changed between the calls to cairo_set_line_width() and 789 * cairo_get_line_width(). 790 * Since 1.0 791 * Returns: the current line width. 792 */ 793 public double getLineWidth() 794 { 795 // double cairo_get_line_width (cairo_t *cr); 796 return cairo_get_line_width(cairo); 797 } 798 799 /** 800 * Sets the current miter limit within the cairo context. 801 * If the current line join style is set to CAIRO_LINE_JOIN_MITER 802 * (see cairo_set_line_join()), the miter limit is used to determine 803 * whether the lines should be joined with a bevel instead of a miter. 804 * Cairo divides the length of the miter by the line width. 805 * If the result is greater than the miter limit, the style is 806 * converted to a bevel. 807 * As with the other stroke parameters, the current line miter limit is 808 * examined by cairo_stroke(), cairo_stroke_extents(), and 809 * cairo_stroke_to_path(), but does not have any effect during path 810 * construction. 811 * The default miter limit value is 10.0, which will convert joins 812 * with interior angles less than 11 degrees to bevels instead of 813 * miters. For reference, a miter limit of 2.0 makes the miter cutoff 814 * at 60 degrees, and a miter limit of 1.414 makes the cutoff at 90 815 * degrees. 816 * A miter limit for a desired angle can be computed as: miter limit = 817 * 1/sin(angle/2) 818 * Since 1.0 819 * Params: 820 * limit = miter limit to set 821 */ 822 public void setMiterLimit(double limit) 823 { 824 // void cairo_set_miter_limit (cairo_t *cr, double limit); 825 cairo_set_miter_limit(cairo, limit); 826 } 827 828 /** 829 * Gets the current miter limit, as set by cairo_set_miter_limit(). 830 * Since 1.0 831 * Returns: the current miter limit. 832 */ 833 public double getMiterLimit() 834 { 835 // double cairo_get_miter_limit (cairo_t *cr); 836 return cairo_get_miter_limit(cairo); 837 } 838 839 /** 840 * Sets the compositing operator to be used for all drawing 841 * operations. See cairo_operator_t for details on the semantics of 842 * each available compositing operator. 843 * The default operator is CAIRO_OPERATOR_OVER. 844 * Since 1.0 845 * Params: 846 * op = a compositing operator, specified as a cairo_operator_t 847 */ 848 public void setOperator(cairo_operator_t op) 849 { 850 // void cairo_set_operator (cairo_t *cr, cairo_operator_t op); 851 cairo_set_operator(cairo, op); 852 } 853 854 /** 855 * Gets the current compositing operator for a cairo context. 856 * Since 1.0 857 * Returns: the current compositing operator. 858 */ 859 public cairo_operator_t getOperator() 860 { 861 // cairo_operator_t cairo_get_operator (cairo_t *cr); 862 return cairo_get_operator(cairo); 863 } 864 865 /** 866 * Sets the tolerance used when converting paths into trapezoids. 867 * Curved segments of the path will be subdivided until the maximum 868 * deviation between the original path and the polygonal approximation 869 * is less than tolerance. The default value is 0.1. A larger 870 * value will give better performance, a smaller value, better 871 * appearance. (Reducing the value from the default value of 0.1 872 * is unlikely to improve appearance significantly.) The accuracy of paths 873 * within Cairo is limited by the precision of its internal arithmetic, and 874 * the prescribed tolerance is restricted to the smallest 875 * representable internal value. 876 * Since 1.0 877 * Params: 878 * tolerance = the tolerance, in device units (typically pixels) 879 */ 880 public void setTolerance(double tolerance) 881 { 882 // void cairo_set_tolerance (cairo_t *cr, double tolerance); 883 cairo_set_tolerance(cairo, tolerance); 884 } 885 886 /** 887 * Gets the current tolerance value, as set by cairo_set_tolerance(). 888 * Since 1.0 889 * Returns: the current tolerance value. 890 */ 891 public double getTolerance() 892 { 893 // double cairo_get_tolerance (cairo_t *cr); 894 return cairo_get_tolerance(cairo); 895 } 896 897 /** 898 * Establishes a new clip region by intersecting the current clip 899 * region with the current path as it would be filled by cairo_fill() 900 * and according to the current fill rule (see cairo_set_fill_rule()). 901 * After cairo_clip(), the current path will be cleared from the cairo 902 * context. 903 * The current clip region affects all drawing operations by 904 * effectively masking out any changes to the surface that are outside 905 * the current clip region. 906 * Calling cairo_clip() can only make the clip region smaller, never 907 * larger. But the current clip is part of the graphics state, so a 908 * temporary restriction of the clip region can be achieved by 909 * calling cairo_clip() within a cairo_save()/cairo_restore() 910 * pair. The only other means of increasing the size of the clip 911 * region is cairo_reset_clip(). 912 * Since 1.0 913 */ 914 public void clip() 915 { 916 // void cairo_clip (cairo_t *cr); 917 cairo_clip(cairo); 918 } 919 920 /** 921 * Establishes a new clip region by intersecting the current clip 922 * region with the current path as it would be filled by cairo_fill() 923 * and according to the current fill rule (see cairo_set_fill_rule()). 924 * Unlike cairo_clip(), cairo_clip_preserve() preserves the path within 925 * the cairo context. 926 * The current clip region affects all drawing operations by 927 * effectively masking out any changes to the surface that are outside 928 * the current clip region. 929 * Calling cairo_clip_preserve() can only make the clip region smaller, never 930 * larger. But the current clip is part of the graphics state, so a 931 * temporary restriction of the clip region can be achieved by 932 * calling cairo_clip_preserve() within a cairo_save()/cairo_restore() 933 * pair. The only other means of increasing the size of the clip 934 * region is cairo_reset_clip(). 935 * Since 1.0 936 */ 937 public void clipPreserve() 938 { 939 // void cairo_clip_preserve (cairo_t *cr); 940 cairo_clip_preserve(cairo); 941 } 942 943 /** 944 * Computes a bounding box in user coordinates covering the area inside the 945 * current clip. 946 * Since 1.4 947 * Params: 948 * x1 = left of the resulting extents 949 * y1 = top of the resulting extents 950 * x2 = right of the resulting extents 951 * y2 = bottom of the resulting extents 952 */ 953 public void clipExtents(out double x1, out double y1, out double x2, out double y2) 954 { 955 // void cairo_clip_extents (cairo_t *cr, double *x1, double *y1, double *x2, double *y2); 956 cairo_clip_extents(cairo, &x1, &y1, &x2, &y2); 957 } 958 959 /** 960 * Tests whether the given point is inside the area that would be 961 * visible through the current clip, i.e. the area that would be filled by 962 * a cairo_paint() operation. 963 * See cairo_clip(), and cairo_clip_preserve(). 964 * Since 1.10 965 * Params: 966 * x = X coordinate of the point to test 967 * y = Y coordinate of the point to test 968 * Returns: A non-zero value if the point is inside, or zero if outside. 969 */ 970 public cairo_bool_t inClip(double x, double y) 971 { 972 // cairo_bool_t cairo_in_clip (cairo_t *cr, double x, double y); 973 return cairo_in_clip(cairo, x, y); 974 } 975 976 /** 977 * Reset the current clip region to its original, unrestricted 978 * state. That is, set the clip region to an infinitely large shape 979 * containing the target surface. Equivalently, if infinity is too 980 * hard to grasp, one can imagine the clip region being reset to the 981 * exact bounds of the target surface. 982 * Note that code meant to be reusable should not call 983 * cairo_reset_clip() as it will cause results unexpected by 984 * higher-level code which calls cairo_clip(). Consider using 985 * cairo_save() and cairo_restore() around cairo_clip() as a more 986 * robust means of temporarily restricting the clip region. 987 * Since 1.0 988 */ 989 public void resetClip() 990 { 991 // void cairo_reset_clip (cairo_t *cr); 992 cairo_reset_clip(cairo); 993 } 994 995 /** 996 * Unconditionally frees rectangle_list and all associated 997 * references. After this call, the rectangle_list pointer must not 998 * be dereferenced. 999 * Since 1.4 1000 * Params: 1001 * rectangleList = a rectangle list, as obtained from cairo_copy_clip_rectangle_list() 1002 */ 1003 public static void rectangleListDestroy(cairo_rectangle_list_t* rectangleList) 1004 { 1005 // void cairo_rectangle_list_destroy (cairo_rectangle_list_t *rectangle_list); 1006 cairo_rectangle_list_destroy(rectangleList); 1007 } 1008 1009 /** 1010 * Gets the current clip region as a list of rectangles in user coordinates. 1011 * Never returns NULL. 1012 * The status in the list may be CAIRO_STATUS_CLIP_NOT_REPRESENTABLE to 1013 * indicate that the clip region cannot be represented as a list of 1014 * user-space rectangles. The status may have other values to indicate 1015 * other errors. 1016 * Since 1.4 1017 * Returns: the current clip region as a list of rectangles in user coordinates, which should be destroyed using cairo_rectangle_list_destroy(). 1018 */ 1019 public cairo_rectangle_list_t* copyClipRectangleList() 1020 { 1021 // cairo_rectangle_list_t * cairo_copy_clip_rectangle_list (cairo_t *cr); 1022 return cairo_copy_clip_rectangle_list(cairo); 1023 } 1024 1025 /** 1026 * A drawing operator that fills the current path according to the 1027 * current fill rule, (each sub-path is implicitly closed before being 1028 * filled). After cairo_fill(), the current path will be cleared from 1029 * the cairo context. See cairo_set_fill_rule() and 1030 * cairo_fill_preserve(). 1031 * Since 1.0 1032 */ 1033 public void fill() 1034 { 1035 // void cairo_fill (cairo_t *cr); 1036 cairo_fill(cairo); 1037 } 1038 1039 /** 1040 * A drawing operator that fills the current path according to the 1041 * current fill rule, (each sub-path is implicitly closed before being 1042 * filled). Unlike cairo_fill(), cairo_fill_preserve() preserves the 1043 * path within the cairo context. 1044 * See cairo_set_fill_rule() and cairo_fill(). 1045 * Since 1.0 1046 */ 1047 public void fillPreserve() 1048 { 1049 // void cairo_fill_preserve (cairo_t *cr); 1050 cairo_fill_preserve(cairo); 1051 } 1052 1053 /** 1054 * Computes a bounding box in user coordinates covering the area that 1055 * would be affected, (the "inked" area), by a cairo_fill() operation 1056 * given the current path and fill parameters. If the current path is 1057 * empty, returns an empty rectangle ((0,0), (0,0)). Surface 1058 * dimensions and clipping are not taken into account. 1059 * Contrast with cairo_path_extents(), which is similar, but returns 1060 * non-zero extents for some paths with no inked area, (such as a 1061 * simple line segment). 1062 * Note that cairo_fill_extents() must necessarily do more work to 1063 * compute the precise inked areas in light of the fill rule, so 1064 * cairo_path_extents() may be more desirable for sake of performance 1065 * if the non-inked path extents are desired. 1066 * See cairo_fill(), cairo_set_fill_rule() and cairo_fill_preserve(). 1067 * Since 1.0 1068 * Params: 1069 * x1 = left of the resulting extents 1070 * y1 = top of the resulting extents 1071 * x2 = right of the resulting extents 1072 * y2 = bottom of the resulting extents 1073 */ 1074 public void fillExtents(out double x1, out double y1, out double x2, out double y2) 1075 { 1076 // void cairo_fill_extents (cairo_t *cr, double *x1, double *y1, double *x2, double *y2); 1077 cairo_fill_extents(cairo, &x1, &y1, &x2, &y2); 1078 } 1079 1080 /** 1081 * Tests whether the given point is inside the area that would be 1082 * affected by a cairo_fill() operation given the current path and 1083 * filling parameters. Surface dimensions and clipping are not taken 1084 * into account. 1085 * See cairo_fill(), cairo_set_fill_rule() and cairo_fill_preserve(). 1086 * Since 1.0 1087 * Params: 1088 * x = X coordinate of the point to test 1089 * y = Y coordinate of the point to test 1090 * Returns: A non-zero value if the point is inside, or zero if outside. 1091 */ 1092 public cairo_bool_t inFill(double x, double y) 1093 { 1094 // cairo_bool_t cairo_in_fill (cairo_t *cr, double x, double y); 1095 return cairo_in_fill(cairo, x, y); 1096 } 1097 1098 /** 1099 * A drawing operator that paints the current source 1100 * using the alpha channel of pattern as a mask. (Opaque 1101 * areas of pattern are painted with the source, transparent 1102 * areas are not painted.) 1103 * Since 1.0 1104 * Params: 1105 * pattern = a cairo_pattern_t 1106 */ 1107 public void mask(Pattern pattern) 1108 { 1109 // void cairo_mask (cairo_t *cr, cairo_pattern_t *pattern); 1110 cairo_mask(cairo, (pattern is null) ? null : pattern.getPatternStruct()); 1111 } 1112 1113 /** 1114 * A drawing operator that paints the current source 1115 * using the alpha channel of surface as a mask. (Opaque 1116 * areas of surface are painted with the source, transparent 1117 * areas are not painted.) 1118 * Since 1.0 1119 * Params: 1120 * surface = a cairo_surface_t 1121 * surfaceX = X coordinate at which to place the origin of surface 1122 * surfaceY = Y coordinate at which to place the origin of surface 1123 */ 1124 public void maskSurface(Surface surface, double surfaceX, double surfaceY) 1125 { 1126 // void cairo_mask_surface (cairo_t *cr, cairo_surface_t *surface, double surface_x, double surface_y); 1127 cairo_mask_surface(cairo, (surface is null) ? null : surface.getSurfaceStruct(), surfaceX, surfaceY); 1128 } 1129 1130 /** 1131 * A drawing operator that paints the current source everywhere within 1132 * the current clip region. 1133 * Since 1.0 1134 */ 1135 public void paint() 1136 { 1137 // void cairo_paint (cairo_t *cr); 1138 cairo_paint(cairo); 1139 } 1140 1141 /** 1142 * A drawing operator that paints the current source everywhere within 1143 * the current clip region using a mask of constant alpha value 1144 * alpha. The effect is similar to cairo_paint(), but the drawing 1145 * is faded out using the alpha value. 1146 * Since 1.0 1147 * Params: 1148 * alpha = alpha value, between 0 (transparent) and 1 (opaque) 1149 */ 1150 public void paintWithAlpha(double alpha) 1151 { 1152 // void cairo_paint_with_alpha (cairo_t *cr, double alpha); 1153 cairo_paint_with_alpha(cairo, alpha); 1154 } 1155 1156 /** 1157 * A drawing operator that strokes the current path according to the 1158 * current line width, line join, line cap, and dash settings. After 1159 * cairo_stroke(), the current path will be cleared from the cairo 1160 * context. See cairo_set_line_width(), cairo_set_line_join(), 1161 * cairo_set_line_cap(), cairo_set_dash(), and 1162 * cairo_stroke_preserve(). 1163 * Note: Degenerate segments and sub-paths are treated specially and 1164 * provide a useful result. These can result in two different 1165 * Since 1.0 1166 */ 1167 public void stroke() 1168 { 1169 // void cairo_stroke (cairo_t *cr); 1170 cairo_stroke(cairo); 1171 } 1172 1173 /** 1174 * A drawing operator that strokes the current path according to the 1175 * current line width, line join, line cap, and dash settings. Unlike 1176 * cairo_stroke(), cairo_stroke_preserve() preserves the path within the 1177 * cairo context. 1178 * See cairo_set_line_width(), cairo_set_line_join(), 1179 * cairo_set_line_cap(), cairo_set_dash(), and 1180 * cairo_stroke_preserve(). 1181 * Since 1.0 1182 */ 1183 public void strokePreserve() 1184 { 1185 // void cairo_stroke_preserve (cairo_t *cr); 1186 cairo_stroke_preserve(cairo); 1187 } 1188 1189 /** 1190 * Computes a bounding box in user coordinates covering the area that 1191 * would be affected, (the "inked" area), by a cairo_stroke() 1192 * operation given the current path and stroke parameters. 1193 * If the current path is empty, returns an empty rectangle ((0,0), (0,0)). 1194 * Surface dimensions and clipping are not taken into account. 1195 * Note that if the line width is set to exactly zero, then 1196 * cairo_stroke_extents() will return an empty rectangle. Contrast with 1197 * cairo_path_extents() which can be used to compute the non-empty 1198 * bounds as the line width approaches zero. 1199 * Note that cairo_stroke_extents() must necessarily do more work to 1200 * compute the precise inked areas in light of the stroke parameters, 1201 * so cairo_path_extents() may be more desirable for sake of 1202 * performance if non-inked path extents are desired. 1203 * See cairo_stroke(), cairo_set_line_width(), cairo_set_line_join(), 1204 * cairo_set_line_cap(), cairo_set_dash(), and 1205 * cairo_stroke_preserve(). 1206 * Since 1.0 1207 * Params: 1208 * x1 = left of the resulting extents 1209 * y1 = top of the resulting extents 1210 * x2 = right of the resulting extents 1211 * y2 = bottom of the resulting extents 1212 */ 1213 public void strokeExtents(out double x1, out double y1, out double x2, out double y2) 1214 { 1215 // void cairo_stroke_extents (cairo_t *cr, double *x1, double *y1, double *x2, double *y2); 1216 cairo_stroke_extents(cairo, &x1, &y1, &x2, &y2); 1217 } 1218 1219 /** 1220 * Tests whether the given point is inside the area that would be 1221 * affected by a cairo_stroke() operation given the current path and 1222 * stroking parameters. Surface dimensions and clipping are not taken 1223 * into account. 1224 * See cairo_stroke(), cairo_set_line_width(), cairo_set_line_join(), 1225 * cairo_set_line_cap(), cairo_set_dash(), and 1226 * cairo_stroke_preserve(). 1227 * Since 1.0 1228 * Params: 1229 * x = X coordinate of the point to test 1230 * y = Y coordinate of the point to test 1231 * Returns: A non-zero value if the point is inside, or zero if outside. 1232 */ 1233 public cairo_bool_t inStroke(double x, double y) 1234 { 1235 // cairo_bool_t cairo_in_stroke (cairo_t *cr, double x, double y); 1236 return cairo_in_stroke(cairo, x, y); 1237 } 1238 1239 /** 1240 * Emits the current page for backends that support multiple pages, but 1241 * doesn't clear it, so, the contents of the current page will be retained 1242 * for the next page too. Use cairo_show_page() if you want to get an 1243 * empty page after the emission. 1244 * This is a convenience function that simply calls 1245 * cairo_surface_copy_page() on cr's target. 1246 * Since 1.0 1247 */ 1248 public void copyPage() 1249 { 1250 // void cairo_copy_page (cairo_t *cr); 1251 cairo_copy_page(cairo); 1252 } 1253 1254 /** 1255 * Emits and clears the current page for backends that support multiple 1256 * pages. Use cairo_copy_page() if you don't want to clear the page. 1257 * This is a convenience function that simply calls 1258 * cairo_surface_show_page() on cr's target. 1259 * Since 1.0 1260 */ 1261 public void showPage() 1262 { 1263 // void cairo_show_page (cairo_t *cr); 1264 cairo_show_page(cairo); 1265 } 1266 1267 /** 1268 * Returns the current reference count of cr. 1269 * Since 1.4 1270 * Returns: the current reference count of cr. If the object is a nil object, 0 will be returned. 1271 */ 1272 public uint getReferenceCount() 1273 { 1274 // unsigned int cairo_get_reference_count (cairo_t *cr); 1275 return cairo_get_reference_count(cairo); 1276 } 1277 1278 /** 1279 * Attach user data to cr. To remove user data from a surface, 1280 * call this function with the key that was used to set it and NULL 1281 * for data. 1282 * Since 1.4 1283 * Params: 1284 * key = the address of a cairo_user_data_key_t to attach the user data to 1285 * userData = the user data to attach to the cairo_t 1286 * destroy = a cairo_destroy_func_t which will be called when the 1287 * cairo_t is destroyed or when new user data is attached using the 1288 * same key. 1289 * Returns: CAIRO_STATUS_SUCCESS or CAIRO_STATUS_NO_MEMORY if a slot could not be allocated for the user data. 1290 */ 1291 public cairo_status_t setUserData(cairo_user_data_key_t* key, void* userData, cairo_destroy_func_t destroy) 1292 { 1293 // cairo_status_t cairo_set_user_data (cairo_t *cr, const cairo_user_data_key_t *key, void *user_data, cairo_destroy_func_t destroy); 1294 return cairo_set_user_data(cairo, key, userData, destroy); 1295 } 1296 1297 /** 1298 * Return user data previously attached to cr using the specified 1299 * key. If no user data has been attached with the given key this 1300 * function returns NULL. 1301 * Since 1.4 1302 * Params: 1303 * key = the address of the cairo_user_data_key_t the user data was 1304 * attached to 1305 * Returns: the user data previously attached or NULL. 1306 */ 1307 public void* getUserData(cairo_user_data_key_t* key) 1308 { 1309 // void * cairo_get_user_data (cairo_t *cr, const cairo_user_data_key_t *key); 1310 return cairo_get_user_data(cairo, key); 1311 } 1312 1313 /** 1314 * Creates a copy of the current path and returns it to the user as a 1315 * cairo_path_t. See cairo_path_data_t for hints on how to iterate 1316 * over the returned data structure. 1317 * This function will always return a valid pointer, but the result 1318 * will have no data (data==NULL and 1319 * num_data==0), if either of the following 1320 * Since 1.0 1321 * Returns: the copy of the current path. The caller owns the returned object and should call cairo_path_destroy() when finished with it. 1322 */ 1323 public cairo_path_t* copyPath() 1324 { 1325 // cairo_path_t * cairo_copy_path (cairo_t *cr); 1326 return cairo_copy_path(cairo); 1327 } 1328 1329 /** 1330 * Gets a flattened copy of the current path and returns it to the 1331 * user as a cairo_path_t. See cairo_path_data_t for hints on 1332 * how to iterate over the returned data structure. 1333 * This function is like cairo_copy_path() except that any curves 1334 * in the path will be approximated with piecewise-linear 1335 * approximations, (accurate to within the current tolerance 1336 * value). That is, the result is guaranteed to not have any elements 1337 * of type CAIRO_PATH_CURVE_TO which will instead be replaced by a 1338 * series of CAIRO_PATH_LINE_TO elements. 1339 * This function will always return a valid pointer, but the result 1340 * will have no data (data==NULL and 1341 * num_data==0), if either of the following 1342 * Since 1.0 1343 * Returns: the copy of the current path. The caller owns the returned object and should call cairo_path_destroy() when finished with it. 1344 */ 1345 public cairo_path_t* copyPathFlat() 1346 { 1347 // cairo_path_t * cairo_copy_path_flat (cairo_t *cr); 1348 return cairo_copy_path_flat(cairo); 1349 } 1350 1351 /** 1352 * Immediately releases all memory associated with path. After a call 1353 * to cairo_path_destroy() the path pointer is no longer valid and 1354 * should not be used further. 1355 * Note: cairo_path_destroy() should only be called with a 1356 * pointer to a cairo_path_t returned by a cairo function. Any path 1357 * that is created manually (ie. outside of cairo) should be destroyed 1358 * manually as well. 1359 * Since 1.0 1360 * Params: 1361 * path = a path previously returned by either cairo_copy_path() or 1362 * cairo_copy_path_flat(). 1363 */ 1364 public static void pathDestroy(cairo_path_t* path) 1365 { 1366 // void cairo_path_destroy (cairo_path_t *path); 1367 cairo_path_destroy(path); 1368 } 1369 1370 /** 1371 * Append the path onto the current path. The path may be either the 1372 * return value from one of cairo_copy_path() or 1373 * cairo_copy_path_flat() or it may be constructed manually. See 1374 * cairo_path_t for details on how the path data structure should be 1375 * initialized, and note that path->status must be 1376 * initialized to CAIRO_STATUS_SUCCESS. 1377 * Since 1.0 1378 * Params: 1379 * path = path to be appended 1380 */ 1381 public void appendPath(cairo_path_t* path) 1382 { 1383 // void cairo_append_path (cairo_t *cr, const cairo_path_t *path); 1384 cairo_append_path(cairo, path); 1385 } 1386 1387 /** 1388 * Returns whether a current point is defined on the current path. 1389 * See cairo_get_current_point() for details on the current point. 1390 * Since 1.6 1391 * Returns: whether a current point is defined. 1392 */ 1393 public cairo_bool_t hasCurrentPoint() 1394 { 1395 // cairo_bool_t cairo_has_current_point (cairo_t *cr); 1396 return cairo_has_current_point(cairo); 1397 } 1398 1399 /** 1400 * Gets the current point of the current path, which is 1401 * conceptually the final point reached by the path so far. 1402 * The current point is returned in the user-space coordinate 1403 * system. If there is no defined current point or if cr is in an 1404 * error status, x and y will both be set to 0.0. It is possible to 1405 * check this in advance with cairo_has_current_point(). 1406 * Most path construction functions alter the current point. See the 1407 * Since 1.0 1408 * Params: 1409 * x = return value for X coordinate of the current point 1410 * y = return value for Y coordinate of the current point 1411 */ 1412 public void getCurrentPoint(out double x, out double y) 1413 { 1414 // void cairo_get_current_point (cairo_t *cr, double *x, double *y); 1415 cairo_get_current_point(cairo, &x, &y); 1416 } 1417 1418 /** 1419 * Clears the current path. After this call there will be no path and 1420 * no current point. 1421 * Since 1.0 1422 */ 1423 public void newPath() 1424 { 1425 // void cairo_new_path (cairo_t *cr); 1426 cairo_new_path(cairo); 1427 } 1428 1429 /** 1430 * Begin a new sub-path. Note that the existing path is not 1431 * affected. After this call there will be no current point. 1432 * In many cases, this call is not needed since new sub-paths are 1433 * frequently started with cairo_move_to(). 1434 * A call to cairo_new_sub_path() is particularly useful when 1435 * beginning a new sub-path with one of the cairo_arc() calls. This 1436 * makes things easier as it is no longer necessary to manually 1437 * compute the arc's initial coordinates for a call to 1438 * cairo_move_to(). 1439 * Since 1.2 1440 */ 1441 public void newSubPath() 1442 { 1443 // void cairo_new_sub_path (cairo_t *cr); 1444 cairo_new_sub_path(cairo); 1445 } 1446 1447 /** 1448 * Adds a line segment to the path from the current point to the 1449 * beginning of the current sub-path, (the most recent point passed to 1450 * cairo_move_to()), and closes this sub-path. After this call the 1451 * current point will be at the joined endpoint of the sub-path. 1452 * The behavior of cairo_close_path() is distinct from simply calling 1453 * cairo_line_to() with the equivalent coordinate in the case of 1454 * stroking. When a closed sub-path is stroked, there are no caps on 1455 * the ends of the sub-path. Instead, there is a line join connecting 1456 * the final and initial segments of the sub-path. 1457 * If there is no current point before the call to cairo_close_path(), 1458 * this function will have no effect. 1459 * Note: As of cairo version 1.2.4 any call to cairo_close_path() will 1460 * place an explicit MOVE_TO element into the path immediately after 1461 * the CLOSE_PATH element, (which can be seen in cairo_copy_path() for 1462 * example). This can simplify path processing in some cases as it may 1463 * not be necessary to save the "last move_to point" during processing 1464 * as the MOVE_TO immediately after the CLOSE_PATH will provide that 1465 * point. 1466 * Since 1.0 1467 */ 1468 public void closePath() 1469 { 1470 // void cairo_close_path (cairo_t *cr); 1471 cairo_close_path(cairo); 1472 } 1473 1474 /** 1475 * Adds a circular arc of the given radius to the current path. The 1476 * arc is centered at (xc, yc), begins at angle1 and proceeds in 1477 * the direction of increasing angles to end at angle2. If angle2 is 1478 * less than angle1 it will be progressively increased by 1479 * 2*M_PI until it is greater than angle1. 1480 * If there is a current point, an initial line segment will be added 1481 * to the path to connect the current point to the beginning of the 1482 * arc. If this initial line is undesired, it can be avoided by 1483 * calling cairo_new_sub_path() before calling cairo_arc(). 1484 * Angles are measured in radians. An angle of 0.0 is in the direction 1485 * of the positive X axis (in user space). An angle of 1486 * M_PI/2.0 radians (90 degrees) is in the 1487 * direction of the positive Y axis (in user space). Angles increase 1488 * in the direction from the positive X axis toward the positive Y 1489 * axis. So with the default transformation matrix, angles increase in 1490 * a clockwise direction. 1491 * (To convert from degrees to radians, use degrees * (M_PI / 1492 * 180.).) 1493 * This function gives the arc in the direction of increasing angles; 1494 * see cairo_arc_negative() to get the arc in the direction of 1495 * decreasing angles. 1496 * The arc is circular in user space. To achieve an elliptical arc, 1497 * you can scale the current transformation matrix by different 1498 * amounts in the X and Y directions. For example, to draw an ellipse 1499 * Since 1.0 1500 * Params: 1501 * xc = X position of the center of the arc 1502 * yc = Y position of the center of the arc 1503 * radius = the radius of the arc 1504 * angle1 = the start angle, in radians 1505 * angle2 = the end angle, in radians 1506 */ 1507 public void arc(double xc, double yc, double radius, double angle1, double angle2) 1508 { 1509 // void cairo_arc (cairo_t *cr, double xc, double yc, double radius, double angle1, double angle2); 1510 cairo_arc(cairo, xc, yc, radius, angle1, angle2); 1511 } 1512 1513 /** 1514 * Adds a circular arc of the given radius to the current path. The 1515 * arc is centered at (xc, yc), begins at angle1 and proceeds in 1516 * the direction of decreasing angles to end at angle2. If angle2 is 1517 * greater than angle1 it will be progressively decreased by 1518 * 2*M_PI until it is less than angle1. 1519 * See cairo_arc() for more details. This function differs only in the 1520 * direction of the arc between the two angles. 1521 * Since 1.0 1522 * Params: 1523 * xc = X position of the center of the arc 1524 * yc = Y position of the center of the arc 1525 * radius = the radius of the arc 1526 * angle1 = the start angle, in radians 1527 * angle2 = the end angle, in radians 1528 */ 1529 public void arcNegative(double xc, double yc, double radius, double angle1, double angle2) 1530 { 1531 // void cairo_arc_negative (cairo_t *cr, double xc, double yc, double radius, double angle1, double angle2); 1532 cairo_arc_negative(cairo, xc, yc, radius, angle1, angle2); 1533 } 1534 1535 /** 1536 * Adds a cubic Bézier spline to the path from the current point to 1537 * position (x3, y3) in user-space coordinates, using (x1, y1) and 1538 * (x2, y2) as the control points. After this call the current point 1539 * will be (x3, y3). 1540 * If there is no current point before the call to cairo_curve_to() 1541 * this function will behave as if preceded by a call to 1542 * cairo_move_to(cr, x1, y1). 1543 * Since 1.0 1544 * Params: 1545 * x1 = the X coordinate of the first control point 1546 * y1 = the Y coordinate of the first control point 1547 * x2 = the X coordinate of the second control point 1548 * y2 = the Y coordinate of the second control point 1549 * x3 = the X coordinate of the end of the curve 1550 * y3 = the Y coordinate of the end of the curve 1551 */ 1552 public void curveTo(double x1, double y1, double x2, double y2, double x3, double y3) 1553 { 1554 // void cairo_curve_to (cairo_t *cr, double x1, double y1, double x2, double y2, double x3, double y3); 1555 cairo_curve_to(cairo, x1, y1, x2, y2, x3, y3); 1556 } 1557 1558 /** 1559 * Adds a line to the path from the current point to position (x, y) 1560 * in user-space coordinates. After this call the current point 1561 * will be (x, y). 1562 * If there is no current point before the call to cairo_line_to() 1563 * this function will behave as cairo_move_to(cr, x, y). 1564 * Since 1.0 1565 * Params: 1566 * x = the X coordinate of the end of the new line 1567 * y = the Y coordinate of the end of the new line 1568 */ 1569 public void lineTo(double x, double y) 1570 { 1571 // void cairo_line_to (cairo_t *cr, double x, double y); 1572 cairo_line_to(cairo, x, y); 1573 } 1574 1575 /** 1576 * Begin a new sub-path. After this call the current point will be (x, 1577 * y). 1578 * Since 1.0 1579 * Params: 1580 * x = the X coordinate of the new position 1581 * y = the Y coordinate of the new position 1582 */ 1583 public void moveTo(double x, double y) 1584 { 1585 // void cairo_move_to (cairo_t *cr, double x, double y); 1586 cairo_move_to(cairo, x, y); 1587 } 1588 1589 /** 1590 * Adds a closed sub-path rectangle of the given size to the current 1591 * path at position (x, y) in user-space coordinates. 1592 * Since 1.0 1593 * Params: 1594 * x = the X coordinate of the top left corner of the rectangle 1595 * y = the Y coordinate to the top left corner of the rectangle 1596 * width = the width of the rectangle 1597 * height = the height of the rectangle 1598 */ 1599 public void rectangle(double x, double y, double width, double height) 1600 { 1601 // void cairo_rectangle (cairo_t *cr, double x, double y, double width, double height); 1602 cairo_rectangle(cairo, x, y, width, height); 1603 } 1604 1605 /** 1606 * Adds closed paths for the glyphs to the current path. The generated 1607 * path if filled, achieves an effect similar to that of 1608 * cairo_show_glyphs(). 1609 * Since 1.0 1610 * Params: 1611 * glyphs = array of glyphs to show 1612 * numGlyphs = number of glyphs to show 1613 */ 1614 public void glyphPath(cairo_glyph_t* glyphs, int numGlyphs) 1615 { 1616 // void cairo_glyph_path (cairo_t *cr, const cairo_glyph_t *glyphs, int num_glyphs); 1617 cairo_glyph_path(cairo, glyphs, numGlyphs); 1618 } 1619 1620 /** 1621 * Adds closed paths for text to the current path. The generated 1622 * path if filled, achieves an effect similar to that of 1623 * cairo_show_text(). 1624 * Text conversion and positioning is done similar to cairo_show_text(). 1625 * Like cairo_show_text(), After this call the current point is 1626 * moved to the origin of where the next glyph would be placed in 1627 * this same progression. That is, the current point will be at 1628 * the origin of the final glyph offset by its advance values. 1629 * This allows for chaining multiple calls to to cairo_text_path() 1630 * without having to set current point in between. 1631 * Note: The cairo_text_path() function call is part of what the cairo 1632 * designers call the "toy" text API. It is convenient for short demos 1633 * and simple programs, but it is not expected to be adequate for 1634 * serious text-using applications. See cairo_glyph_path() for the 1635 * "real" text path API in cairo. 1636 * Since 1.0 1637 * Params: 1638 * utf8 = a NUL-terminated string of text encoded in UTF-8, or NULL 1639 */ 1640 public void textPath(string utf8) 1641 { 1642 // void cairo_text_path (cairo_t *cr, const char *utf8); 1643 cairo_text_path(cairo, Str.toStringz(utf8)); 1644 } 1645 1646 /** 1647 * Relative-coordinate version of cairo_curve_to(). All offsets are 1648 * relative to the current point. Adds a cubic Bézier spline to the 1649 * path from the current point to a point offset from the current 1650 * point by (dx3, dy3), using points offset by (dx1, dy1) and 1651 * (dx2, dy2) as the control points. After this call the current 1652 * point will be offset by (dx3, dy3). 1653 * Given a current point of (x, y), cairo_rel_curve_to(cr, dx1, 1654 * dy1, dx2, dy2, dx3, dy3) is logically equivalent to 1655 * cairo_curve_to(cr, x+dx1, y+dy1, x+dx2, y+dy2, x+dx3, y+dy3). 1656 * It is an error to call this function with no current point. Doing 1657 * so will cause cr to shutdown with a status of 1658 * CAIRO_STATUS_NO_CURRENT_POINT. 1659 * Since 1.0 1660 * Params: 1661 * dx1 = the X offset to the first control point 1662 * dy1 = the Y offset to the first control point 1663 * dx2 = the X offset to the second control point 1664 * dy2 = the Y offset to the second control point 1665 * dx3 = the X offset to the end of the curve 1666 * dy3 = the Y offset to the end of the curve 1667 */ 1668 public void relCurveTo(double dx1, double dy1, double dx2, double dy2, double dx3, double dy3) 1669 { 1670 // void cairo_rel_curve_to (cairo_t *cr, double dx1, double dy1, double dx2, double dy2, double dx3, double dy3); 1671 cairo_rel_curve_to(cairo, dx1, dy1, dx2, dy2, dx3, dy3); 1672 } 1673 1674 /** 1675 * Relative-coordinate version of cairo_line_to(). Adds a line to the 1676 * path from the current point to a point that is offset from the 1677 * current point by (dx, dy) in user space. After this call the 1678 * current point will be offset by (dx, dy). 1679 * Given a current point of (x, y), cairo_rel_line_to(cr, dx, dy) 1680 * is logically equivalent to cairo_line_to(cr, x + dx, y + dy). 1681 * It is an error to call this function with no current point. Doing 1682 * so will cause cr to shutdown with a status of 1683 * CAIRO_STATUS_NO_CURRENT_POINT. 1684 * Since 1.0 1685 * Params: 1686 * dx = the X offset to the end of the new line 1687 * dy = the Y offset to the end of the new line 1688 */ 1689 public void relLineTo(double dx, double dy) 1690 { 1691 // void cairo_rel_line_to (cairo_t *cr, double dx, double dy); 1692 cairo_rel_line_to(cairo, dx, dy); 1693 } 1694 1695 /** 1696 * Begin a new sub-path. After this call the current point will offset 1697 * by (x, y). 1698 * Given a current point of (x, y), cairo_rel_move_to(cr, dx, dy) 1699 * is logically equivalent to cairo_move_to(cr, x + dx, y + dy). 1700 * It is an error to call this function with no current point. Doing 1701 * so will cause cr to shutdown with a status of 1702 * CAIRO_STATUS_NO_CURRENT_POINT. 1703 * Since 1.0 1704 * Params: 1705 * dx = the X offset 1706 * dy = the Y offset 1707 */ 1708 public void relMoveTo(double dx, double dy) 1709 { 1710 // void cairo_rel_move_to (cairo_t *cr, double dx, double dy); 1711 cairo_rel_move_to(cairo, dx, dy); 1712 } 1713 1714 /** 1715 * Computes a bounding box in user-space coordinates covering the 1716 * points on the current path. If the current path is empty, returns 1717 * an empty rectangle ((0,0), (0,0)). Stroke parameters, fill rule, 1718 * surface dimensions and clipping are not taken into account. 1719 * Contrast with cairo_fill_extents() and cairo_stroke_extents() which 1720 * return the extents of only the area that would be "inked" by 1721 * the corresponding drawing operations. 1722 * The result of cairo_path_extents() is defined as equivalent to the 1723 * limit of cairo_stroke_extents() with CAIRO_LINE_CAP_ROUND as the 1724 * line width approaches 0.0, (but never reaching the empty-rectangle 1725 * returned by cairo_stroke_extents() for a line width of 0.0). 1726 * Specifically, this means that zero-area sub-paths such as 1727 * cairo_move_to();cairo_line_to() segments, (even degenerate cases 1728 * where the coordinates to both calls are identical), will be 1729 * considered as contributing to the extents. However, a lone 1730 * cairo_move_to() will not contribute to the results of 1731 * cairo_path_extents(). 1732 * Since 1.6 1733 * Params: 1734 * x1 = left of the resulting extents 1735 * y1 = top of the resulting extents 1736 * x2 = right of the resulting extents 1737 * y2 = bottom of the resulting extents 1738 */ 1739 public void pathExtents(out double x1, out double y1, out double x2, out double y2) 1740 { 1741 // void cairo_path_extents (cairo_t *cr, double *x1, double *y1, double *x2, double *y2); 1742 cairo_path_extents(cairo, &x1, &y1, &x2, &y2); 1743 } 1744 1745 /** 1746 * Modifies the current transformation matrix (CTM) by translating the 1747 * user-space origin by (tx, ty). This offset is interpreted as a 1748 * user-space coordinate according to the CTM in place before the new 1749 * call to cairo_translate(). In other words, the translation of the 1750 * user-space origin takes place after any existing transformation. 1751 * Since 1.0 1752 * Params: 1753 * tx = amount to translate in the X direction 1754 * ty = amount to translate in the Y direction 1755 */ 1756 public void translate(double tx, double ty) 1757 { 1758 // void cairo_translate (cairo_t *cr, double tx, double ty); 1759 cairo_translate(cairo, tx, ty); 1760 } 1761 1762 /** 1763 * Modifies the current transformation matrix (CTM) by scaling the X 1764 * and Y user-space axes by sx and sy respectively. The scaling of 1765 * the axes takes place after any existing transformation of user 1766 * space. 1767 * Since 1.0 1768 * Params: 1769 * sx = scale factor for the X dimension 1770 * sy = scale factor for the Y dimension 1771 */ 1772 public void scale(double sx, double sy) 1773 { 1774 // void cairo_scale (cairo_t *cr, double sx, double sy); 1775 cairo_scale(cairo, sx, sy); 1776 } 1777 1778 /** 1779 * Modifies the current transformation matrix (CTM) by rotating the 1780 * user-space axes by angle radians. The rotation of the axes takes 1781 * places after any existing transformation of user space. The 1782 * rotation direction for positive angles is from the positive X axis 1783 * toward the positive Y axis. 1784 * Since 1.0 1785 * Params: 1786 * angle = angle (in radians) by which the user-space axes will be 1787 * rotated 1788 */ 1789 public void rotate(double angle) 1790 { 1791 // void cairo_rotate (cairo_t *cr, double angle); 1792 cairo_rotate(cairo, angle); 1793 } 1794 1795 /** 1796 * Modifies the current transformation matrix (CTM) by applying 1797 * matrix as an additional transformation. The new transformation of 1798 * user space takes place after any existing transformation. 1799 * Since 1.0 1800 * Params: 1801 * matrix = a transformation to be applied to the user-space axes 1802 */ 1803 public void transform(Matrix matrix) 1804 { 1805 // void cairo_transform (cairo_t *cr, const cairo_matrix_t *matrix); 1806 cairo_transform(cairo, (matrix is null) ? null : matrix.getMatrixStruct()); 1807 } 1808 1809 /** 1810 * Modifies the current transformation matrix (CTM) by setting it 1811 * equal to matrix. 1812 * Since 1.0 1813 * Params: 1814 * matrix = a transformation matrix from user space to device space 1815 */ 1816 public void setMatrix(Matrix matrix) 1817 { 1818 // void cairo_set_matrix (cairo_t *cr, const cairo_matrix_t *matrix); 1819 cairo_set_matrix(cairo, (matrix is null) ? null : matrix.getMatrixStruct()); 1820 } 1821 1822 /** 1823 * Stores the current transformation matrix (CTM) into matrix. 1824 * Since 1.0 1825 * Params: 1826 * matrix = return value for the matrix 1827 */ 1828 public void getMatrix(Matrix matrix) 1829 { 1830 // void cairo_get_matrix (cairo_t *cr, cairo_matrix_t *matrix); 1831 cairo_get_matrix(cairo, (matrix is null) ? null : matrix.getMatrixStruct()); 1832 } 1833 1834 /** 1835 * Resets the current transformation matrix (CTM) by setting it equal 1836 * to the identity matrix. That is, the user-space and device-space 1837 * axes will be aligned and one user-space unit will transform to one 1838 * device-space unit. 1839 * Since 1.0 1840 */ 1841 public void identityMatrix() 1842 { 1843 // void cairo_identity_matrix (cairo_t *cr); 1844 cairo_identity_matrix(cairo); 1845 } 1846 1847 /** 1848 * Transform a coordinate from user space to device space by 1849 * multiplying the given point by the current transformation matrix 1850 * (CTM). 1851 * Since 1.0 1852 * Params: 1853 * x = X value of coordinate (in/out parameter) 1854 * y = Y value of coordinate (in/out parameter) 1855 */ 1856 public void userToDevice(ref double x, ref double y) 1857 { 1858 // void cairo_user_to_device (cairo_t *cr, double *x, double *y); 1859 cairo_user_to_device(cairo, &x, &y); 1860 } 1861 1862 /** 1863 * Transform a distance vector from user space to device space. This 1864 * function is similar to cairo_user_to_device() except that the 1865 * translation components of the CTM will be ignored when transforming 1866 * (dx,dy). 1867 * Since 1.0 1868 * Params: 1869 * dx = X component of a distance vector (in/out parameter) 1870 * dy = Y component of a distance vector (in/out parameter) 1871 */ 1872 public void userToDeviceDistance(ref double dx, ref double dy) 1873 { 1874 // void cairo_user_to_device_distance (cairo_t *cr, double *dx, double *dy); 1875 cairo_user_to_device_distance(cairo, &dx, &dy); 1876 } 1877 1878 /** 1879 * Transform a coordinate from device space to user space by 1880 * multiplying the given point by the inverse of the current 1881 * transformation matrix (CTM). 1882 * Since 1.0 1883 * Params: 1884 * x = X value of coordinate (in/out parameter) 1885 * y = Y value of coordinate (in/out parameter) 1886 */ 1887 public void deviceToUser(ref double x, ref double y) 1888 { 1889 // void cairo_device_to_user (cairo_t *cr, double *x, double *y); 1890 cairo_device_to_user(cairo, &x, &y); 1891 } 1892 1893 /** 1894 * Transform a distance vector from device space to user space. This 1895 * function is similar to cairo_device_to_user() except that the 1896 * translation components of the inverse CTM will be ignored when 1897 * transforming (dx,dy). 1898 * Since 1.0 1899 * Params: 1900 * dx = X component of a distance vector (in/out parameter) 1901 * dy = Y component of a distance vector (in/out parameter) 1902 */ 1903 public void deviceToUserDistance(ref double dx, ref double dy) 1904 { 1905 // void cairo_device_to_user_distance (cairo_t *cr, double *dx, double *dy); 1906 cairo_device_to_user_distance(cairo, &dx, &dy); 1907 } 1908 1909 /** 1910 * Note: The cairo_select_font_face() function call is part of what 1911 * the cairo designers call the "toy" text API. It is convenient for 1912 * short demos and simple programs, but it is not expected to be 1913 * adequate for serious text-using applications. 1914 * Selects a family and style of font from a simplified description as 1915 * a family name, slant and weight. Cairo provides no operation to 1916 * list available family names on the system (this is a "toy", 1917 * remember), but the standard CSS2 generic family names, ("serif", 1918 * "sans-serif", "cursive", "fantasy", "monospace"), are likely to 1919 * work as expected. 1920 * If family starts with the string "cairo:", or if no native font 1921 * backends are compiled in, cairo will use an internal font family. 1922 * The internal font family recognizes many modifiers in the family 1923 * string, most notably, it recognizes the string "monospace". That is, 1924 * the family name "cairo:monospace" will use the monospace version of 1925 * the internal font family. 1926 * For "real" font selection, see the font-backend-specific 1927 * font_face_create functions for the font backend you are using. (For 1928 * example, if you are using the freetype-based cairo-ft font backend, 1929 * see cairo_ft_font_face_create_for_ft_face() or 1930 * cairo_ft_font_face_create_for_pattern().) The resulting font face 1931 * could then be used with cairo_scaled_font_create() and 1932 * cairo_set_scaled_font(). 1933 * Similarly, when using the "real" font support, you can call 1934 * directly into the underlying font system, (such as fontconfig or 1935 * freetype), for operations such as listing available fonts, etc. 1936 * It is expected that most applications will need to use a more 1937 * comprehensive font handling and text layout library, (for example, 1938 * pango), in conjunction with cairo. 1939 * If text is drawn without a call to cairo_select_font_face(), (nor 1940 * cairo_set_font_face() nor cairo_set_scaled_font()), the default 1941 * family is platform-specific, but is essentially "sans-serif". 1942 * Default slant is CAIRO_FONT_SLANT_NORMAL, and default weight is 1943 * CAIRO_FONT_WEIGHT_NORMAL. 1944 * This function is equivalent to a call to cairo_toy_font_face_create() 1945 * followed by cairo_set_font_face(). 1946 * Since 1.0 1947 * Params: 1948 * family = a font family name, encoded in UTF-8 1949 * slant = the slant for the font 1950 * weight = the weight for the font 1951 */ 1952 public void selectFontFace(string family, cairo_font_slant_t slant, cairo_font_weight_t weight) 1953 { 1954 // void cairo_select_font_face (cairo_t *cr, const char *family, cairo_font_slant_t slant, cairo_font_weight_t weight); 1955 cairo_select_font_face(cairo, Str.toStringz(family), slant, weight); 1956 } 1957 1958 /** 1959 * Sets the current font matrix to a scale by a factor of size, replacing 1960 * any font matrix previously set with cairo_set_font_size() or 1961 * cairo_set_font_matrix(). This results in a font size of size user space 1962 * units. (More precisely, this matrix will result in the font's 1963 * em-square being a size by size square in user space.) 1964 * If text is drawn without a call to cairo_set_font_size(), (nor 1965 * cairo_set_font_matrix() nor cairo_set_scaled_font()), the default 1966 * font size is 10.0. 1967 * Since 1.0 1968 * Params: 1969 * size = the new font size, in user space units 1970 */ 1971 public void setFontSize(double size) 1972 { 1973 // void cairo_set_font_size (cairo_t *cr, double size); 1974 cairo_set_font_size(cairo, size); 1975 } 1976 1977 /** 1978 * Sets the current font matrix to matrix. The font matrix gives a 1979 * transformation from the design space of the font (in this space, 1980 * the em-square is 1 unit by 1 unit) to user space. Normally, a 1981 * simple scale is used (see cairo_set_font_size()), but a more 1982 * complex font matrix can be used to shear the font 1983 * or stretch it unequally along the two axes 1984 * Since 1.0 1985 * Params: 1986 * matrix = a cairo_matrix_t describing a transform to be applied to 1987 * the current font. 1988 */ 1989 public void setFontMatrix(Matrix matrix) 1990 { 1991 // void cairo_set_font_matrix (cairo_t *cr, const cairo_matrix_t *matrix); 1992 cairo_set_font_matrix(cairo, (matrix is null) ? null : matrix.getMatrixStruct()); 1993 } 1994 1995 /** 1996 * Stores the current font matrix into matrix. See 1997 * cairo_set_font_matrix(). 1998 * Since 1.0 1999 * Params: 2000 * matrix = return value for the matrix 2001 */ 2002 public void getFontMatrix(Matrix matrix) 2003 { 2004 // void cairo_get_font_matrix (cairo_t *cr, cairo_matrix_t *matrix); 2005 cairo_get_font_matrix(cairo, (matrix is null) ? null : matrix.getMatrixStruct()); 2006 } 2007 2008 /** 2009 * Sets a set of custom font rendering options for the cairo_t. 2010 * Rendering options are derived by merging these options with the 2011 * options derived from underlying surface; if the value in options 2012 * has a default value (like CAIRO_ANTIALIAS_DEFAULT), then the value 2013 * from the surface is used. 2014 * Since 1.0 2015 * Params: 2016 * options = font options to use 2017 */ 2018 public void setFontOptions(FontOption options) 2019 { 2020 // void cairo_set_font_options (cairo_t *cr, const cairo_font_options_t *options); 2021 cairo_set_font_options(cairo, (options is null) ? null : options.getFontOptionStruct()); 2022 } 2023 2024 /** 2025 * Retrieves font rendering options set via cairo_set_font_options. 2026 * Note that the returned options do not include any options derived 2027 * from the underlying surface; they are literally the options 2028 * passed to cairo_set_font_options(). 2029 * Since 1.0 2030 * Params: 2031 * options = a cairo_font_options_t object into which to store 2032 * the retrieved options. All existing values are overwritten 2033 */ 2034 public void getFontOptions(FontOption options) 2035 { 2036 // void cairo_get_font_options (cairo_t *cr, cairo_font_options_t *options); 2037 cairo_get_font_options(cairo, (options is null) ? null : options.getFontOptionStruct()); 2038 } 2039 2040 /** 2041 * Replaces the current cairo_font_face_t object in the cairo_t with 2042 * font_face. The replaced font face in the cairo_t will be 2043 * destroyed if there are no other references to it. 2044 * Since 1.0 2045 * Params: 2046 * fontFace = a cairo_font_face_t, or NULL to restore to the default font 2047 */ 2048 public void setFontFace(FontFace fontFace) 2049 { 2050 // void cairo_set_font_face (cairo_t *cr, cairo_font_face_t *font_face); 2051 cairo_set_font_face(cairo, (fontFace is null) ? null : fontFace.getFontFaceStruct()); 2052 } 2053 2054 /** 2055 * Gets the current font face for a cairo_t. 2056 * Since 1.0 2057 * Returns: the current font face. This object is owned by cairo. To keep a reference to it, you must call cairo_font_face_reference(). This function never returns NULL. If memory cannot be allocated, a special "nil" cairo_font_face_t object will be returned on which cairo_font_face_status() returns CAIRO_STATUS_NO_MEMORY. Using this nil object will cause its error state to propagate to other objects it is passed to, (for example, calling cairo_set_font_face() with a nil font will trigger an error that will shutdown the cairo_t object). 2058 */ 2059 public FontFace getFontFace() 2060 { 2061 // cairo_font_face_t * cairo_get_font_face (cairo_t *cr); 2062 auto p = cairo_get_font_face(cairo); 2063 2064 if(p is null) 2065 { 2066 return null; 2067 } 2068 2069 return new FontFace(cast(cairo_font_face_t*) p); 2070 } 2071 2072 /** 2073 * Replaces the current font face, font matrix, and font options in 2074 * the cairo_t with those of the cairo_scaled_font_t. Except for 2075 * some translation, the current CTM of the cairo_t should be the 2076 * same as that of the cairo_scaled_font_t, which can be accessed 2077 * using cairo_scaled_font_get_ctm(). 2078 * Since 1.2 2079 * Params: 2080 * scaledFont = a cairo_scaled_font_t 2081 */ 2082 public void setScaledFont(ScaledFont scaledFont) 2083 { 2084 // void cairo_set_scaled_font (cairo_t *cr, const cairo_scaled_font_t *scaled_font); 2085 cairo_set_scaled_font(cairo, (scaledFont is null) ? null : scaledFont.getScaledFontStruct()); 2086 } 2087 2088 /** 2089 * Gets the current scaled font for a cairo_t. 2090 * Since 1.4 2091 * Returns: the current scaled font. This object is owned by cairo. To keep a reference to it, you must call cairo_scaled_font_reference(). This function never returns NULL. If memory cannot be allocated, a special "nil" cairo_scaled_font_t object will be returned on which cairo_scaled_font_status() returns CAIRO_STATUS_NO_MEMORY. Using this nil object will cause its error state to propagate to other objects it is passed to, (for example, calling cairo_set_scaled_font() with a nil font will trigger an error that will shutdown the cairo_t object). 2092 */ 2093 public ScaledFont getScaledFont() 2094 { 2095 // cairo_scaled_font_t * cairo_get_scaled_font (cairo_t *cr); 2096 auto p = cairo_get_scaled_font(cairo); 2097 2098 if(p is null) 2099 { 2100 return null; 2101 } 2102 2103 return new ScaledFont(cast(cairo_scaled_font_t*) p); 2104 } 2105 2106 /** 2107 * A drawing operator that generates the shape from a string of UTF-8 2108 * characters, rendered according to the current font_face, font_size 2109 * (font_matrix), and font_options. 2110 * This function first computes a set of glyphs for the string of 2111 * text. The first glyph is placed so that its origin is at the 2112 * current point. The origin of each subsequent glyph is offset from 2113 * that of the previous glyph by the advance values of the previous 2114 * glyph. 2115 * After this call the current point is moved to the origin of where 2116 * the next glyph would be placed in this same progression. That is, 2117 * the current point will be at the origin of the final glyph offset 2118 * by its advance values. This allows for easy display of a single 2119 * logical string with multiple calls to cairo_show_text(). 2120 * Note: The cairo_show_text() function call is part of what the cairo 2121 * designers call the "toy" text API. It is convenient for short demos 2122 * and simple programs, but it is not expected to be adequate for 2123 * serious text-using applications. See cairo_show_glyphs() for the 2124 * "real" text display API in cairo. 2125 * Since 1.0 2126 * Params: 2127 * utf8 = a NUL-terminated string of text encoded in UTF-8, or NULL 2128 */ 2129 public void showText(string utf8) 2130 { 2131 // void cairo_show_text (cairo_t *cr, const char *utf8); 2132 cairo_show_text(cairo, Str.toStringz(utf8)); 2133 } 2134 2135 /** 2136 * A drawing operator that generates the shape from an array of glyphs, 2137 * rendered according to the current font face, font size 2138 * (font matrix), and font options. 2139 * Since 1.0 2140 * Params: 2141 * glyphs = array of glyphs to show 2142 */ 2143 public void showGlyphs(cairo_glyph_t[] glyphs) 2144 { 2145 // void cairo_show_glyphs (cairo_t *cr, const cairo_glyph_t *glyphs, int num_glyphs); 2146 cairo_show_glyphs(cairo, glyphs.ptr, cast(int) glyphs.length); 2147 } 2148 2149 /** 2150 * This operation has rendering effects similar to cairo_show_glyphs() 2151 * but, if the target surface supports it, uses the provided text and 2152 * cluster mapping to embed the text for the glyphs shown in the output. 2153 * If the target does not support the extended attributes, this function 2154 * acts like the basic cairo_show_glyphs() as if it had been passed 2155 * glyphs and num_glyphs. 2156 * The mapping between utf8 and glyphs is provided by an array of 2157 * clusters. Each cluster covers a number of 2158 * text bytes and glyphs, and neighboring clusters cover neighboring 2159 * areas of utf8 and glyphs. The clusters should collectively cover utf8 2160 * and glyphs in entirety. 2161 * The first cluster always covers bytes from the beginning of utf8. 2162 * If cluster_flags do not have the CAIRO_TEXT_CLUSTER_FLAG_BACKWARD 2163 * set, the first cluster also covers the beginning 2164 * of glyphs, otherwise it covers the end of the glyphs array and 2165 * following clusters move backward. 2166 * See cairo_text_cluster_t for constraints on valid clusters. 2167 * Since 1.8 2168 * Params: 2169 * utf8 = a string of text encoded in UTF-8 2170 * utf8_Len = length of utf8 in bytes, or -1 if it is NUL-terminated 2171 * glyphs = array of glyphs to show 2172 * clusters = array of cluster mapping information 2173 * clusterFlags = cluster mapping flags 2174 */ 2175 public void showTextGlyphs(string utf8, int utf8_Len, cairo_glyph_t[] glyphs, cairo_text_cluster_t[] clusters, cairo_text_cluster_flags_t clusterFlags) 2176 { 2177 // void cairo_show_text_glyphs (cairo_t *cr, const char *utf8, int utf8_len, const cairo_glyph_t *glyphs, int num_glyphs, const cairo_text_cluster_t *clusters, int num_clusters, cairo_text_cluster_flags_t cluster_flags); 2178 cairo_show_text_glyphs(cairo, Str.toStringz(utf8), utf8_Len, glyphs.ptr, cast(int) glyphs.length, clusters.ptr, cast(int) clusters.length, clusterFlags); 2179 } 2180 2181 /** 2182 * Gets the font extents for the currently selected font. 2183 * Since 1.0 2184 * Params: 2185 * extents = a cairo_font_extents_t object into which the results 2186 * will be stored. 2187 */ 2188 public void fontExtents(cairo_font_extents_t* extents) 2189 { 2190 // void cairo_font_extents (cairo_t *cr, cairo_font_extents_t *extents); 2191 cairo_font_extents(cairo, extents); 2192 } 2193 2194 /** 2195 * Gets the extents for a string of text. The extents describe a 2196 * user-space rectangle that encloses the "inked" portion of the text, 2197 * (as it would be drawn by cairo_show_text()). Additionally, the 2198 * x_advance and y_advance values indicate the amount by which the 2199 * current point would be advanced by cairo_show_text(). 2200 * Note that whitespace characters do not directly contribute to the 2201 * size of the rectangle (extents.width and extents.height). They do 2202 * contribute indirectly by changing the position of non-whitespace 2203 * characters. In particular, trailing whitespace characters are 2204 * likely to not affect the size of the rectangle, though they will 2205 * affect the x_advance and y_advance values. 2206 * Since 1.0 2207 * Params: 2208 * utf8 = a NUL-terminated string of text encoded in UTF-8, or NULL 2209 * extents = a cairo_text_extents_t object into which the results 2210 * will be stored 2211 */ 2212 public void textExtents(string utf8, cairo_text_extents_t* extents) 2213 { 2214 // void cairo_text_extents (cairo_t *cr, const char *utf8, cairo_text_extents_t *extents); 2215 cairo_text_extents(cairo, Str.toStringz(utf8), extents); 2216 } 2217 2218 /** 2219 * Gets the extents for an array of glyphs. The extents describe a 2220 * user-space rectangle that encloses the "inked" portion of the 2221 * glyphs, (as they would be drawn by cairo_show_glyphs()). 2222 * Additionally, the x_advance and y_advance values indicate the 2223 * amount by which the current point would be advanced by 2224 * cairo_show_glyphs(). 2225 * Note that whitespace glyphs do not contribute to the size of the 2226 * rectangle (extents.width and extents.height). 2227 * Since 1.0 2228 * Params: 2229 * glyphs = an array of cairo_glyph_t objects 2230 * extents = a cairo_text_extents_t object into which the results 2231 * will be stored 2232 */ 2233 public void glyphExtents(cairo_glyph_t[] glyphs, cairo_text_extents_t* extents) 2234 { 2235 // void cairo_glyph_extents (cairo_t *cr, const cairo_glyph_t *glyphs, int num_glyphs, cairo_text_extents_t *extents); 2236 cairo_glyph_extents(cairo, glyphs.ptr, cast(int) glyphs.length, extents); 2237 } 2238 2239 /** 2240 * Creates a font face from a triplet of family, slant, and weight. 2241 * These font faces are used in implementation of the the cairo_t "toy" 2242 * font API. 2243 * If family is the zero-length string "", the platform-specific default 2244 * family is assumed. The default family then can be queried using 2245 * cairo_toy_font_face_get_family(). 2246 * The cairo_select_font_face() function uses this to create font faces. 2247 * See that function for limitations and other details of toy font faces. 2248 * Since 1.8 2249 * Params: 2250 * family = a font family name, encoded in UTF-8 2251 * slant = the slant for the font 2252 * weight = the weight for the font 2253 * Returns: a newly created cairo_font_face_t. Free with cairo_font_face_destroy() when you are done using it. 2254 */ 2255 public static FontFace toyFontFaceCreate(string family, cairo_font_slant_t slant, cairo_font_weight_t weight) 2256 { 2257 // cairo_font_face_t * cairo_toy_font_face_create (const char *family, cairo_font_slant_t slant, cairo_font_weight_t weight); 2258 auto p = cairo_toy_font_face_create(Str.toStringz(family), slant, weight); 2259 2260 if(p is null) 2261 { 2262 return null; 2263 } 2264 2265 return new FontFace(cast(cairo_font_face_t*) p); 2266 } 2267 2268 /** 2269 * Gets the familly name of a toy font. 2270 * Since 1.8 2271 * Params: 2272 * fontFace = A toy font face 2273 * Returns: The family name. This string is owned by the font face and remains valid as long as the font face is alive (referenced). 2274 */ 2275 public static string toyFontFaceGetFamily(FontFace fontFace) 2276 { 2277 // const char * cairo_toy_font_face_get_family (cairo_font_face_t *font_face); 2278 return Str.toString(cairo_toy_font_face_get_family((fontFace is null) ? null : fontFace.getFontFaceStruct())); 2279 } 2280 2281 /** 2282 * Gets the slant a toy font. 2283 * Since 1.8 2284 * Params: 2285 * fontFace = A toy font face 2286 * Returns: The slant value 2287 */ 2288 public static cairo_font_slant_t toyFontFaceGetSlant(FontFace fontFace) 2289 { 2290 // cairo_font_slant_t cairo_toy_font_face_get_slant (cairo_font_face_t *font_face); 2291 return cairo_toy_font_face_get_slant((fontFace is null) ? null : fontFace.getFontFaceStruct()); 2292 } 2293 2294 /** 2295 * Gets the weight a toy font. 2296 * Since 1.8 2297 * Params: 2298 * fontFace = A toy font face 2299 * Returns: The weight value 2300 */ 2301 public static cairo_font_weight_t toyFontFaceGetWeight(FontFace fontFace) 2302 { 2303 // cairo_font_weight_t cairo_toy_font_face_get_weight (cairo_font_face_t *font_face); 2304 return cairo_toy_font_face_get_weight((fontFace is null) ? null : fontFace.getFontFaceStruct()); 2305 } 2306 2307 /** 2308 * Frees an array of cairo_glyph_t's allocated using cairo_glyph_allocate(). 2309 * This function is only useful to free glyph array returned 2310 * by cairo_scaled_font_text_to_glyphs() where cairo returns 2311 * an array of glyphs that the user will free. 2312 * For all other uses, user can use their own allocation method 2313 * for glyphs. 2314 * Since 1.8 2315 * Params: 2316 * glyphs = array of glyphs to free, or NULL 2317 */ 2318 public static void glyphFree(cairo_glyph_t[] glyphs) 2319 { 2320 // void cairo_glyph_free (cairo_glyph_t *glyphs); 2321 cairo_glyph_free(glyphs.ptr); 2322 } 2323 2324 /** 2325 * Frees an array of cairo_text_cluster's allocated using cairo_text_cluster_allocate(). 2326 * This function is only useful to free text cluster array returned 2327 * by cairo_scaled_font_text_to_glyphs() where cairo returns 2328 * an array of text clusters that the user will free. 2329 * For all other uses, user can use their own allocation method 2330 * for text clusters. 2331 * Since 1.8 2332 * Params: 2333 * clusters = array of text clusters to free, or NULL 2334 */ 2335 public static void textClusterFree(cairo_text_cluster_t[] clusters) 2336 { 2337 // void cairo_text_cluster_free (cairo_text_cluster_t *clusters); 2338 cairo_text_cluster_free(clusters.ptr); 2339 } 2340 }