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