cairo.surface
Module for [Surface] class
Types 1
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].
Surface self()Returns `this`, for use in `with` statements.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.showP...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 ...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.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. Generall...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 surf...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. Aft...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 ...cairo.types.Content getContent()This function returns the content type of surface which indicates whether the surface contains color and/or alpha information. See #cairocontentt. Returns: The content type of surface.cairo.device.Device getDevice()This function returns the device for a surface. See #cairodevicet. Returns: The device for surface or null if the surface does not have an associated device.void getDeviceOffset(out double xOffset, out double yOffset)This function returns the previous device offset set by [cairo.surface.Surface.setDeviceOffset].void getDeviceScale(out double xScale, out double yScale)This function returns the previous device scale set by [cairo.surface.Surface.setDeviceScale].void getFallbackResolution(out double xPixelsPerInch, out double yPixelsPerInch)This function returns the previous fallback resolution set by [cairo.surface.Surface.setFallbackResolution], or default fallback resolution if never set.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 a...void getMimeData(string mimeType, out 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.cairo.types.SurfaceType getSurfaceType()This function returns the type of the backend used to create a surface. See #cairosurfacetype_t for available types. Returns: The type of surface.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.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.Conte...cairo.surface.Surface mapToImage(cairo.types.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 surfacevoid 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 suc...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.double observerElapsed()Returns the total observation time. Returns: the elapsed time, in nanosecondscairo.types.Status observerPrint(cairo.types.WriteFunc writeFunc)Prints the observer log using the given callback.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 #cairosurfacet that redirects drawin...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 fact...void setFallbackResolution(double xPixelsPerInch, double yPixelsPerInch)Set the horizontal and vertical resolution for image fallbacks.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.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.cairo.types.Status status()Checks whether an error has previously occurred for this surface. Returns: [cairo.types.Status.Success], [cairo.types.Status.NullPointer], [cairo.types.Status.NoMemory], [cairo.types.Status.ReadErr...cairo.types.Bool supportsMimeType(string mimeType)Return whether surface supports mime_type.void unmapImage(cairo.surface.Surface image)Unmaps the image surface as returned from #[cairo.surface.Surface.mapToImage].cairo.types.Status writeToPng(string filename)Writes the contents of surface to a new file filename as a PNG image.cairo.types.Status writeToPngStream(cairo.types.WriteFunc writeFunc)Writes the image surface to the write function.