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