diff options
author | Adrian Johnson <ajohnson@redneon.com> | 2017-11-09 20:52:36 +1030 |
---|---|---|
committer | Adrian Johnson <ajohnson@redneon.com> | 2017-11-09 22:01:40 +1030 |
commit | d5cb45013bf10d97657cea105683bf5ccb21c2d7 (patch) | |
tree | 2005ccbd286e6a9aa00115d54cc11b7fdd01846b /src/cairo-surface.c | |
parent | bff47b43c4b0501c0255e9ba191904bea13ddf5c (diff) | |
download | cairo-d5cb45013bf10d97657cea105683bf5ccb21c2d7.tar.gz |
pdf: fix mime-unique-id jpeg attached to recording test
- Restructure the emit_surface code so that mime types are checked first.
- Add a test parameter to emit_surface to test if the surface will be emitted
as an image or recording instead checking the surface type as the attached
mime may override this.
- Mark surface as not clear when mime is attached to avoid optimizing away
"clear" surfaces that have mime attached.
- Include entire surface in analysis if mime attached (also fixes bug with
calculating the extents CONTENT_COLOR surfaces)
Diffstat (limited to 'src/cairo-surface.c')
-rw-r--r-- | src/cairo-surface.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/cairo-surface.c b/src/cairo-surface.c index 6e69faba8..e04c478fb 100644 --- a/src/cairo-surface.c +++ b/src/cairo-surface.c @@ -1224,6 +1224,44 @@ _cairo_mime_data_destroy (void *ptr) free (mime_data); } + +static const char *_cairo_surface_image_mime_types[] = { + CAIRO_MIME_TYPE_JPEG, + CAIRO_MIME_TYPE_PNG, + CAIRO_MIME_TYPE_JP2, + CAIRO_MIME_TYPE_JBIG2, + CAIRO_MIME_TYPE_CCITT_FAX, +}; + +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)) + return FALSE; + + /* The number of mime-types attached to a surface is usually small, + * typically zero. Therefore it is quicker to do a strcmp() against + * each key than it is to intern the string (i.e. compute a hash, + * search the hash table, and do a final strcmp). + */ + 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; + } + } + } + + return FALSE; +} + /** * CAIRO_MIME_TYPE_CCITT_FAX: * @@ -1405,6 +1443,8 @@ cairo_surface_set_mime_data (cairo_surface_t *surface, return _cairo_surface_set_error (surface, status); } + surface->is_clear = FALSE; + return CAIRO_STATUS_SUCCESS; } slim_hidden_def (cairo_surface_set_mime_data); @@ -1479,6 +1519,8 @@ _cairo_surface_copy_mime_data (cairo_surface_t *dst, _cairo_mime_data_reference, NULL); + dst->is_clear = FALSE; + return CAIRO_STATUS_SUCCESS; } |