📄 cairo-surface.c
字号:
* After calling cairo_surface_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 last call to cairo_surface_destroy() decreases the * reference count to zero, cairo will call cairo_surface_finish() if * it hasn't been called already, before freeing the resources * associated with the surface. **/voidcairo_surface_finish (cairo_surface_t *surface){ cairo_status_t status; if (surface->finished) { _cairo_surface_set_error (surface, CAIRO_STATUS_SURFACE_FINISHED); return; } if (surface->backend->finish == NULL) { surface->finished = TRUE; return; } if (!surface->status && surface->backend->flush) { status = surface->backend->flush (surface); if (status) { _cairo_surface_set_error (surface, status); return; } } status = surface->backend->finish (surface); if (status) { _cairo_surface_set_error (surface, status); return; } surface->finished = TRUE;}/** * cairo_surface_get_user_data: * @surface: a #cairo_surface_t * @key: the address of the #cairo_user_data_key_t the user data was * attached to * * 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. * * Return value: the user data previously attached or %NULL. **/void *cairo_surface_get_user_data (cairo_surface_t *surface, const cairo_user_data_key_t *key){ return _cairo_user_data_array_get_data (&surface->user_data, key);}/** * cairo_surface_set_user_data: * @surface: a #cairo_surface_t * @key: the address of a #cairo_user_data_key_t to attach the user data to * @user_data: the user data to attach to the surface * @destroy: a #cairo_destroy_func_t which will be called when the * surface is destroyed or when new user data is attached using the * same key. * * Attach user data to @surface. To remove user data from a surface, * call this function with the key that was used to set it and %NULL * for @data. * * Return value: %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY if a * slot could not be allocated for the user data. **/cairo_status_tcairo_surface_set_user_data (cairo_surface_t *surface, const cairo_user_data_key_t *key, void *user_data, cairo_destroy_func_t destroy){ if (surface->ref_count == -1) return CAIRO_STATUS_NO_MEMORY; return _cairo_user_data_array_set_data (&surface->user_data, key, user_data, destroy);}/** * cairo_surface_get_font_options: * @surface: a #cairo_surface_t * @options: a #cairo_font_options_t object into which to store * the retrieved options. All existing values are overwritten * * 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(). **/voidcairo_surface_get_font_options (cairo_surface_t *surface, cairo_font_options_t *options){ if (!surface->finished && surface->backend->get_font_options) { surface->backend->get_font_options (surface, options); } else { _cairo_font_options_init_default (options); }}/** * cairo_surface_flush: * @surface: a #cairo_surface_t * * Do any pending drawing for the surface and also restore any * temporary modification's 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. **/voidcairo_surface_flush (cairo_surface_t *surface){ if (surface->status) return; if (surface->finished) { _cairo_surface_set_error (surface, CAIRO_STATUS_SURFACE_FINISHED); return; } if (surface->backend->flush) { cairo_status_t status; status = surface->backend->flush (surface); if (status) _cairo_surface_set_error (surface, status); }}/** * cairo_surface_mark_dirty: * @surface: a #cairo_surface_t * * 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_flush() before doing such drawing. */voidcairo_surface_mark_dirty (cairo_surface_t *surface){ assert (! surface->is_snapshot); cairo_surface_mark_dirty_rectangle (surface, 0, 0, -1, -1);}/** * cairo_surface_mark_dirty_rectangle: * @surface: a #cairo_surface_t * @x: X coordinate of dirty rectangle * @y: Y coordinate of dirty rectangle * @width: width of dirty rectangle * @height: height of dirty rectangle * * Like cairo_surface_mark_dirty(), but drawing has been done only to * the specified rectangle, so that cairo can retain cached contents * for other parts of the surface. * * Any cached clip set on the surface will be reset by this function, * to make sure that future cairo calls have the clip set that they * expect. */voidcairo_surface_mark_dirty_rectangle (cairo_surface_t *surface, int x, int y, int width, int height){ assert (! surface->is_snapshot); if (surface->status) return; if (surface->finished) { _cairo_surface_set_error (surface, CAIRO_STATUS_SURFACE_FINISHED); return; } /* Always reset the clip here, to avoid having external calls to * clip manipulation functions of the underlying device clip result * in a desync between the cairo clip and the backend clip, due to * the clip caching. */ surface->current_clip_serial = -1; if (surface->backend->mark_dirty_rectangle) { cairo_status_t status; /* XXX: FRAGILE: We're ignoring the scaling component of * device_transform here. I don't know what the right thing to * do would actually be if there were some scaling here, but * we avoid this since device_transfom scaling is not exported * publicly and mark_dirty is not used internally. */ status = surface->backend->mark_dirty_rectangle (surface, x + surface->device_transform.x0, y + surface->device_transform.y0, width, height); if (status) _cairo_surface_set_error (surface, status); }}/** * _cairo_surface_set_device_scale: * @surface: a #cairo_surface_t * @sx: a scale factor in the X direction * @sy: a scale factor in the Y direction * * Private function for setting an extra scale factor to affect all * drawing to a surface. This is used, for example, when replaying a * meta surface to an image fallback intended for an eventual * vector-oriented backend. Since the meta surface will record * coordinates in one backend space, but the image fallback uses a * different backend space, (differing by the fallback resolution * scale factors), we need a scale factor correction. * * Caution: There is no guarantee that a surface with both a * device_scale and a device_offset will be treated in consistent * fashion. So, for now, just don't do that. (And we'll need to * examine this issue in more detail if we were to ever want to export * support for device scaling.) **/void_cairo_surface_set_device_scale (cairo_surface_t *surface, double sx, double sy){ assert (! surface->is_snapshot); if (surface->status) return; if (surface->finished) { _cairo_surface_set_error (surface, CAIRO_STATUS_SURFACE_FINISHED); return; } surface->device_transform.xx = sx; surface->device_transform.yy = sy; surface->device_transform_inverse.xx = 1.0 / sx; surface->device_transform_inverse.yy = 1.0 / sy;}/** * cairo_surface_set_device_offset: * @surface: a #cairo_surface_t * @x_offset: the offset in the X direction, in device units * @y_offset: the offset in the Y direction, in device units * * 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_translate() isn't * sufficient to do this, since functions like * cairo_device_to_user() will expose the hidden offset. * * Note that the offset affects drawing to the surface as well as * using the surface in a source pattern. **/voidcairo_surface_set_device_offset (cairo_surface_t *surface, double x_offset, double y_offset){ assert (! surface->is_snapshot); if (surface->status) return; if (surface->finished) { _cairo_surface_set_error (surface, CAIRO_STATUS_SURFACE_FINISHED); return; } surface->device_transform.x0 = x_offset; surface->device_transform.y0 = y_offset; surface->device_transform_inverse.x0 = - x_offset; surface->device_transform_inverse.y0 = - y_offset;}/** * cairo_surface_get_device_offset: * @surface: a #cairo_surface_t * @x_offset: the offset in the X direction, in device units * @y_offset: the offset in the Y direction, in device units * * This function returns the previous device offset set by * cairo_surface_set_device_offset(). * * Since: 1.2 **/voidcairo_surface_get_device_offset (cairo_surface_t *surface, double *x_offset, double *y_offset){ *x_offset = surface->device_transform.x0; *y_offset = surface->device_transform.y0;}/** * cairo_surface_set_fallback_resolution: * @surface: a #cairo_surface_t * @x_pixels_per_inch: horizontal setting for pixels per inch * @y_pixels_per_inch: vertical setting for pixels per inch * * Set the horizontal and vertical resolution for image fallbacks. * * When certain operations aren't supported natively by a backend, * cairo will fallback by rendering operations to an image and then * overlaying that image onto the output. For backends that are * natively vector-oriented, this function can be used to set the * resolution used for these image fallbacks, (larger values will * result in more detailed images, but also larger file sizes). * * Some examples of natively vector-oriented backends are the ps, pdf, * and svg backends. * * For backends that are natively raster-oriented, image fallbacks are * still possible, but they are always performed at the native * device resolution. So this function has no effect on those * backends. * * NOTE: The fallback resolution only takes effect at the time of * completing a page (with cairo_show_page() or cairo_copy_page()) so * there is currently no way to have more than one fallback resolution * in effect on a single page. * * Since: 1.2 **/voidcairo_surface_set_fallback_resolution (cairo_surface_t *surface, double x_pixels_per_inch, double y_pixels_per_inch){ surface->x_fallback_resolution = x_pixels_per_inch; surface->y_fallback_resolution = y_pixels_per_inch;}cairo_bool_t_cairo_surface_has_device_transform (cairo_surface_t *surface){ return ! _cairo_matrix_is_identity (&surface->device_transform);}/** * _cairo_surface_acquire_source_image: * @surface: a #cairo_surface_t * @image_out: location to store a pointer to an image surface that * has identical contents to @surface. This surface could be @surface * itself, a surface held internal to @surface, or it could be a new * surface with a copy of the relevant portion of @surface. * @image_extra: location to store image specific backend data * * Gets an image surface to use when drawing as a fallback when drawing with * @surface as a source. _cairo_surface_release_source_image() must be called * when finished. * * Return value: %CAIRO_STATUS_SUCCESS if a an image was stored in @image_out. * %CAIRO_INT_STATUS_UNSUPPORTED if an image cannot be retrieved for the specified * surface. Or %CAIRO_STATUS_NO_MEMORY. **/cairo_status_t_cairo_surface_acquire_source_image (cairo_surface_t *surface, cairo_image_surface_t **image_out, void **image_extra){ assert (!surface->finished); return surface->backend->acquire_source_image (surface, image_out, image_extra);}/** * _cairo_surface_release_source_image: * @surface: a #cairo_surface_t * @image_extra: same as return from the matching _cairo_surface_acquire_source_image() * * Releases any resources obtained with _cairo_surface_acquire_source_image() **/void_cairo_surface_release_source_image (cairo_surface_t *surface, cairo_image_surface_t *image, void *image_extra){ assert (!surface->finished); if (surface->backend->release_source_image) surface->backend->release_source_image (surface, image, image_extra);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -