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