There are different subtypes of cairo surface for different drawing backends. This class is a base class for all subtypes and should not be used directly
Surfaces are reference-counted objects that should be used via Cairo::RefPtr.
Public Types | |
typedef cairo_surface_t | cobject |
The underlying C cairo surface type. | |
Public Member Functions | |
const cobject * | cobj () const |
Provides acces to the underlying C cairo surface. | |
cobject * | cobj () |
Provides acces to the underlying C cairo surface. | |
void | finish () |
This function finishes the surface and drops all references to external resources. | |
void | flush () |
Do any pending drawing for the surface and also restore any temporary modifications cairo has made to the surface's state. | |
void | get_device_offset (double &x_offset, double &y_offset) const |
Returns a previous device offset set by set_device_offset(). | |
void | get_font_options (FontOptions &options) const |
Retrieves the default font rendering options for the surface. | |
SurfaceType | get_type () const |
void | mark_dirty (int x, int y, int width, int height) |
Marks a rectangular area of the given surface dirty. | |
void | mark_dirty () |
Tells cairo to consider the data buffer dirty. | |
void | set_device_offset (double x_offset, double y_offset) |
Sets an offset that is added to the device coordinates determined by the CTM when drawing to surface. | |
void | set_fallback_resolution (double x_pixels_per_inch, double y_pixels_per_inch) |
Sets the fallback resolution of the image in dots per inch. | |
Surface (cairo_surface_t *cobject, bool has_reference=false) | |
Create a C++ wrapper for the C instance. | |
void | write_to_png (cairo_write_func_t write_func, void *closure) |
Writes the Surface to the write function. | |
void | write_to_png (const std::string &filename) |
Writes the contents of surface to a new file filename as a PNG image. | |
virtual | ~Surface () |
Static Public Member Functions | |
static RefPtr< Surface > | create (const RefPtr< Surface > other, Content content, int width, int height) |
Create a new surface that is as compatible as possible with an existing surface. | |
Protected Attributes | |
cobject * | m_cobject |
The underlying C cairo surface type that is wrapped by this Surface. |
typedef cairo_surface_t Cairo::Surface::cobject |
The underlying C cairo surface type.
Cairo::Surface::Surface | ( | cairo_surface_t * | cobject, | |
bool | has_reference = false | |||
) | [explicit] |
Create a C++ wrapper for the C instance.
This C++ instance should then be given to a RefPtr.
cobject | The C instance. | |
has_reference | Whether we already have a reference. Otherwise, the constructor will take an extra reference. |
virtual Cairo::Surface::~Surface | ( | ) | [virtual] |
const cobject* Cairo::Surface::cobj | ( | ) | const [inline] |
Provides acces to the underlying C cairo surface.
cobject* Cairo::Surface::cobj | ( | ) | [inline] |
Provides acces to the underlying C cairo surface.
static RefPtr<Surface> Cairo::Surface::create | ( | const RefPtr< Surface > | other, | |
Content | content, | |||
int | width, | |||
int | height | |||
) | [static] |
Create a new surface that is as compatible as possible with an existing surface.
The new surface will use the same backend as other unless that is not possible for some reason.
other | an existing surface used to select the backend of the new surface | |
content | the content for the new surface | |
width | width of the new surface, (in device-space units) | |
height | height of the new surface (in device-space units) |
void Cairo::Surface::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 finish() the only valid operations on a surface are getting and setting user data and referencing and destroying it. Further drawing to the surface will not affect the surface but will instead trigger a CAIRO_STATUS_SURFACE_FINISHED error.
When the Surface is destroyed, cairo will call finish() if it hasn't been called already, before freeing the resources associated with the Surface.
void Cairo::Surface::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. If the surface doesn't support direct access, then this function does nothing.
void Cairo::Surface::get_device_offset | ( | double & | x_offset, | |
double & | y_offset | |||
) | const |
Returns a previous device offset set by set_device_offset().
void Cairo::Surface::get_font_options | ( | FontOptions & | options | ) | const |
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_scaled_font_create().
options | a FontOptions object into which to store the retrieved options. All existing values are overwritten |
SurfaceType Cairo::Surface::get_type | ( | ) | const |
void Cairo::Surface::mark_dirty | ( | int | x, | |
int | y, | |||
int | width, | |||
int | height | |||
) |
Marks a rectangular area of the given surface dirty.
x | X coordinate of dirty rectangle | |
y | Y coordinate of dirty rectangle | |
width | width of dirty rectangle | |
height | height of dirty rectangle |
void Cairo::Surface::mark_dirty | ( | ) |
Tells cairo to consider the data buffer dirty.
In particular, if you've created an ImageSurface with a data buffer that you've allocated yourself and you draw to that data buffer using means other than cairo, you must call mark_dirty() before doing any additional drawing to that surface with cairo.
Note that if you do draw to the Surface outside of cairo, you must call flush() before doing the drawing.
void Cairo::Surface::set_device_offset | ( | double | x_offset, | |
double | y_offset | |||
) |
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 Surface 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_translate() isn't sufficient to do this, since functions like Cairo::Context::device_to_user() will expose the hidden offset.
Note that the offset only affects drawing to the surface, not using the surface in a surface pattern.
x_offset | the offset in the X direction, in device units | |
y_offset | the offset in the Y direction, in device units |
void Cairo::Surface::set_fallback_resolution | ( | double | x_pixels_per_inch, | |
double | y_pixels_per_inch | |||
) |
Sets the fallback resolution of the image in dots per inch.
x_pixels_per_inch | Pixels per inch in the x direction | |
y_pixels_per_inch | Pixels per inch in the y direction |
void Cairo::Surface::write_to_png | ( | cairo_write_func_t | write_func, | |
void * | closure | |||
) |
Writes the Surface to the write function.
write_func | The function to be called when the backend needs to write data to an output stream | |
closure | closure data for the write function |
void Cairo::Surface::write_to_png | ( | const std::string & | filename | ) |
Writes the contents of surface to a new file filename as a PNG image.
filename | the name of a file to write to |
cobject* Cairo::Surface::m_cobject [protected] |
The underlying C cairo surface type that is wrapped by this Surface.