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-surface-t.html 27 * outPack = cairo 28 * outFile = Surface 29 * strct = cairo_surface_t 30 * realStrct= 31 * ctorStrct= 32 * clss = Surface 33 * interf = 34 * class Code: Yes 35 * interface Code: No 36 * template for: 37 * extend = 38 * implements: 39 * prefixes: 40 * - cairo_surface_ 41 * omit structs: 42 * omit prefixes: 43 * omit code: 44 * - cairo_surface_get_mime_data 45 * omit signals: 46 * imports: 47 * - glib.Str 48 * - cairo.Device 49 * - cairo.FontOption 50 * - gdk.Window 51 * - gtkc.gdk 52 * structWrap: 53 * - cairo_device_t* -> Device 54 * - cairo_font_options_t* -> FontOption 55 * - cairo_surface_t* -> Surface 56 * module aliases: 57 * local aliases: 58 * overrides: 59 */ 60 61 module cairo.Surface; 62 63 public import cairo.c.types; 64 65 private import cairo.c.functions; 66 private import glib.ConstructionException; 67 68 private import glib.Str; 69 private import cairo.Device; 70 private import cairo.FontOption; 71 72 /** 73 * cairo_surface_t is the abstract type representing all different drawing 74 * targets that cairo can render to. The actual drawings are 75 * performed using a cairo context. 76 * 77 * A cairo surface is created by using backend-specific 78 * constructors, typically of the form 79 * cairo_backend_surface_create(). 80 * 81 * Most surface types allow accessing the surface without using Cairo 82 * functions. If you do this, keep in mind that it is mandatory that you call 83 * cairo_surface_flush() before reading from or writing to the surface and that 84 * you must use cairo_surface_mark_dirty() after modifying it. 85 * 86 * $(DDOC_COMMENT example) 87 * 88 * Note that for other surface types it might be necessary to acquire the 89 * surface's device first. See cairo_device_acquire() for a discussion of 90 * devices. 91 */ 92 public class Surface 93 { 94 95 /** the main Gtk struct */ 96 protected cairo_surface_t* cairo_surface; 97 98 99 /** Get the main Gtk struct */ 100 public cairo_surface_t* getSurfaceStruct() 101 { 102 return cairo_surface; 103 } 104 105 106 /** the main Gtk struct as a void* */ 107 protected void* getStruct() 108 { 109 return cast(void*)cairo_surface; 110 } 111 112 /** 113 * Sets our main struct and passes it to the parent class 114 */ 115 public this (cairo_surface_t* cairo_surface) 116 { 117 this.cairo_surface = cairo_surface; 118 } 119 120 /** 121 * Return mime data previously attached to surface using the 122 * specified mime type. If no data has been attached with the given 123 * mime type, data is set NULL. 124 * Since 1.10 125 * Params: 126 * mimeType = the mime type of the image data 127 * data = the image data to attached to the surface 128 */ 129 public void getMimeData(string mimeType, out ubyte[] data) 130 { 131 // void cairo_surface_get_mime_data (cairo_surface_t *surface, const char *mime_type, unsigned char **data, unsigned long *length); 132 uchar* outdata = null; 133 ulong length; 134 135 cairo_surface_get_mime_data(cairo_surface, Str.toStringz(mimeType), &outdata, &length); 136 137 data = outdata[0 .. cast(size_t)length]; 138 } 139 140 /** 141 */ 142 143 /** 144 * Create a new surface that is as compatible as possible with an 145 * existing surface. For example the new surface will have the same 146 * fallback resolution and font options as other. Generally, the new 147 * surface will also use the same backend as other, unless that is 148 * not possible for some reason. The type of the returned surface may 149 * be examined with cairo_surface_get_type(). 150 * Initially the surface contents are all 0 (transparent if contents 151 * have transparency, black otherwise.) 152 * Use cairo_surface_create_similar_image() if you need an image surface 153 * which can be painted quickly to the target surface. 154 * Since 1.0 155 * Params: 156 * content = the content for the new surface 157 * width = width of the new surface, (in device-space units) 158 * height = height of the new surface (in device-space units) 159 * Returns: a pointer to the newly allocated surface. The caller owns the surface and should call cairo_surface_destroy() when done with it. This function always returns a valid pointer, but it will return a pointer to a "nil" surface if other is already in an error state or any other error occurs. 160 */ 161 public Surface createSimilar(cairo_content_t content, int width, int height) 162 { 163 // cairo_surface_t * cairo_surface_create_similar (cairo_surface_t *other, cairo_content_t content, int width, int height); 164 auto p = cairo_surface_create_similar(cairo_surface, content, width, height); 165 166 if(p is null) 167 { 168 return null; 169 } 170 171 return new Surface(cast(cairo_surface_t*) p); 172 } 173 174 /** 175 * Create a new image surface that is as compatible as possible for uploading 176 * to and the use in conjunction with an existing surface. However, this surface 177 * can still be used like any normal image surface. 178 * Initially the surface contents are all 0 (transparent if contents 179 * have transparency, black otherwise.) 180 * Use cairo_surface_create_similar() if you don't need an image surface. 181 * Since 1.12 182 * Params: 183 * format = the format for the new surface 184 * width = width of the new surface, (in device-space units) 185 * height = height of the new surface (in device-space units) 186 * Returns: a pointer to the newly allocated image surface. The caller owns the surface and should call cairo_surface_destroy() when done with it. This function always returns a valid pointer, but it will return a pointer to a "nil" surface if other is already in an error state or any other error occurs. 187 */ 188 public Surface createSimilarImage(cairo_format_t format, int width, int height) 189 { 190 // cairo_surface_t * cairo_surface_create_similar_image (cairo_surface_t *other, cairo_format_t format, int width, int height); 191 auto p = cairo_surface_create_similar_image(cairo_surface, format, width, height); 192 193 if(p is null) 194 { 195 return null; 196 } 197 198 return new Surface(cast(cairo_surface_t*) p); 199 } 200 201 /** 202 * Create a new surface that is a rectangle within the target surface. 203 * All operations drawn to this surface are then clipped and translated 204 * onto the target surface. Nothing drawn via this sub-surface outside of 205 * its bounds is drawn onto the target surface, making this a useful method 206 * for passing constrained child surfaces to library routines that draw 207 * directly onto the parent surface, i.e. with no further backend allocations, 208 * double buffering or copies. 209 * Note 210 * The semantics of subsurfaces have not been finalized yet 211 * unless the rectangle is in full device units, is contained within 212 * the extents of the target surface, and the target or subsurface's 213 * device transforms are not changed. 214 * Since 1.10 215 * Params: 216 * x = the x-origin of the sub-surface from the top-left of the target surface (in device-space units) 217 * y = the y-origin of the sub-surface from the top-left of the target surface (in device-space units) 218 * width = width of the sub-surface (in device-space units) 219 * height = height of the sub-surface (in device-space units) 220 * Returns: a pointer to the newly allocated surface. The caller owns the surface and should call cairo_surface_destroy() when done with it. This function always returns a valid pointer, but it will return a pointer to a "nil" surface if other is already in an error state or any other error occurs. 221 */ 222 public Surface createForRectangle(double x, double y, double width, double height) 223 { 224 // cairo_surface_t * cairo_surface_create_for_rectangle (cairo_surface_t *target, double x, double y, double width, double height); 225 auto p = cairo_surface_create_for_rectangle(cairo_surface, x, y, width, height); 226 227 if(p is null) 228 { 229 return null; 230 } 231 232 return new Surface(cast(cairo_surface_t*) p); 233 } 234 235 /** 236 * Increases the reference count on surface by one. This prevents 237 * surface from being destroyed until a matching call to 238 * cairo_surface_destroy() is made. 239 * The number of references to a cairo_surface_t can be get using 240 * cairo_surface_get_reference_count(). 241 * Since 1.0 242 * Returns: the referenced cairo_surface_t. 243 */ 244 public Surface reference() 245 { 246 // cairo_surface_t * cairo_surface_reference (cairo_surface_t *surface); 247 auto p = cairo_surface_reference(cairo_surface); 248 249 if(p is null) 250 { 251 return null; 252 } 253 254 return new Surface(cast(cairo_surface_t*) p); 255 } 256 257 /** 258 * Decreases the reference count on surface by one. If the result is 259 * zero, then surface and all associated resources are freed. See 260 * cairo_surface_reference(). 261 * Since 1.0 262 */ 263 public void destroy() 264 { 265 // void cairo_surface_destroy (cairo_surface_t *surface); 266 cairo_surface_destroy(cairo_surface); 267 } 268 269 /** 270 * Checks whether an error has previously occurred for this 271 * surface. 272 * Since 1.0 273 * Returns: CAIRO_STATUS_SUCCESS, CAIRO_STATUS_NULL_POINTER, CAIRO_STATUS_NO_MEMORY, CAIRO_STATUS_READ_ERROR, CAIRO_STATUS_INVALID_CONTENT, CAIRO_STATUS_INVALID_FORMAT, or CAIRO_STATUS_INVALID_VISUAL. 274 */ 275 public cairo_status_t status() 276 { 277 // cairo_status_t cairo_surface_status (cairo_surface_t *surface); 278 return cairo_surface_status(cairo_surface); 279 } 280 281 /** 282 * This function finishes the surface and drops all references to 283 * external resources. For example, for the Xlib backend it means 284 * that cairo will no longer access the drawable, which can be freed. 285 * After calling cairo_surface_finish() the only valid operations on a 286 * surface are getting and setting user, referencing and 287 * destroying, and flushing and finishing it. 288 * Further drawing to the surface will not affect the 289 * surface but will instead trigger a CAIRO_STATUS_SURFACE_FINISHED 290 * error. 291 * When the last call to cairo_surface_destroy() decreases the 292 * reference count to zero, cairo will call cairo_surface_finish() if 293 * it hasn't been called already, before freeing the resources 294 * associated with the surface. 295 * Since 1.0 296 */ 297 public void finish() 298 { 299 // void cairo_surface_finish (cairo_surface_t *surface); 300 cairo_surface_finish(cairo_surface); 301 } 302 303 /** 304 * Do any pending drawing for the surface and also restore any 305 * temporary modifications cairo has made to the surface's 306 * state. This function must be called before switching from 307 * drawing on the surface with cairo to drawing on it directly 308 * with native APIs. If the surface doesn't support direct access, 309 * then this function does nothing. 310 * Since 1.0 311 */ 312 public void flush() 313 { 314 // void cairo_surface_flush (cairo_surface_t *surface); 315 cairo_surface_flush(cairo_surface); 316 } 317 318 /** 319 * This function returns the device for a surface. 320 * See cairo_device_t. 321 * Since 1.10 322 * Returns: The device for surface or NULL if the surface does not have an associated device. 323 */ 324 public Device getDevice() 325 { 326 // cairo_device_t * cairo_surface_get_device (cairo_surface_t *surface); 327 auto p = cairo_surface_get_device(cairo_surface); 328 329 if(p is null) 330 { 331 return null; 332 } 333 334 return new Device(cast(cairo_device_t*) p); 335 } 336 337 /** 338 * Retrieves the default font rendering options for the surface. 339 * This allows display surfaces to report the correct subpixel order 340 * for rendering on them, print surfaces to disable hinting of 341 * metrics and so forth. The result can then be used with 342 * cairo_scaled_font_create(). 343 * Since 1.0 344 * Params: 345 * options = a cairo_font_options_t object into which to store 346 * the retrieved options. All existing values are overwritten 347 */ 348 public void getFontOptions(FontOption options) 349 { 350 // void cairo_surface_get_font_options (cairo_surface_t *surface, cairo_font_options_t *options); 351 cairo_surface_get_font_options(cairo_surface, (options is null) ? null : options.getFontOptionStruct()); 352 } 353 354 /** 355 * This function returns the content type of surface which indicates 356 * whether the surface contains color and/or alpha information. See 357 * cairo_content_t. 358 * Since 1.2 359 * Returns: The content type of surface. 360 */ 361 public cairo_content_t getContent() 362 { 363 // cairo_content_t cairo_surface_get_content (cairo_surface_t *surface); 364 return cairo_surface_get_content(cairo_surface); 365 } 366 367 /** 368 * Tells cairo that drawing has been done to surface using means other 369 * than cairo, and that cairo should reread any cached areas. Note 370 * that you must call cairo_surface_flush() before doing such drawing. 371 * Since 1.0 372 */ 373 public void markDirty() 374 { 375 // void cairo_surface_mark_dirty (cairo_surface_t *surface); 376 cairo_surface_mark_dirty(cairo_surface); 377 } 378 379 /** 380 * Like cairo_surface_mark_dirty(), but drawing has been done only to 381 * the specified rectangle, so that cairo can retain cached contents 382 * for other parts of the surface. 383 * Any cached clip set on the surface will be reset by this function, 384 * to make sure that future cairo calls have the clip set that they 385 * expect. 386 * Since 1.0 387 * Params: 388 * x = X coordinate of dirty rectangle 389 * y = Y coordinate of dirty rectangle 390 * width = width of dirty rectangle 391 * height = height of dirty rectangle 392 */ 393 public void markDirtyRectangle(int x, int y, int width, int height) 394 { 395 // void cairo_surface_mark_dirty_rectangle (cairo_surface_t *surface, int x, int y, int width, int height); 396 cairo_surface_mark_dirty_rectangle(cairo_surface, x, y, width, height); 397 } 398 399 /** 400 * Sets an offset that is added to the device coordinates determined 401 * by the CTM when drawing to surface. One use case for this function 402 * is when we want to create a cairo_surface_t that redirects drawing 403 * for a portion of an onscreen surface to an offscreen surface in a 404 * way that is completely invisible to the user of the cairo 405 * API. Setting a transformation via cairo_translate() isn't 406 * sufficient to do this, since functions like 407 * cairo_device_to_user() will expose the hidden offset. 408 * Note that the offset affects drawing to the surface as well as 409 * using the surface in a source pattern. 410 * Since 1.0 411 * Params: 412 * xOffset = the offset in the X direction, in device units 413 * yOffset = the offset in the Y direction, in device units 414 */ 415 public void setDeviceOffset(double xOffset, double yOffset) 416 { 417 // void cairo_surface_set_device_offset (cairo_surface_t *surface, double x_offset, double y_offset); 418 cairo_surface_set_device_offset(cairo_surface, xOffset, yOffset); 419 } 420 421 /** 422 * This function returns the previous device offset set by 423 * cairo_surface_set_device_offset(). 424 * Since 1.2 425 * Params: 426 * xOffset = the offset in the X direction, in device units 427 * yOffset = the offset in the Y direction, in device units 428 */ 429 public void getDeviceOffset(out double xOffset, out double yOffset) 430 { 431 // void cairo_surface_get_device_offset (cairo_surface_t *surface, double *x_offset, double *y_offset); 432 cairo_surface_get_device_offset(cairo_surface, &xOffset, &yOffset); 433 } 434 435 /** 436 * Set the horizontal and vertical resolution for image fallbacks. 437 * When certain operations aren't supported natively by a backend, 438 * cairo will fallback by rendering operations to an image and then 439 * overlaying that image onto the output. For backends that are 440 * natively vector-oriented, this function can be used to set the 441 * resolution used for these image fallbacks, (larger values will 442 * result in more detailed images, but also larger file sizes). 443 * Some examples of natively vector-oriented backends are the ps, pdf, 444 * and svg backends. 445 * For backends that are natively raster-oriented, image fallbacks are 446 * still possible, but they are always performed at the native 447 * device resolution. So this function has no effect on those 448 * backends. 449 * Note: The fallback resolution only takes effect at the time of 450 * completing a page (with cairo_show_page() or cairo_copy_page()) so 451 * there is currently no way to have more than one fallback resolution 452 * in effect on a single page. 453 * The default fallback resoultion is 300 pixels per inch in both 454 * dimensions. 455 * Since 1.2 456 * Params: 457 * xPixelsPerInch = horizontal setting for pixels per inch 458 * yPixelsPerInch = vertical setting for pixels per inch 459 */ 460 public void setFallbackResolution(double xPixelsPerInch, double yPixelsPerInch) 461 { 462 // void cairo_surface_set_fallback_resolution (cairo_surface_t *surface, double x_pixels_per_inch, double y_pixels_per_inch); 463 cairo_surface_set_fallback_resolution(cairo_surface, xPixelsPerInch, yPixelsPerInch); 464 } 465 466 /** 467 * This function returns the previous fallback resolution set by 468 * cairo_surface_set_fallback_resolution(), or default fallback 469 * resolution if never set. 470 * Since 1.8 471 * Params: 472 * xPixelsPerInch = horizontal pixels per inch 473 * yPixelsPerInch = vertical pixels per inch 474 */ 475 public void getFallbackResolution(out double xPixelsPerInch, out double yPixelsPerInch) 476 { 477 // void cairo_surface_get_fallback_resolution (cairo_surface_t *surface, double *x_pixels_per_inch, double *y_pixels_per_inch); 478 cairo_surface_get_fallback_resolution(cairo_surface, &xPixelsPerInch, &yPixelsPerInch); 479 } 480 481 /** 482 * This function returns the type of the backend used to create 483 * a surface. See cairo_surface_type_t for available types. 484 * Since 1.2 485 * Params: 486 * surface = a cairo_surface_t 487 * Returns: The type of surface. 488 */ 489 public cairo_surface_type_t getType() 490 { 491 // cairo_surface_type_t cairo_surface_get_type (cairo_surface_t *surface); 492 return cairo_surface_get_type(cairo_surface); 493 } 494 495 /** 496 * Returns the current reference count of surface. 497 * Since 1.4 498 * Returns: the current reference count of surface. If the object is a nil object, 0 will be returned. 499 */ 500 public uint getReferenceCount() 501 { 502 // unsigned int cairo_surface_get_reference_count (cairo_surface_t *surface); 503 return cairo_surface_get_reference_count(cairo_surface); 504 } 505 506 /** 507 * Attach user data to surface. To remove user data from a surface, 508 * call this function with the key that was used to set it and NULL 509 * for data. 510 * Since 1.0 511 * Params: 512 * key = the address of a cairo_user_data_key_t to attach the user data to 513 * userData = the user data to attach to the surface 514 * destroy = a cairo_destroy_func_t which will be called when the 515 * surface is destroyed or when new user data is attached using the 516 * same key. 517 * Returns: CAIRO_STATUS_SUCCESS or CAIRO_STATUS_NO_MEMORY if a slot could not be allocated for the user data. 518 */ 519 public cairo_status_t setUserData(cairo_user_data_key_t* key, void* userData, cairo_destroy_func_t destroy) 520 { 521 // cairo_status_t cairo_surface_set_user_data (cairo_surface_t *surface, const cairo_user_data_key_t *key, void *user_data, cairo_destroy_func_t destroy); 522 return cairo_surface_set_user_data(cairo_surface, key, userData, destroy); 523 } 524 525 /** 526 * Return user data previously attached to surface using the specified 527 * key. If no user data has been attached with the given key this 528 * function returns NULL. 529 * Since 1.0 530 * Params: 531 * key = the address of the cairo_user_data_key_t the user data was 532 * attached to 533 * Returns: the user data previously attached or NULL. 534 */ 535 public void* getUserData(cairo_user_data_key_t* key) 536 { 537 // void * cairo_surface_get_user_data (cairo_surface_t *surface, const cairo_user_data_key_t *key); 538 return cairo_surface_get_user_data(cairo_surface, key); 539 } 540 541 /** 542 * Emits the current page for backends that support multiple pages, 543 * but doesn't clear it, so that the contents of the current page will 544 * be retained for the next page. Use cairo_surface_show_page() if you 545 * want to get an empty page after the emission. 546 * There is a convenience function for this that takes a cairo_t, 547 * namely cairo_copy_page(). 548 * Since 1.6 549 */ 550 public void copyPage() 551 { 552 // void cairo_surface_copy_page (cairo_surface_t *surface); 553 cairo_surface_copy_page(cairo_surface); 554 } 555 556 /** 557 * Emits and clears the current page for backends that support multiple 558 * pages. Use cairo_surface_copy_page() if you don't want to clear the page. 559 * There is a convenience function for this that takes a cairo_t, 560 * namely cairo_show_page(). 561 * Since 1.6 562 */ 563 public void showPage() 564 { 565 // void cairo_surface_show_page (cairo_surface_t *surface); 566 cairo_surface_show_page(cairo_surface); 567 } 568 569 /** 570 * Returns whether the surface supports 571 * sophisticated cairo_show_text_glyphs() operations. That is, 572 * whether it actually uses the provided text and cluster data 573 * to a cairo_show_text_glyphs() call. 574 * Note: Even if this function returns FALSE, a 575 * cairo_show_text_glyphs() operation targeted at surface will 576 * still succeed. It just will 577 * act like a cairo_show_glyphs() operation. Users can use this 578 * function to avoid computing UTF-8 text and cluster mapping if the 579 * target surface does not use it. 580 * Since 1.8 581 * Returns: TRUE if surface supports cairo_show_text_glyphs(), FALSE otherwise 582 */ 583 public cairo_bool_t hasShowTextGlyphs() 584 { 585 // cairo_bool_t cairo_surface_has_show_text_glyphs (cairo_surface_t *surface); 586 return cairo_surface_has_show_text_glyphs(cairo_surface); 587 } 588 589 /** 590 * Attach an image in the format mime_type to surface. To remove 591 * the data from a surface, call this function with same mime type 592 * and NULL for data. 593 * The attached image (or filename) data can later be used by backends 594 * which support it (currently: PDF, PS, SVG and Win32 Printing 595 * surfaces) to emit this data instead of making a snapshot of the 596 * surface. This approach tends to be faster and requires less 597 * memory and disk space. 598 * The recognized MIME types are the following: CAIRO_MIME_TYPE_JPEG, 599 * CAIRO_MIME_TYPE_PNG, CAIRO_MIME_TYPE_JP2, CAIRO_MIME_TYPE_URI. 600 * See corresponding backend surface docs for details about which MIME 601 * types it can handle. Caution: the associated MIME data will be 602 * discarded if you draw on the surface afterwards. Use this function 603 * with care. 604 * Since 1.10 605 * Params: 606 * mimeType = the MIME type of the image data 607 * data = the image data to attach to the surface 608 * destroy = a cairo_destroy_func_t which will be called when the 609 * surface is destroyed or when new image data is attached using the 610 * same mime type. 611 * closure = the data to be passed to the destroy notifier 612 * Returns: CAIRO_STATUS_SUCCESS or CAIRO_STATUS_NO_MEMORY if a slot could not be allocated for the user data. 613 */ 614 public cairo_status_t setMimeData(string mimeType, ubyte[] data, cairo_destroy_func_t destroy, void* closure) 615 { 616 // cairo_status_t cairo_surface_set_mime_data (cairo_surface_t *surface, const char *mime_type, const unsigned char *data, unsigned long length, cairo_destroy_func_t destroy, void *closure); 617 return cairo_surface_set_mime_data(cairo_surface, Str.toStringz(mimeType), data.ptr, cast(int) data.length, destroy, closure); 618 } 619 620 /** 621 * Return whether surface supports mime_type. 622 * Since 1.12 623 * Params: 624 * mimeType = the mime type 625 * Returns: TRUE if surface supports mime_type, FALSE otherwise 626 */ 627 public cairo_bool_t supportsMimeType(string mimeType) 628 { 629 // cairo_bool_t cairo_surface_supports_mime_type (cairo_surface_t *surface, const char *mime_type); 630 return cairo_surface_supports_mime_type(cairo_surface, Str.toStringz(mimeType)); 631 } 632 633 /** 634 * Returns an image surface that is the most efficient mechanism for 635 * modifying the backing store of the target surface. The region retrieved 636 * may be limited to the extents or NULL for the whole surface 637 * Note, the use of the original surface as a target or source whilst it is 638 * mapped is undefined. The result of mapping the surface multiple times is 639 * undefined. Calling cairo_surface_destroy() or cairo_surface_finish() on the 640 * resulting image surface results in undefined behavior. 641 * Since 1.12 642 * Params: 643 * extents = limit the extraction to an rectangular region 644 * Returns: a pointer to the newly allocated image surface. The caller must use cairo_surface_unmap_image() to destroy this image surface. This function always returns a valid pointer, but it will return a pointer to a "nil" surface if other is already in an error state or any other error occurs. 645 */ 646 public Surface mapToImage(ref cairo_rectangle_int_t extents) 647 { 648 // cairo_surface_t * cairo_surface_map_to_image (cairo_surface_t *surface, const cairo_rectangle_int_t *extents); 649 auto p = cairo_surface_map_to_image(cairo_surface, &extents); 650 651 if(p is null) 652 { 653 return null; 654 } 655 656 return new Surface(cast(cairo_surface_t*) p); 657 } 658 659 /** 660 * Unmaps the image surface as returned from #cairo_surface_map_to_image(). 661 * The content of the image will be uploaded to the target surface. 662 * Afterwards, the image is destroyed. 663 * Using an image surface which wasn't returned by cairo_surface_map_to_image() 664 * results in undefined behavior. 665 * Since 1.12 666 * Params: 667 * image = the currently mapped image 668 */ 669 public void unmapImage(Surface image) 670 { 671 // void cairo_surface_unmap_image (cairo_surface_t *surface, cairo_surface_t *image); 672 cairo_surface_unmap_image(cairo_surface, (image is null) ? null : image.getSurfaceStruct()); 673 } 674 }