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