alternative to assert
[gtkD.git] / gtkD / src / cairoLib / Surface.d
blob1bd53b7c692ffe6ed128ae49148e74db35f46918
1 /*
2 * This file is part of gtkD.
4 * gtkD is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2.1 of the License, or
7 * (at your option) any later version.
9 * gtkD is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with gtkD; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // generated automatically - do not change
20 // find conversion definition on APILookup.txt
21 // implement new conversion functionalities on the wrap.utils pakage
24 * Conversion parameters:
25 * inFile = cairo-cairo-surface-t.html
26 * outPack = cairoLib
27 * outFile = Surface
28 * strct = cairo_surface_t
29 * realStrct=
30 * ctorStrct=
31 * clss = Surface
32 * interf =
33 * class Code: No
34 * interface Code: No
35 * template for:
36 * extend =
37 * implements:
38 * prefixes:
39 * - cairo_surface_
40 * - cairo_
41 * omit structs:
42 * omit prefixes:
43 * omit code:
44 * imports:
45 * - glib.Str
46 * structWrap:
47 * module aliases:
48 * local aliases:
51 module cairoLib.Surface;
53 version(noAssert)
55 version(Tango)
57 import tango.io.Stdout; // use the tango loging?
61 private import gtkc.cairoLibtypes;
63 private import gtkc.cairoLib;
66 private import glib.Str;
71 /**
72 * Description
74 public class Surface
77 /** the main Gtk struct */
78 protected cairo_surface_t* cairo_surface;
81 public cairo_surface_t* getSurfaceStruct()
83 return cairo_surface;
87 /** the main Gtk struct as a void* */
88 protected void* getStruct()
90 return cast(void*)cairo_surface;
93 /**
94 * Sets our main struct and passes it to the parent class
96 public this (cairo_surface_t* cairo_surface)
98 version(noAssert)
100 if ( cairo_surface is null )
102 int zero = 0;
103 version(Tango)
105 Stdout("struct cairo_surface is null on constructor").newline;
107 else
109 printf("struct cairo_surface is null on constructor");
111 zero = zero / zero;
114 else
116 assert(cairo_surface !is null, "struct cairo_surface is null on constructor");
118 this.cairo_surface = cairo_surface;
122 * Description
123 * Image surfaces provide the ability to render to memory buffers
124 * either allocated by cairo or by the calling code. The supported
125 * image formats are those defined in cairo_format_t.
134 * Create a new surface that is as compatible as possible with an
135 * existing surface. For example the new surface will have the same
136 * fallback resolution and font options as other. Generally, the new
137 * surface will also use the same backend as other, unless that is
138 * not possible for some reason. The type of the returned surface may
139 * be examined with cairo_surface_get_type().
140 * Initially the surface contents are all 0 (transparent if contents
141 * have transparency, black otherwise.)
142 * other:
143 * an existing surface used to select the backend of the new surface
144 * content:
145 * the content for the new surface
146 * width:
147 * width of the new surface, (in device-space units)
148 * height:
149 * height of the new surface (in device-space units)
150 * Returns:
151 * a pointer to the newly allocated surface. The caller
152 * owns the surface and should call cairo_surface_destroy when done
153 * with it.
154 * This function always returns a valid pointer, but it will return a
155 * pointer to a "nil" surface if other is already in an error state
156 * or any other error occurs.
158 public cairo_surface_t* createSimilar(cairo_content_t content, int width, int height)
160 // cairo_surface_t* cairo_surface_create_similar (cairo_surface_t *other, cairo_content_t content, int width, int height);
161 return cairo_surface_create_similar(cairo_surface, content, width, height);
165 * Decreases the reference count on surface by one. If the result is
166 * zero, then surface and all associated resources are freed. See
167 * cairo_surface_reference().
168 * surface:
169 * a cairo_t
171 public void destroy()
173 // void cairo_surface_destroy (cairo_surface_t *surface);
174 cairo_surface_destroy(cairo_surface);
178 * This function finishes the surface and drops all references to
179 * external resources. For example, for the Xlib backend it means
180 * that cairo will no longer access the drawable, which can be freed.
181 * After calling cairo_surface_finish() the only valid operations on a
182 * surface are getting and setting user data and referencing and
183 * destroying it. Further drawing to the surface will not affect the
184 * surface but will instead trigger a CAIRO_STATUS_SURFACE_FINISHED
185 * error.
186 * When the last call to cairo_surface_destroy() decreases the
187 * reference count to zero, cairo will call cairo_surface_finish() if
188 * it hasn't been called already, before freeing the resources
189 * associated with the surface.
190 * surface:
191 * the cairo_surface_t to finish
193 public void finish()
195 // void cairo_surface_finish (cairo_surface_t *surface);
196 cairo_surface_finish(cairo_surface);
200 * Do any pending drawing for the surface and also restore any
201 * temporary modification's cairo has made to the surface's
202 * state. This function must be called before switching from
203 * drawing on the surface with cairo to drawing on it directly
204 * with native APIs. If the surface doesn't support direct access,
205 * then this function does nothing.
206 * surface:
207 * a cairo_surface_t
209 public void flush()
211 // void cairo_surface_flush (cairo_surface_t *surface);
212 cairo_surface_flush(cairo_surface);
216 * Retrieves the default font rendering options for the surface.
217 * This allows display surfaces to report the correct subpixel order
218 * for rendering on them, print surfaces to disable hinting of
219 * metrics and so forth. The result can then be used with
220 * cairo_scaled_font_create().
221 * surface:
222 * a cairo_surface_t
223 * options:
224 * a cairo_font_options_t object into which to store
225 * the retrieved options. All existing values are overwritten
227 public void getFontOptions(cairo_font_options_t* options)
229 // void cairo_surface_get_font_options (cairo_surface_t *surface, cairo_font_options_t *options);
230 cairo_surface_get_font_options(cairo_surface, options);
234 * surface:
235 * a cairo_surface_t
236 * Returns:
237 * The content type of surface which indicates whether
238 * the surface contains color and/or alpha information. See
239 * cairo_content_t.
240 * Since 1.2
242 public cairo_content_t getContent()
244 // cairo_content_t cairo_surface_get_content (cairo_surface_t *surface);
245 return cairo_surface_get_content(cairo_surface);
249 * Attach user data to surface. To remove user data from a surface,
250 * call this function with the key that was used to set it and NULL
251 * for data.
252 * surface:
253 * a cairo_surface_t
254 * key:
255 * the address of a cairo_user_data_key_t to attach the user data to
256 * user_data:
257 * the user data to attach to the surface
258 * destroy:
259 * a cairo_destroy_func_t which will be called when the
260 * surface is destroyed or when new user data is attached using the
261 * same key.
262 * Returns:
263 * CAIRO_STATUS_SUCCESS or CAIRO_STATUS_NO_MEMORY if a
264 * slot could not be allocated for the user data.
266 public cairo_status_t setUserData(cairo_user_data_key_t* key, void* userData, cairo_destroy_func_t destroy)
268 // 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);
269 return cairo_surface_set_user_data(cairo_surface, key, userData, destroy);
273 * Return user data previously attached to surface using the specified
274 * key. If no user data has been attached with the given key this
275 * function returns NULL.
276 * surface:
277 * a cairo_surface_t
278 * key:
279 * the address of the cairo_user_data_key_t the user data was
280 * attached to
281 * Returns:
282 * the user data previously attached or NULL.
284 public void* getUserData(cairo_user_data_key_t* key)
286 // void* cairo_surface_get_user_data (cairo_surface_t *surface, const cairo_user_data_key_t *key);
287 return cairo_surface_get_user_data(cairo_surface, key);
291 * Tells cairo that drawing has been done to surface using means other
292 * than cairo, and that cairo should reread any cached areas. Note
293 * that you must call cairo_surface_flush() before doing such drawing.
294 * surface:
295 * a cairo_surface_t
297 public void markDirty()
299 // void cairo_surface_mark_dirty (cairo_surface_t *surface);
300 cairo_surface_mark_dirty(cairo_surface);
304 * Like cairo_surface_mark_dirty(), but drawing has been done only to
305 * the specified rectangle, so that cairo can retain cached contents
306 * for other parts of the surface.
307 * Any cached clip set on the surface will be reset by this function,
308 * to make sure that future cairo calls have the clip set that they
309 * expect.
310 * surface:
311 * a cairo_surface_t
312 * x:
313 * X coordinate of dirty rectangle
314 * y:
315 * Y coordinate of dirty rectangle
316 * width:
317 * width of dirty rectangle
318 * height:
319 * height of dirty rectangle
321 public void markDirtyRectangle(int x, int y, int width, int height)
323 // void cairo_surface_mark_dirty_rectangle (cairo_surface_t *surface, int x, int y, int width, int height);
324 cairo_surface_mark_dirty_rectangle(cairo_surface, x, y, width, height);
328 * Increases the reference count on surface by one. This prevents
329 * surface from being destroyed until a matching call to
330 * cairo_surface_destroy() is made.
331 * surface:
332 * a cairo_surface_t
333 * Returns:
334 * the referenced cairo_surface_t.
336 public cairo_surface_t* reference()
338 // cairo_surface_t* cairo_surface_reference (cairo_surface_t *surface);
339 return cairo_surface_reference(cairo_surface);
343 * Sets an offset that is added to the device coordinates determined
344 * by the CTM when drawing to surface. One use case for this function
345 * is when we want to create a cairo_surface_t that redirects drawing
346 * for a portion of an onscreen surface to an offscreen surface in a
347 * way that is completely invisible to the user of the cairo
348 * API. Setting a transformation via cairo_translate() isn't
349 * sufficient to do this, since functions like
350 * cairo_device_to_user() will expose the hidden offset.
351 * Note that the offset affects drawing to the surface as well as
352 * using the surface in a source pattern.
353 * surface:
354 * a cairo_surface_t
355 * x_offset:
356 * the offset in the X direction, in device units
357 * y_offset:
358 * the offset in the Y direction, in device units
360 public void setDeviceOffset(double xOffset, double yOffset)
362 // void cairo_surface_set_device_offset (cairo_surface_t *surface, double x_offset, double y_offset);
363 cairo_surface_set_device_offset(cairo_surface, xOffset, yOffset);
367 * This function returns the previous device offset set by
368 * cairo_surface_set_device_offset().
369 * surface:
370 * a cairo_surface_t
371 * x_offset:
372 * the offset in the X direction, in device units
373 * y_offset:
374 * the offset in the Y direction, in device units
375 * Since 1.2
377 public void getDeviceOffset(double* xOffset, double* yOffset)
379 // void cairo_surface_get_device_offset (cairo_surface_t *surface, double *x_offset, double *y_offset);
380 cairo_surface_get_device_offset(cairo_surface, xOffset, yOffset);
384 * Set the horizontal and vertical resolution for image fallbacks.
385 * When certain operations aren't supported natively by a backend,
386 * cairo will fallback by rendering operations to an image and then
387 * overlaying that image onto the output. For backends that are
388 * natively vector-oriented, this function can be used to set the
389 * resolution used for these image fallbacks, (larger values will
390 * result in more detailed images, but also larger file sizes).
391 * Some examples of natively vector-oriented backends are the ps, pdf,
392 * and svg backends.
393 * For backends that are natively raster-oriented, image fallbacks are
394 * still possible, but they are always performed at the native
395 * device resolution. So this function has no effect on those
396 * backends.
397 * NOTE: The fallback resolution only takes effect at the time of
398 * completing a page (with cairo_show_page() or cairo_copy_page()) so
399 * there is currently no way to have more than one fallback resolution
400 * in effect on a single page.
401 * surface:
402 * a cairo_surface_t
403 * x_pixels_per_inch:
404 * horizontal setting for pixels per inch
405 * y_pixels_per_inch:
406 * vertical setting for pixels per inch
407 * Since 1.2
409 public void setFallbackResolution(double xPixelsPerInch, double yPixelsPerInch)
411 // void cairo_surface_set_fallback_resolution (cairo_surface_t *surface, double x_pixels_per_inch, double y_pixels_per_inch);
412 cairo_surface_set_fallback_resolution(cairo_surface, xPixelsPerInch, yPixelsPerInch);
416 * Checks whether an error has previously occurred for this
417 * surface.
418 * surface:
419 * a cairo_surface_t
420 * Returns:
421 * CAIRO_STATUS_SUCCESS, CAIRO_STATUS_NULL_POINTER,
422 * CAIRO_STATUS_NO_MEMORY, CAIRO_STATUS_READ_ERROR,
423 * CAIRO_STATUS_INVALID_CONTENT, CAIRO_STATUS_INVALUE_FORMAT, or
424 * CAIRO_STATUS_INVALID_VISUAL.
426 public cairo_status_t status()
428 // cairo_status_t cairo_surface_status (cairo_surface_t *surface);
429 return cairo_surface_status(cairo_surface);
434 * This function returns the type of the backend used to create
435 * a surface. See cairo_surface_type_t for available types.
436 * surface:
437 * a cairo_surface_t
438 * Returns:
439 * The type of surface.
440 * Since 1.2
442 public cairo_surface_type_t getType()
444 // cairo_surface_type_t cairo_surface_get_type (cairo_surface_t *surface);
445 return cairo_surface_get_type(cairo_surface);
450 * Creates an image surface of the specified format and
451 * dimensions. Initially the surface contents are all
452 * 0. (Specifically, within each pixel, each color or alpha channel
453 * belonging to format will be 0. The contents of bits within a pixel,
454 * but not belonging to the given format are undefined).
455 * format:
456 * format of pixels in the surface to create
457 * width:
458 * width of the surface, in pixels
459 * height:
460 * height of the surface, in pixels
461 * Returns:
462 * a pointer to the newly created surface. The caller
463 * owns the surface and should call cairo_surface_destroy when done
464 * with it.
465 * This function always returns a valid pointer, but it will return a
466 * pointer to a "nil" surface if an error such as out of memory
467 * occurs. You can use cairo_surface_status() to check for this.
469 public static cairo_surface_t* imageSurfaceCreate(cairo_format_t format, int width, int height)
471 // cairo_surface_t* cairo_image_surface_create (cairo_format_t format, int width, int height);
472 return cairo_image_surface_create(format, width, height);
476 * Creates an image surface for the provided pixel data. The output
477 * buffer must be kept around until the cairo_surface_t is destroyed
478 * or cairo_surface_finish() is called on the surface. The initial
479 * contents of buffer will be used as the inital image contents; you
480 * must explicitely clear the buffer, using, for example,
481 * cairo_rectangle() and cairo_fill() if you want it cleared.
482 * data:
483 * a pointer to a buffer supplied by the application
484 * in which to write contents.
485 * format:
486 * the format of pixels in the buffer
487 * width:
488 * the width of the image to be stored in the buffer
489 * height:
490 * the height of the image to be stored in the buffer
491 * stride:
492 * the number of bytes between the start of rows
493 * in the buffer. Having this be specified separate from width
494 * allows for padding at the end of rows, or for writing
495 * to a subportion of a larger image.
496 * Returns:
497 * a pointer to the newly created surface. The caller
498 * owns the surface and should call cairo_surface_destroy when done
499 * with it.
500 * This function always returns a valid pointer, but it will return a
501 * pointer to a "nil" surface if an error such as out of memory
502 * occurs. You can use cairo_surface_status() to check for this.
503 * See cairo_surface_set_user_data() for a means of attaching a
504 * destroy-notification fallback to the surface if necessary.
506 public static cairo_surface_t* imageSurfaceCreateForData(ubyte* data, cairo_format_t format, int width, int height, int stride)
508 // cairo_surface_t* cairo_image_surface_create_for_data (unsigned char *data, cairo_format_t format, int width, int height, int stride);
509 return cairo_image_surface_create_for_data(data, format, width, height, stride);
513 * Get a pointer to the data of the image surface, for direct
514 * inspection or modification.
515 * surface:
516 * a cairo_image_surface_t
517 * Returns:
518 * a pointer to the image data of this surface or NULL
519 * if surface is not an image surface.
520 * Since 1.2
522 public ubyte* imageSurfaceGetData()
524 // unsigned char* cairo_image_surface_get_data (cairo_surface_t *surface);
525 return cairo_image_surface_get_data(cairo_surface);
529 * Get the format of the surface.
530 * surface:
531 * a cairo_image_surface_t
532 * Returns:
533 * the format of the surface
534 * Since 1.2
536 public cairo_format_t imageSurfaceGetFormat()
538 // cairo_format_t cairo_image_surface_get_format (cairo_surface_t *surface);
539 return cairo_image_surface_get_format(cairo_surface);
543 * Get the width of the image surface in pixels.
544 * surface:
545 * a cairo_image_surface_t
546 * Returns:
547 * the width of the surface in pixels.
549 public int imageSurfaceGetWidth()
551 // int cairo_image_surface_get_width (cairo_surface_t *surface);
552 return cairo_image_surface_get_width(cairo_surface);
556 * Get the height of the image surface in pixels.
557 * surface:
558 * a cairo_image_surface_t
559 * Returns:
560 * the height of the surface in pixels.
562 public int imageSurfaceGetHeight()
564 // int cairo_image_surface_get_height (cairo_surface_t *surface);
565 return cairo_image_surface_get_height(cairo_surface);
569 * Get the stride of the image surface in bytes
570 * surface:
571 * a cairo_image_surface_t
572 * Returns:
573 * the stride of the image surface in bytes (or 0 if
574 * surface is not an image surface). The stride is the distance in
575 * bytes from the beginning of one row of the image data to the
576 * beginning of the next row.
577 * Since 1.2
579 public int imageSurfaceGetStride()
581 // int cairo_image_surface_get_stride (cairo_surface_t *surface);
582 return cairo_image_surface_get_stride(cairo_surface);