From 0a2f3673b9cbe340cdf329f3b303832b16f7d2ee Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sat, 17 Dec 2022 13:51:23 -0500 Subject: [PATCH] [paint] Use tags for image formats This fits better with the rest of the HarfBuzz API. --- src/hb-ot-color-cbdt-table.hh | 2 +- src/hb-ot-color-sbix-table.hh | 2 +- src/hb-ot-color-svg-table.hh | 2 +- src/hb-paint.cc | 6 +++--- src/hb-paint.h | 30 +++++++++++++++++++++++------- src/hb-paint.hh | 4 ++-- util/hb-test.c | 4 ++-- 7 files changed, 33 insertions(+), 17 deletions(-) diff --git a/src/hb-ot-color-cbdt-table.hh b/src/hb-ot-color-cbdt-table.hh index 66c083460..4ab0188df 100644 --- a/src/hb-ot-color-cbdt-table.hh +++ b/src/hb-ot-color-cbdt-table.hh @@ -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; diff --git a/src/hb-ot-color-sbix-table.hh b/src/hb-ot-color-sbix-table.hh index ef96b226c..4190e6d1e 100644 --- a/src/hb-ot-color-sbix-table.hh +++ b/src/hb-ot-color-sbix-table.hh @@ -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; diff --git a/src/hb-ot-color-svg-table.hh b/src/hb-ot-color-svg-table.hh index b13b485c3..3967a1196 100644 --- a/src/hb-ot-color-svg-table.hh +++ b/src/hb-ot-color-svg-table.hh @@ -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; diff --git a/src/hb-paint.cc b/src/hb-paint.cc index ac5312148..537fccd2c 100644 --- a/src/hb-paint.cc +++ b/src/hb-paint.cc @@ -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 diff --git a/src/hb-paint.h b/src/hb-paint.h index ecedcf829..12539b4de 100644 --- a/src/hb-paint.h +++ b/src/hb-paint.h @@ -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 diff --git a/src/hb-paint.hh b/src/hb-paint.hh index e700dd31a..9e7927ac0 100644 --- a/src/hb-paint.hh +++ b/src/hb-paint.hh @@ -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, diff --git a/util/hb-test.c b/util/hb-test.c index c993b499e..5eb83d123 100644 --- a/util/hb-test.c +++ b/util/hb-test.c @@ -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;