Surface

A #cairo_surface_t represents an image, either as the destination of a drawing operation or as source when drawing onto another surface. To draw to a #cairo_surface_t, create a cairo context with the surface as the target, using cairo.global.create.

There are different subtypes of #cairo_surface_t for different drawing backends; for example, cairo.global.imageSurfaceCreate creates a bitmap image in memory. The type of a surface can be queried with cairo.surface.Surface.getSurfaceType.

The initial contents of a surface after creation depend upon the manner of its creation. If cairo creates the surface and backing storage for the user, it will be initially cleared; for example, cairo.global.imageSurfaceCreate and cairo.surface.Surface.createSimilar. Alternatively, if the user passes in a reference to some backing storage and asks cairo to wrap that in a #cairo_surface_t, then the contents are not modified; for example, cairo.global.imageSurfaceCreateForData and cairo_xlib_surface_create().

Memory management of #cairo_surface_t is done with cairo.surface.Surface.reference and cairo.surface.Surface.destroy.

class Surface : Boxed {}

Members

Functions

copyPage
void copyPage()

Emits the current page for backends that support multiple pages, but doesn't clear it, so that the contents of the current page will be retained for the next page. Use cairo.surface.Surface.showPage if you want to get an empty page after the emission.

createForRectangle
cairo.surface.Surface createForRectangle(double x, double y, double width, double height)

Create a new surface that is a rectangle within the target surface. All operations drawn to this surface are then clipped and translated onto the target surface. Nothing drawn via this sub-surface outside of its bounds is drawn onto the target surface, making this a useful method for passing constrained child surfaces to library routines that draw directly onto the parent surface, i.e. with no further backend allocations, double buffering or copies.

createObserver
cairo.surface.Surface createObserver(cairo.types.SurfaceObserverMode mode)

Create a new surface that exists solely to watch another is doing. In the process it will log operations and times, which are fast, which are slow, which are frequent, etc.

createSimilar
cairo.surface.Surface createSimilar(cairo.types.Content content, int width, int height)

Create a new surface that is as compatible as possible with an existing surface. For example the new surface will have the same device scale, fallback resolution and font options as other. Generally, the new surface will also use the same backend as other, unless that is not possible for some reason. The type of the returned surface may be examined with cairo.surface.Surface.getSurfaceType.

createSimilarImage
cairo.surface.Surface createSimilarImage(cairo.types.Format format, int width, int height)

Create a new image surface that is as compatible as possible for uploading to and the use in conjunction with an existing surface. However, this surface can still be used like any normal image surface. Unlike cairo.surface.Surface.createSimilar the new image surface won't inherit the device scale from other.

finish
void finish()

This function finishes the surface and drops all references to external resources. For example, for the Xlib backend it means that cairo will no longer access the drawable, which can be freed. After calling cairo.surface.Surface.finish the only valid operations on a surface are checking status, getting and setting user, referencing and destroying, and flushing and finishing it. Further drawing to the surface will not affect the surface but will instead trigger a cairo.types.Status.SurfaceFinished error.

flush
void flush()

Do any pending drawing for the surface and also restore any temporary modifications cairo has made to the surface's state. This function must be called before switching from drawing on the surface with cairo to drawing on it directly with native APIs, or accessing its memory outside of Cairo. If the surface doesn't support direct access, then this function does nothing.

getContent
cairo.types.Content getContent()

This function returns the content type of surface which indicates whether the surface contains color and/or alpha information. See #cairo_content_t.

getDevice
cairo.device.Device getDevice()

This function returns the device for a surface. See #cairo_device_t.

getDeviceOffset
void getDeviceOffset(double xOffset, double yOffset)

This function returns the previous device offset set by cairo.surface.Surface.setDeviceOffset.

getDeviceScale
void getDeviceScale(double xScale, double yScale)

This function returns the previous device scale set by cairo.surface.Surface.setDeviceScale.

getFallbackResolution
void getFallbackResolution(double xPixelsPerInch, double yPixelsPerInch)

This function returns the previous fallback resolution set by cairo.surface.Surface.setFallbackResolution, or default fallback resolution if never set.

getFontOptions
void getFontOptions(cairo.font_options.FontOptions options)

Retrieves the default font rendering options for the surface. This allows display surfaces to report the correct subpixel order for rendering on them, print surfaces to disable hinting of metrics and so forth. The result can then be used with cairo.global.scaledFontCreate.

getMimeData
void getMimeData(string mimeType, ubyte[] data)

Return mime data previously attached to surface using the specified mime type. If no data has been attached with the given mime type, data is set null.

getSurfaceType
cairo.types.SurfaceType getSurfaceType()

This function returns the type of the backend used to create a surface. See #cairo_surface_type_t for available types.

getUserData
void* getUserData(cairo.types.UserDataKey key)

Return user data previously attached to surface using the specified key. If no user data has been attached with the given key this function returns null.

hasShowTextGlyphs
cairo.types.Bool hasShowTextGlyphs()

Returns whether the surface supports sophisticated cairo.context.Context.showTextGlyphs operations. That is, whether it actually uses the provided text and cluster data to a cairo.context.Context.showTextGlyphs call.

mapToImage
cairo.surface.Surface mapToImage(cairo.rectangle_int.RectangleInt extents)

Returns an image surface that is the most efficient mechanism for modifying the backing store of the target surface. The region retrieved may be limited to the extents or null for the whole surface

markDirty
void markDirty()

Tells cairo that drawing has been done to surface using means other than cairo, and that cairo should reread any cached areas. Note that you must call cairo.surface.Surface.flush before doing such drawing.

markDirtyRectangle
void markDirtyRectangle(int x, int y, int width, int height)

Like cairo.surface.Surface.markDirty, but drawing has been done only to the specified rectangle, so that cairo can retain cached contents for other parts of the surface.

observerElapsed
double observerElapsed()

Returns the total observation time.

observerPrint
cairo.types.Status observerPrint(cairo.types.WriteFunc writeFunc)

Prints the observer log using the given callback.

setDeviceOffset
void setDeviceOffset(double xOffset, double yOffset)

Sets an offset that is added to the device coordinates determined by the CTM when drawing to surface. One use case for this function is when we want to create a #cairo_surface_t that redirects drawing for a portion of an onscreen surface to an offscreen surface in a way that is completely invisible to the user of the cairo API. Setting a transformation via cairo.context.Context.translate isn't sufficient to do this, since functions like cairo.context.Context.deviceToUser will expose the hidden offset.

setDeviceScale
void setDeviceScale(double xScale, double yScale)

Sets a scale that is multiplied to the device coordinates determined by the CTM when drawing to surface. One common use for this is to render to very high resolution display devices at a scale factor, so that code that assumes 1 pixel will be a certain size will still work. Setting a transformation via cairo.context.Context.scale isn't sufficient to do this, since functions like cairo.context.Context.deviceToUser will expose the hidden scale.

setFallbackResolution
void setFallbackResolution(double xPixelsPerInch, double yPixelsPerInch)

Set the horizontal and vertical resolution for image fallbacks.

setMimeData
cairo.types.Status setMimeData(string mimeType, ubyte[] data, cairo.types.DestroyFunc destroy)

Attach an image in the format mime_type to surface. To remove the data from a surface, call this function with same mime type and null for data.

showPage
void showPage()

Emits and clears the current page for backends that support multiple pages. Use cairo.surface.Surface.copyPage if you don't want to clear the page.

status
cairo.types.Status status()

Checks whether an error has previously occurred for this surface.

supportsMimeType
cairo.types.Bool supportsMimeType(string mimeType)

Return whether surface supports mime_type.

unmapImage
void unmapImage(cairo.surface.Surface image)

Unmaps the image surface as returned from #cairo.surface.Surface.mapToImage.

writeToPng
cairo.types.Status writeToPng(string filename)

Writes the contents of surface to a new file filename as a PNG image.

writeToPngStream
cairo.types.Status writeToPngStream(cairo.types.WriteFunc writeFunc)

Writes the image surface to the write function.

Inherited Members

From Boxed

cInstancePtr
void* cInstancePtr;

Pointer to the C boxed value

getType
GType getType()

Get the GType of this boxed type.

gType
GType gType [@property getter]

Boxed GType property.

self
Boxed self()

Convenience method to return this cast to a type. For use in D with statements.

copy_
void* copy_()

Make a copy of the wrapped C boxed data.

boxedCopy
void* boxedCopy(void* cBoxed)

Copy a C boxed value using g_boxed_copy.

boxedFree
void boxedFree(void* cBoxed)

Free a C boxed value using g_boxed_free.