[cairo] [cairo-commit] 12 commits - src/cairo-analysis-surface.c src/cairo-directfb-surface.c src/cairo-gstate.c src/cairo.h src/cairoint.h src/cairo-jpeg-info.c src/cairo-jpeg-info-private.h src/cairo-meta-surface.c src/cairo-meta-surface-private.h src/cairo-paginated-surface.c src/cairo-pdf-surface.c src/cairo-pdf-surface-private.h src/cairo-ps-surface.c src/cairo-ps-surface-private.h src/cairo-quartz-surface.c src/cairo-surface.c src/cairo-surface-fallback.c src/cairo-surface-private.h src/cairo-svg-surface.c src/cairo-type1-subset.c src/cairo-type3-glyph-surface.c src/cairo-win32-printing-surface.c src/cairo-win32-surface.c src/cairo-xlib-surface.c src/Makefile.sources src/test-meta-surface.c src/test-paginated-surface.c test/cairo-test.c test/README

Behdad Esfahbod behdad at behdad.org
Sun Nov 2 15:38:36 PST 2008


Adrian Johnson wrote:
>  src/cairo-jpeg-info-private.h      |   54 +++++++++++
>  src/cairo-jpeg-info.c              |  142 +++++++++++++++++++++++++++++

These two are short enough to live in cairoint.h and cairo-misc.c.


>  /**
> + * cairo_surface_get_mime_data:
> + * @surface: a #cairo_surface_t
> + * @mime_type: the mime type of the image data
> + * @data: the image data to attached to the surface
> + * @length: the length of the image 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.
> + *
> + * Since: 1.10
> + **/
> +void
> +cairo_surface_get_mime_data (cairo_surface_t		*surface,
> +                             const char 		*mime_type,
> +                             const unsigned char       **data,
> +                             unsigned int		*length)
> +{
> +    if (strcmp (mime_type, CAIRO_MIME_TYPE_JPEG) == 0) {
> +	*data = surface->jpeg_data;
> +	*length = surface->jpeg_data_length;
> +    } else {
> +	*data = NULL;
> +    }
> +}
> +
> +/**
> + * 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.
> + *
> + * 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.
> + *
> + * Since: 1.10
> + **/
> +void
> +cairo_surface_set_mime_data (cairo_surface_t		*surface,
> +                             const char			*mime_type,
> +                             const unsigned char	*data,
> +                             unsigned int		 length,
> +			     cairo_destroy_func_t	 destroy)
> +{
> +    if (strcmp (mime_type, CAIRO_MIME_TYPE_JPEG) == 0) {
> +	if (surface->jpeg_data)
> +	    surface->jpeg_destroy (surface->jpeg_data);
> +
> +	surface->jpeg_data = data;
> +	surface->jpeg_data_length = length;
> +	surface->jpeg_destroy = destroy;
> +    }
> +}

This is the wrong approach.  The getter returns NULL for any types it doesn't
understand.  The idea is to keep anything the user sets, and let the backend
use as appropriate.

The way it should be done instead is using a central interned string store
(cairo_user_data_key_from_string() implemented using a hash table), plus the
currently in place user-data facilities.

behdad



More information about the cairo mailing list