/** *_cairo_surface_set_error: *@surface:asurface *@status:astatusvalueindicatinganerror * *Atomicallysetssurface->statusto@statusandcalls_cairo_error; *Doesnothingifstatusis%CAIRO_STATUS_SUCCESSoranyoftheinternal *statusvalues. * *Allassignmentsofanerrorstatustosurface->statusshouldhappen *through_cairo_surface_set_error().Notethatduetothenatureof *theatomicoperation,itisnotsafetocallthisfunctiononthe *nilobjects. * *Thepurposeofthisfunctionistoallowtheusertoseta *breakpointin_cairo_error()togenerateastacktraceforwhenthe *usercausescairotodetectanerror. * *Returnvalue:theerrorstatus.
**/
cairo_int_status_t
_cairo_surface_set_error (cairo_surface_t *surface,
cairo_int_status_t status)
{ /* NOTHING_TO_DO is magic. We use it to break out of the inner-most *surfacefunction,butanythinghigherjustsees"success".
*/ if (status == CAIRO_INT_STATUS_NOTHING_TO_DO)
status = CAIRO_INT_STATUS_SUCCESS;
if (status == CAIRO_INT_STATUS_SUCCESS ||
status >= (int)CAIRO_INT_STATUS_LAST_STATUS) return status;
/* Don't overwrite an existing error. This preserves the first
* error, which is the most significant. */
_cairo_status_set_error (&surface->status, (cairo_status_t)status);
return _cairo_error (status);
}
/** *cairo_surface_get_type: *@surface:a#cairo_surface_t * *Thisfunctionreturnsthetypeofthebackendusedtocreate *asurface.See#cairo_surface_type_tforavailabletypes. * *Returnvalue:Thetypeof@surface. * *Since:1.2
**/
cairo_surface_type_t
cairo_surface_get_type (cairo_surface_t *surface)
{ /* We don't use surface->backend->type here so that some of the *special"wrapper"surfacessuchascairo_paginated_surface_t *canoverridesurface->typewiththetypeofthe"child"
* surface. */ return surface->type;
}
/* We have to apply the translate from map_to_image's extents.x and .y */
cairo_matrix_init_translate (&pattern.base.matrix,
image->base.device_transform.x0,
image->base.device_transform.y0);
/* And we also have to clip the operation to the image's extents */
extents.x = image->base.device_transform_inverse.x0;
extents.y = image->base.device_transform_inverse.y0;
extents.width = image->width;
extents.height = image->height;
clip = _cairo_clip_intersect_rectangle (NULL, &extents);
status = _cairo_surface_paint (surface,
CAIRO_OPERATOR_SOURCE,
&pattern.base,
clip);
/* If this surface is bounded, we can't map parts
* that are outside of it. */ if (likely (surface->backend->get_extents (surface, &surface_extents))) { if (unlikely (! _cairo_rectangle_contains_rectangle (&surface_extents, extents))) return _cairo_surface_create_in_error (CAIRO_STATUS_INVALID_SIZE);
}
}
if (! _cairo_reference_count_dec_and_test (&surface->ref_count)) return;
assert (surface->snapshot_of == NULL);
if (! surface->finished) {
_cairo_surface_finish_snapshots (surface); /* We may have been referenced by a snapshot prior to have *detachingitwiththecopy-on-write.
*/ if (CAIRO_REFERENCE_COUNT_GET_VALUE (&surface->ref_count)) return;
_cairo_surface_finish (surface);
}
if (surface->damage)
_cairo_damage_destroy (surface->damage);
/* update the snapshots *before* we declare the surface as finished */
surface->_finishing = TRUE;
status = _cairo_surface_flush (surface, 0);
(void) status;
}
/* call finish even if in error mode */ if (surface->backend->finish) {
status = surface->backend->finish (surface); if (unlikely (status))
_cairo_surface_set_error (surface, status);
}
/* Prevent reads of the array during teardown */ if (! CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&surface->ref_count)) return;
/* The number of mime-types attached to a surface is usually small, *typicallyzero.Thereforeitisquickertodoastrcmp()against *eachkeythanitistointernthestring(i.e.computeahash, *searchthehashtable,anddoafinalstrcmp).
*/
num_slots = surface->mime_data.num_elements;
slots = _cairo_array_index (&surface->mime_data, 0); for (i = 0; i < num_slots; i++) { if (slots[i].key != NULL && strcmp ((char *) slots[i].key, mime_type) == 0) {
cairo_mime_data_t *mime_data = slots[i].user_data;
cairo_bool_t
_cairo_surface_has_mime_image (cairo_surface_t *surface)
{
cairo_user_data_slot_t *slots; int i, j, num_slots;
/* Prevent reads of the array during teardown */ if (! CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&surface->ref_count)) returnFALSE;
/* The number of mime-types attached to a surface is usually small, *typicallyzero.Thereforeitisquickertodoastrcmp()against *eachkeythanitistointernthestring(i.e.computeahash, *searchthehashtable,anddoafinalstrcmp).
*/
num_slots = surface->mime_data.num_elements;
slots = _cairo_array_index (&surface->mime_data, 0); for (i = 0; i < num_slots; i++) { if (slots[i].key != NULL) { for (j = 0; j < ARRAY_LENGTH (_cairo_surface_image_mime_types); j++) { if (strcmp ((char *) slots[i].key, _cairo_surface_image_mime_types[j]) == 0) return TRUE;
}
}
}
/**
* CAIRO_MIME_TYPE_UNIQUE_ID:
*
* Unique identifier for a surface (cairo specific MIME type). All surfaces with
* the same unique identifier will only be embedded once.
*
* Since: 1.12
**/
/**
* cairo_surface_set_mime_data:
* @surface: a #cairo_surface_t
* @mime_type: the MIME type of the image data
* @data: the image data to attach to the surface
* @length: the length of the image data
* @destroy: a #cairo_destroy_func_t which will be called when the
* surface is destroyed or when new image data is attached using the
* same mime type.
* @closure: the data to be passed to the @destroy notifier
*
* 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.
*
* The attached image (or filename) data can later be used by backends
* which support it (currently: PDF, PS, SVG and Win32 Printing
* surfaces) to emit this data instead of making a snapshot of the
* @surface. This approach tends to be faster and requires less
* memory and disk space.
*
* The recognized MIME types are the following: %CAIRO_MIME_TYPE_JPEG,
* %CAIRO_MIME_TYPE_PNG, %CAIRO_MIME_TYPE_JP2, %CAIRO_MIME_TYPE_URI,
* %CAIRO_MIME_TYPE_UNIQUE_ID, %CAIRO_MIME_TYPE_JBIG2,
* %CAIRO_MIME_TYPE_JBIG2_GLOBAL, %CAIRO_MIME_TYPE_JBIG2_GLOBAL_ID,
* %CAIRO_MIME_TYPE_CCITT_FAX, %CAIRO_MIME_TYPE_CCITT_FAX_PARAMS.
*
* See corresponding backend surface docs for details about which MIME
* types it can handle. Caution: the associated MIME data will be
* discarded if you draw on the surface afterwards. Use this function
* with care.
*
* Even if a backend supports a MIME type, that does not mean cairo
* will always be able to use the attached MIME data. For example, if
* the backend does not natively support the compositing operation used
* to apply the MIME data to the backend. In that case, the MIME data
* will be ignored. Therefore, to apply an image in all cases, it is best
* to create an image surface which contains the decoded image data and
* then attach the MIME data to that. This ensures the image will always
* be used while still allowing the MIME data to be used whenever
* possible.
*
* Return value: %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY if a
* slot could not be allocated for the user data.
*
* Since: 1.10
**/
cairo_status_t
cairo_surface_set_mime_data (cairo_surface_t *surface,
const char *mime_type,
const unsigned char *data,
unsigned long length,
cairo_destroy_func_t destroy,
void *closure)
{
cairo_status_t status;
cairo_mime_data_t *mime_data;
if (CAIRO_REFERENCE_COUNT_IS_INVALID (&surface->ref_count))
return surface->status;
if (! CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&surface->ref_count))
return _cairo_error (CAIRO_STATUS_SURFACE_FINISHED);
if (unlikely (surface->status))
return surface->status;
if (unlikely (surface->finished))
return _cairo_surface_set_error (surface, _cairo_error (CAIRO_STATUS_SURFACE_FINISHED));
status = _cairo_intern_string (&mime_type, -1);
if (unlikely (status))
return _cairo_surface_set_error (surface, status);
if (data != NULL) {
mime_data = _cairo_calloc (sizeof (cairo_mime_data_t));
if (unlikely (mime_data == NULL))
return _cairo_surface_set_error (surface, _cairo_error (CAIRO_STATUS_NO_MEMORY));
if (src->status)
return _cairo_surface_set_error (dst, src->status);
/* first copy the mime-data, discarding any already set on dst */
status = _cairo_user_data_array_copy (&dst->mime_data, &src->mime_data);
if (unlikely (status))
return _cairo_surface_set_error (dst, status);
/* now increment the reference counters for the copies */
_cairo_user_data_array_foreach (&dst->mime_data,
_cairo_mime_data_reference,
NULL);
dst->is_clear = FALSE;
return CAIRO_STATUS_SUCCESS;
}
/**
* _cairo_surface_set_font_options:
* @surface: a #cairo_surface_t
* @options: a #cairo_font_options_t object that contains the
* options to use for this surface instead of backend's default
* font options.
*
* Sets the default font rendering options for the surface.
* This is useful to correctly propagate default font options when
* falling back to an image surface in a backend implementation.
* This affects the options returned in cairo_surface_get_font_options().
*
* If @options is %NULL the surface options are reset to those of
* the backend default.
**/
void
_cairo_surface_set_font_options (cairo_surface_t *surface,
cairo_font_options_t *options)
{
if (surface->status)
return;
assert (surface->snapshot_of == NULL);
if (surface->finished) {
_cairo_surface_set_error (surface, _cairo_error (CAIRO_STATUS_SURFACE_FINISHED));
return;
}
/**
* 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().
*
* Since: 1.0
**/
void
cairo_surface_get_font_options (cairo_surface_t *surface,
cairo_font_options_t *options)
{
if (cairo_font_options_status (options))
return;
if (surface->status) {
_cairo_font_options_init_default (options);
return;
}
if (! surface->has_font_options) {
surface->has_font_options = TRUE;
/**
* cairo_surface_set_subpixel_antialiasing:
* @surface: a #cairo_surface_t
*
* Sets whether the surface permits subpixel antialiasing. By default,
* surfaces permit subpixel antialiasing.
*
* Enabling subpixel antialiasing for CONTENT_COLOR_ALPHA surfaces generally
* requires that the pixels in the areas under a subpixel antialiasing
* operation already be opaque.
**/
void
cairo_surface_set_subpixel_antialiasing (cairo_surface_t *surface,
cairo_subpixel_antialiasing_t enabled)
{
if (surface->status)
return;
if (surface->finished) {
_cairo_surface_set_error (surface, CAIRO_STATUS_SURFACE_FINISHED);
return;
}
/**
* cairo_surface_get_subpixel_antialiasing:
* @surface: a #cairo_surface_t
*
* Gets whether the surface supports subpixel antialiasing. By default,
* CAIRO_CONTENT_COLOR surfaces support subpixel antialiasing but other
* surfaces do not.
**/
cairo_subpixel_antialiasing_t
cairo_surface_get_subpixel_antialiasing (cairo_surface_t *surface)
{
if (surface->status)
return CAIRO_SUBPIXEL_ANTIALIASING_DISABLED;
cairo_status_t
_cairo_surface_flush (cairo_surface_t *surface, unsigned flags)
{
/* update the current snapshots *before* the user updates the surface */
_cairo_surface_detach_snapshots (surface);
if (surface->snapshot_of != NULL)
_cairo_surface_detach_snapshot (surface);
_cairo_surface_detach_mime_data (surface);
return __cairo_surface_flush (surface, flags);
}
/**
* cairo_surface_flush:
* @surface: a #cairo_surface_t
*
* 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.
*
* Since: 1.0
**/
void
cairo_surface_flush (cairo_surface_t *surface)
{
cairo_status_t status;
if (surface->status)
return;
if (surface->finished)
return;
status = _cairo_surface_flush (surface, 0);
if (unlikely (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.
*
* Since: 1.0
**/
void
cairo_surface_mark_dirty (cairo_surface_t *surface)
{
cairo_rectangle_int_t extents;
if (unlikely (surface->status))
return;
if (unlikely (surface->finished)) {
_cairo_surface_set_error (surface, _cairo_error (CAIRO_STATUS_SURFACE_FINISHED));
return;
}
/**
* 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.
*
* Since: 1.0
**/
void
cairo_surface_mark_dirty_rectangle (cairo_surface_t *surface,
int x,
int y,
int width,
int height)
{
cairo_status_t status;
if (unlikely (surface->status))
return;
assert (surface->snapshot_of == NULL);
if (unlikely (surface->finished)) {
_cairo_surface_set_error (surface, _cairo_error (CAIRO_STATUS_SURFACE_FINISHED));
return;
}
/* The application *should* have called cairo_surface_flush() before
* modifying the surface independently of cairo (and thus having to
* call mark_dirty()). */
assert (! _cairo_surface_has_snapshots (surface));
assert (! _cairo_surface_has_mime_data (surface));
surface->is_clear = FALSE;
surface->serial++;
if (surface->damage) {
cairo_box_t box;
box.p1.x = x;
box.p1.y = y;
box.p2.x = x + width;
box.p2.y = y + height;
if (surface->backend->mark_dirty_rectangle != NULL) {
/* 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 (unlikely (status))
_cairo_surface_set_error (surface, status);
}
}
/**
* cairo_surface_set_device_scale:
* @surface: a #cairo_surface_t
* @x_scale: a scale factor in the X direction
* @y_scale: a scale factor in the Y direction
*
* 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_scale() isn't
* sufficient to do this, since functions like
* cairo_device_to_user() will expose the hidden scale.
*
* Note that the scale affects drawing to the surface as well as
* using the surface in a source pattern.
*
* Since: 1.14
**/
void
cairo_surface_set_device_scale (cairo_surface_t *surface,
double x_scale,
double y_scale)
{
cairo_status_t status;
if (unlikely (surface->status))
return;
assert (surface->snapshot_of == NULL);
if (unlikely (surface->finished)) {
_cairo_surface_set_error (surface, _cairo_error (CAIRO_STATUS_SURFACE_FINISHED));
return;
}
status = _cairo_surface_begin_modification (surface);
if (unlikely (status)) {
_cairo_surface_set_error (surface, status);
return;
}
/**
* cairo_surface_get_device_scale:
* @surface: a #cairo_surface_t
* @x_scale: the scale in the X direction, in device units
* @y_scale: the scale in the Y direction, in device units
*
* This function returns the previous device scale set by
* cairo_surface_set_device_scale().
*
* Since: 1.14
**/
void
cairo_surface_get_device_scale (cairo_surface_t *surface,
double *x_scale,
double *y_scale)
{
if (x_scale)
*x_scale = surface->device_transform.xx;
if (y_scale)
*y_scale = surface->device_transform.yy;
}
/**
* 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.
*
* Since: 1.0
**/
void
cairo_surface_set_device_offset (cairo_surface_t *surface,
double x_offset,
double y_offset)
{
cairo_status_t status;
if (unlikely (surface->status))
return;
assert (surface->snapshot_of == NULL);
if (unlikely (surface->finished)) {
_cairo_surface_set_error (surface, _cairo_error (CAIRO_STATUS_SURFACE_FINISHED));
return;
}
status = _cairo_surface_begin_modification (surface);
if (unlikely (status)) {
_cairo_surface_set_error (surface, status);
return;
}
/**
* 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
**/
void
cairo_surface_get_device_offset (cairo_surface_t *surface,
double *x_offset,
double *y_offset)
{
if (x_offset)
*x_offset = surface->device_transform.x0;
if (y_offset)
*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.
*
* The default fallback resolution is 300 pixels per inch in both
* dimensions.
*
* Since: 1.2
**/
void
cairo_surface_set_fallback_resolution (cairo_surface_t *surface,
double x_pixels_per_inch,
double y_pixels_per_inch)
{
cairo_status_t status;
if (unlikely (surface->status))
return;
assert (surface->snapshot_of == NULL);
if (unlikely (surface->finished)) {
_cairo_surface_set_error (surface, _cairo_error (CAIRO_STATUS_SURFACE_FINISHED));
return;
}
if (x_pixels_per_inch <= 0 || y_pixels_per_inch <= 0) {
/* XXX Could delay raising the error until we fallback, but throwing
* the error here means that we can catch the real culprit.
*/
_cairo_surface_set_error (surface, CAIRO_STATUS_INVALID_MATRIX);
return;
}
status = _cairo_surface_begin_modification (surface);
if (unlikely (status)) {
_cairo_surface_set_error (surface, status);
return;
}
/**
* cairo_surface_get_fallback_resolution:
* @surface: a #cairo_surface_t
* @x_pixels_per_inch: horizontal pixels per inch
* @y_pixels_per_inch: vertical pixels per inch
*
* This function returns the previous fallback resolution set by
* cairo_surface_set_fallback_resolution(), or default fallback
* resolution if never set.
*
* Since: 1.8
**/
void
cairo_surface_get_fallback_resolution (cairo_surface_t *surface,
double *x_pixels_per_inch,
double *y_pixels_per_inch)
{
if (x_pixels_per_inch)
*x_pixels_per_inch = surface->x_fallback_resolution;
if (y_pixels_per_inch)
*y_pixels_per_inch = surface->y_fallback_resolution;
}
/**
* _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 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)
{
cairo_status_t status;
if (unlikely (surface->status))
return surface->status;
assert (!surface->finished);
if (surface->backend->acquire_source_image == NULL)
return CAIRO_INT_STATUS_UNSUPPORTED;
status = surface->backend->acquire_source_image (surface,
image_out, image_extra);
if (unlikely (status))
return _cairo_surface_set_error (surface, status);
TRACE ((stderr, "%s\n", __FUNCTION__));
if (unlikely (surface->status))
return surface->status;
if (unlikely (surface->finished))
return _cairo_surface_set_error (surface, _cairo_error (CAIRO_STATUS_SURFACE_FINISHED));
if (_cairo_clip_is_all_clipped (clip))
return CAIRO_STATUS_SUCCESS;
/* If the mask is blank, this is just an expensive no-op */
if (_cairo_pattern_is_clear (mask) &&
_cairo_operator_bounded_by_mask (op))
{
return CAIRO_STATUS_SUCCESS;
}
status = _pattern_has_error (source);
if (unlikely (status))
return status;
status = _pattern_has_error (mask);
if (unlikely (status))
return status;
if (nothing_to_do (surface, op, source))
return CAIRO_STATUS_SUCCESS;
status = _cairo_surface_begin_modification (surface);
if (unlikely (status))
return status;
/**
* cairo_surface_copy_page:
* @surface: a #cairo_surface_t
*
* 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_show_page() if you
* want to get an empty page after the emission.
*
* There is a convenience function for this that takes a #cairo_t,
* namely cairo_copy_page().
*
* Since: 1.6
**/
void
cairo_surface_copy_page (cairo_surface_t *surface)
{
if (unlikely (surface->status))
return;
assert (surface->snapshot_of == NULL);
if (unlikely (surface->finished)) {
_cairo_surface_set_error (surface, CAIRO_STATUS_SURFACE_FINISHED);
return;
}
/* It's fine if some backends don't implement copy_page */
if (surface->backend->copy_page == NULL)
return;
/**
* cairo_surface_show_page:
* @surface: a #cairo_Surface_t
*
* Emits and clears the current page for backends that support multiple
* pages. Use cairo_surface_copy_page() if you don't want to clear the page.
*
* There is a convenience function for this that takes a #cairo_t,
* namely cairo_show_page().
*
* Since: 1.6
**/
void
cairo_surface_show_page (cairo_surface_t *surface)
{
cairo_status_t status;
if (unlikely (surface->status))
return;
if (unlikely (surface->finished)) {
_cairo_surface_set_error (surface, CAIRO_STATUS_SURFACE_FINISHED);
return;
}
status = _cairo_surface_begin_modification (surface);
if (unlikely (status)) {
_cairo_surface_set_error (surface, status);
return;
}
/* It's fine if some backends don't implement show_page */
if (surface->backend->show_page == NULL)
return;
/**
* _cairo_surface_get_extents:
* @surface: the #cairo_surface_t to fetch extents for
*
* This function returns a bounding box for the surface. The surface
* bounds are defined as a region beyond which no rendering will
* possibly be recorded, in other words, it is the maximum extent of
* potentially usable coordinates.
*
* For vector surfaces, (PDF, PS, SVG and recording-surfaces), the surface
* might be conceived as unbounded, but we force the user to provide a
* maximum size at the time of surface_create. So get_extents uses
* that size.
*
* Note: The coordinates returned are in "backend" space rather than
* "surface" space. That is, they are relative to the true (0,0)
* origin rather than the device_transform origin. This might seem a
* bit inconsistent with other #cairo_surface_t interfaces, but all
* current callers are within the surface layer where backend space is
* desired.
*
* This behavior would have to be changed is we ever exported a public
* variant of this function.
**/
cairo_bool_t
_cairo_surface_get_extents (cairo_surface_t *surface,
cairo_rectangle_int_t *extents)
{
cairo_bool_t bounded;
if (unlikely (surface->status))
goto zero_extents;
if (unlikely (surface->finished)) {
_cairo_surface_set_error(surface, CAIRO_STATUS_SURFACE_FINISHED);
goto zero_extents;
}
/**
* cairo_surface_has_show_text_glyphs:
* @surface: a #cairo_surface_t
*
* Returns whether the surface supports
* sophisticated cairo_show_text_glyphs() operations. That is,
* whether it actually uses the provided text and cluster data
* to a cairo_show_text_glyphs() call.
*
* Note: Even if this function returns %FALSE, a
* cairo_show_text_glyphs() operation targeted at @surface will
* still succeed. It just will
* act like a cairo_show_glyphs() operation. Users can use this
* function to avoid computing UTF-8 text and cluster mapping if the
* target surface does not use it.
*
* Return value: %TRUE if @surface supports
* cairo_show_text_glyphs(), %FALSE otherwise
*
* Since: 1.8
**/
cairo_bool_t
cairo_surface_has_show_text_glyphs (cairo_surface_t *surface)
{
if (unlikely (surface->status))
return FALSE;
if (unlikely (surface->finished)) {
_cairo_surface_set_error (surface, CAIRO_STATUS_SURFACE_FINISHED);
return FALSE;
}
cache_index = glyph->index % GLYPH_CACHE_SIZE;
*scaled_glyph = glyph_cache[cache_index];
if (*scaled_glyph == NULL || _cairo_scaled_glyph_index (*scaled_glyph) != glyph->index) {
status = _cairo_scaled_glyph_lookup (scaled_font,
glyph->index,
CAIRO_SCALED_GLYPH_INFO_COLOR_SURFACE,
foreground_color,
scaled_glyph);
if (status == CAIRO_INT_STATUS_UNSUPPORTED) {
/* If the color surface not available, ensure scaled_glyph is not NULL. */
status = _cairo_scaled_glyph_lookup (scaled_font,
glyph->index,
CAIRO_SCALED_GLYPH_INFO_SURFACE,
NULL, /* foreground color */
scaled_glyph);
}
if (unlikely (status))
status = _cairo_scaled_font_set_error (scaled_font, status);
if (surface->is_vector)
cairo_scaled_font_destroy (scaled_font);
return status;
}
/* Note: the backends may modify the contents of the glyph array as long as
* they do not return %CAIRO_INT_STATUS_UNSUPPORTED. This makes it possible to
* avoid copying the array again and again, and edit it in-place.
* Backends are in fact free to use the array as a generic buffer as they
* see fit.
*
* For show_glyphs backend method, and NOT for show_text_glyphs method,
* when they do return UNSUPPORTED, they may adjust remaining_glyphs to notify
* that they have successfully rendered some of the glyphs (from the beginning
* of the array), but not all. If they don't touch remaining_glyphs, it
* defaults to all glyphs.
*
* See commits 5a9642c5746fd677aed35ce620ce90b1029b1a0c and
* 1781e6018c17909311295a9cc74b70500c6b4d0a for the rationale.
*/
cairo_status_t
_cairo_surface_show_text_glyphs (cairo_surface_t *surface,
cairo_operator_t op,
const cairo_pattern_t *source,
const char *utf8,
int utf8_len,
cairo_glyph_t *glyphs,
int num_glyphs,
const cairo_text_cluster_t *clusters,
int num_clusters,
cairo_text_cluster_flags_t cluster_flags,
cairo_scaled_font_t *scaled_font,
const cairo_clip_t *clip)
{
cairo_int_status_t status;
char *utf8_copy = NULL;
TRACE ((stderr, "%s\n", __FUNCTION__));
if (unlikely (surface->status))
return surface->status;
if (unlikely (surface->finished))
return _cairo_surface_set_error (surface, _cairo_error (CAIRO_STATUS_SURFACE_FINISHED));
if (num_glyphs == 0 && utf8_len == 0)
return CAIRO_STATUS_SUCCESS;
if (_cairo_clip_is_all_clipped (clip))
return CAIRO_STATUS_SUCCESS;
status = _pattern_has_error (source);
if (unlikely (status))
return status;
status = cairo_scaled_font_status (scaled_font);
if (unlikely (status))
return status;
if (!(_cairo_scaled_font_has_color_glyphs (scaled_font) &&
scaled_font->options.color_mode != CAIRO_COLOR_MODE_NO_COLOR))
{
if (nothing_to_do (surface, op, source))
return CAIRO_STATUS_SUCCESS;
}
status = _cairo_surface_begin_modification (surface);
if (unlikely (status))
return status;
if (source->is_foreground_marker && surface->foreground_source)
source = surface->foreground_source;
/* The logic here is duplicated in _cairo_analysis_surface show_glyphs and
* show_text_glyphs. Keep in synch. */
if (clusters) {
status = CAIRO_INT_STATUS_UNSUPPORTED;
/* A real show_text_glyphs call. Try show_text_glyphs backend
* method first */
if (surface->backend->show_text_glyphs != NULL) {
status = surface->backend->show_text_glyphs (surface, op,
source,
utf8, utf8_len,
glyphs, num_glyphs,
clusters, num_clusters, cluster_flags,
scaled_font,
clip);
}
if (status == CAIRO_INT_STATUS_UNSUPPORTED &&
surface->backend->show_glyphs)
{
status = surface->backend->show_glyphs (surface, op,
source,
glyphs, num_glyphs,
scaled_font,
clip);
}
} else {
/* A mere show_glyphs call. Try show_glyphs backend method first */
if (surface->backend->show_glyphs != NULL) {
status = surface->backend->show_glyphs (surface, op,
source,
glyphs, num_glyphs,
scaled_font,
clip);
} else if (surface->backend->show_text_glyphs != NULL) {
/* Intentionally only try show_text_glyphs method for show_glyphs
* calls if backend does not have show_glyphs. If backend has
* both methods implemented, we don't fallback from show_glyphs to
* show_text_glyphs, and hence the backend can assume in its
* show_text_glyphs call that clusters is not NULL (which also
* implies that UTF-8 is not NULL, unless the text is
* zero-length).
*/
status = surface->backend->show_text_glyphs (surface, op,
source,
utf8, utf8_len,
glyphs, num_glyphs,
clusters, num_clusters, cluster_flags,
scaled_font,
clip);
}
}
cairo_bool_t
_cairo_surface_supports_color_glyph (cairo_surface_t *surface,
cairo_scaled_font_t *scaled_font,
unsigned long glyph_index)
{
if (surface->backend->supports_color_glyph != NULL)
return surface->backend->supports_color_glyph (surface, scaled_font, glyph_index);
return FALSE;
}
/**
* _cairo_surface_set_resolution:
* @surface: the surface
* @x_res: x resolution, in dpi
* @y_res: y resolution, in dpi
*
* Set the actual surface resolution of @surface to the given x and y DPI.
* Mainly used for correctly computing the scale factor when fallback
* rendering needs to take place in the paginated surface.
**/
void
_cairo_surface_set_resolution (cairo_surface_t *surface,
double x_res,
double y_res)
{
if (surface->status)
return;
/**
* _cairo_surface_create_in_error:
* @status: the error status
*
* Return an appropriate static error surface for the error status.
* On error, surface creation functions should always return a surface
* created with _cairo_surface_create_in_error() instead of a new surface
* in an error state. This simplifies internal code as no refcounting has
* to be done.
**/
cairo_surface_t *
_cairo_surface_create_in_error (cairo_status_t status)
{
assert (status < CAIRO_STATUS_LAST_STATUS);
switch (status) {
case CAIRO_STATUS_NO_MEMORY:
return (cairo_surface_t *) &_cairo_surface_nil;
case CAIRO_STATUS_SURFACE_TYPE_MISMATCH:
return (cairo_surface_t *) &_cairo_surface_nil_surface_type_mismatch;
case CAIRO_STATUS_INVALID_STATUS:
return (cairo_surface_t *) &_cairo_surface_nil_invalid_status;
case CAIRO_STATUS_INVALID_CONTENT:
return (cairo_surface_t *) &_cairo_surface_nil_invalid_content;
case CAIRO_STATUS_INVALID_FORMAT:
return (cairo_surface_t *) &_cairo_surface_nil_invalid_format;
case CAIRO_STATUS_INVALID_VISUAL:
return (cairo_surface_t *) &_cairo_surface_nil_invalid_visual;
case CAIRO_STATUS_READ_ERROR:
return (cairo_surface_t *) &_cairo_surface_nil_read_error;
case CAIRO_STATUS_WRITE_ERROR:
return (cairo_surface_t *) &_cairo_surface_nil_write_error;
case CAIRO_STATUS_FILE_NOT_FOUND:
return (cairo_surface_t *) &_cairo_surface_nil_file_not_found;
case CAIRO_STATUS_TEMP_FILE_ERROR:
return (cairo_surface_t *) &_cairo_surface_nil_temp_file_error;
case CAIRO_STATUS_INVALID_STRIDE:
return (cairo_surface_t *) &_cairo_surface_nil_invalid_stride;
case CAIRO_STATUS_INVALID_SIZE:
return (cairo_surface_t *) &_cairo_surface_nil_invalid_size;
case CAIRO_STATUS_DEVICE_TYPE_MISMATCH:
return (cairo_surface_t *) &_cairo_surface_nil_device_type_mismatch;
case CAIRO_STATUS_DEVICE_ERROR:
return (cairo_surface_t *) &_cairo_surface_nil_device_error;
case CAIRO_STATUS_PNG_ERROR:
return (cairo_surface_t *) &_cairo_surface_nil_png_error;
case CAIRO_STATUS_SUCCESS:
case CAIRO_STATUS_LAST_STATUS:
ASSERT_NOT_REACHED;
/* fall-through */
case CAIRO_STATUS_INVALID_RESTORE:
case CAIRO_STATUS_INVALID_POP_GROUP:
case CAIRO_STATUS_NO_CURRENT_POINT:
case CAIRO_STATUS_INVALID_MATRIX:
case CAIRO_STATUS_NULL_POINTER:
case CAIRO_STATUS_INVALID_STRING:
case CAIRO_STATUS_INVALID_PATH_DATA:
case CAIRO_STATUS_SURFACE_FINISHED:
case CAIRO_STATUS_PATTERN_TYPE_MISMATCH:
case CAIRO_STATUS_INVALID_DASH:
case CAIRO_STATUS_INVALID_DSC_COMMENT:
case CAIRO_STATUS_INVALID_INDEX:
case CAIRO_STATUS_CLIP_NOT_REPRESENTABLE:
case CAIRO_STATUS_FONT_TYPE_MISMATCH:
case CAIRO_STATUS_USER_FONT_IMMUTABLE:
case CAIRO_STATUS_USER_FONT_ERROR:
case CAIRO_STATUS_NEGATIVE_COUNT:
case CAIRO_STATUS_INVALID_CLUSTERS:
case CAIRO_STATUS_INVALID_SLANT:
case CAIRO_STATUS_INVALID_WEIGHT:
case CAIRO_STATUS_USER_FONT_NOT_IMPLEMENTED:
case CAIRO_STATUS_INVALID_MESH_CONSTRUCTION:
case CAIRO_STATUS_DEVICE_FINISHED:
case CAIRO_STATUS_JBIG2_GLOBAL_MISSING:
case CAIRO_STATUS_FREETYPE_ERROR:
case CAIRO_STATUS_WIN32_GDI_ERROR:
case CAIRO_INT_STATUS_DWRITE_ERROR:
case CAIRO_STATUS_TAG_ERROR:
case CAIRO_STATUS_SVG_FONT_ERROR:
default:
_cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
return (cairo_surface_t *) &_cairo_surface_nil;
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.