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