[paint] Use tags for image formats

This fits better with the rest of the
HarfBuzz API.
This commit is contained in:
Matthias Clasen 2022-12-17 13:51:23 -05:00 committed by Behdad Esfahbod
parent 4c728e952b
commit 0a2f3673b9
7 changed files with 33 additions and 17 deletions

View File

@ -947,7 +947,7 @@ struct CBDT
if (unlikely (!get_extents (font, glyph, &extents)))
return false;
funcs->image (data, blob, "image/png", &extents);
funcs->image (data, blob, HB_PAINT_IMAGE_FORMAT_PNG, &extents);
hb_blob_destroy (blob);
return true;

View File

@ -248,7 +248,7 @@ struct sbix
if (!get_extents (font, glyph, &extents))
return false;
funcs->image (data, blob, "image/png", &extents);
funcs->image (data, blob, HB_PAINT_IMAGE_FORMAT_PNG, &extents);
hb_blob_destroy (blob);
return true;

View File

@ -103,7 +103,7 @@ struct SVG
if (blob == hb_blob_get_empty ())
return false;
funcs->image (data, blob, "image/svg+xml", nullptr);
funcs->image (data, blob, HB_PAINT_IMAGE_FORMAT_SVG, nullptr);
hb_blob_destroy (blob);
return true;

View File

@ -71,7 +71,7 @@ hb_paint_color_nil (hb_paint_funcs_t *funcs, void *paint_data,
static void
hb_paint_image_nil (hb_paint_funcs_t *funcs, void *paint_data,
hb_blob_t *image,
const char *mimetype,
hb_tag_t format,
hb_glyph_extents_t *extents,
void *user_data) {}
@ -347,10 +347,10 @@ hb_paint_color (hb_paint_funcs_t *funcs, void *paint_data,
void
hb_paint_image (hb_paint_funcs_t *funcs, void *paint_data,
hb_blob_t *image,
const char *mimetype,
hb_tag_t format,
hb_glyph_extents_t *extents)
{
funcs->image (paint_data, image, mimetype, extents);
funcs->image (paint_data, image, format, extents);
}
void

View File

@ -222,12 +222,26 @@ typedef void (*hb_paint_color_func_t) (hb_paint_funcs_t *funcs,
float alpha,
void *user_data);
/**
* HB_PAINT_IMAGE_FORMAT_PNG:
*
* Tag identifying png images in #hb_paint_image_func_t callbacks.
*/
#define HB_PAINT_IMAGE_FORMAT_PNG HB_TAG('p','n','g',' ')
/**
* HB_PAINT_IMAGE_FORMAT_SVG:
*
* Tag identifying svg images in #hb_paint_image_func_t callbacks.
*/
#define HB_PAINT_IMAGE_FORMAT_SVG HB_TAG('s','v','g',' ')
/**
* hb_paint_image_func_t:
* @funcs: paint functions object
* @paint_data: The data accompanying the paint functions
* @image: the image data
* @mimetype: the mime type for the image data
* @format: the image format as a tag
* @extents: (nullable): glyph extents
* @user_data: user data passed to the hb_font_paint_glyph() call
*
@ -235,17 +249,19 @@ typedef void (*hb_paint_color_func_t) (hb_paint_funcs_t *funcs,
* glyph image.
*
* This method is intended for glyphs with image blobs in the CBDT,
* sbix or SVG tables. The @mimetype identifies the kind of data
* that is contained in @image. Possible values include "image/png"
* and "image/svg+xml". The glyph extents are provided if available,
* and should be used to position the image.
* sbix or SVG tables. The @format identifies the kind of data that
* is contained in @image. Possible values include #HB_PAINT_IMAGE_FORMAT_PNG
* and HB_PAINT_IMAGE_FORMAT_SVG.
*
* The glyph extents are provided if available, and should be used
* to position the image.
*
* Since: REPLACEME
*/
typedef void (*hb_paint_image_func_t) (hb_paint_funcs_t *funcs,
void *paint_data,
hb_blob_t *image,
const char *mimetype,
hb_tag_t format,
hb_glyph_extents_t *extents,
void *user_data);
@ -693,7 +709,7 @@ hb_paint_color (hb_paint_funcs_t *funcs, void *paint_data,
HB_EXTERN void
hb_paint_image (hb_paint_funcs_t *funcs, void *paint_data,
hb_blob_t *image,
const char *mimetype,
hb_tag_t format,
hb_glyph_extents_t *extents);
HB_EXTERN void

View File

@ -97,10 +97,10 @@ struct hb_paint_funcs_t
!user_data ? nullptr : user_data->color); }
void image (void *paint_data,
hb_blob_t *image,
const char *mimetype,
hb_tag_t format,
hb_glyph_extents_t *extents)
{ func.image (this, paint_data,
image, mimetype, extents,
image, format, extents,
!user_data ? nullptr : user_data->image); }
void linear_gradient (void *paint_data,
hb_color_line_t *color_line,

View File

@ -325,7 +325,7 @@ static void
paint_image (hb_paint_funcs_t *funcs,
void *paint_data,
hb_blob_t *blob,
const char *mimetype,
hb_tag_t format,
hb_glyph_extents_t *extents,
void *user_data)
{
@ -335,7 +335,7 @@ paint_image (hb_paint_funcs_t *funcs,
cairo_pattern_t *pattern;
cairo_matrix_t m;
if (strcmp (mimetype, "image/png") != 0)
if (format != HB_PAINT_IMAGE_FORMAT_PNG)
return;
r.blob = blob;