paint: Add a paint-image callback

This will be used for image blobs like pngs and svgs.

FIXME: nail down and document sizing.
This commit is contained in:
Matthias Clasen 2022-12-17 00:33:59 -05:00 committed by Behdad Esfahbod
parent 56b02b6599
commit 82e23f322a
3 changed files with 61 additions and 0 deletions

View File

@ -68,6 +68,11 @@ hb_paint_color_nil (hb_paint_funcs_t *funcs, void *paint_data,
float alpha, float alpha,
void *user_data) {} void *user_data) {}
static void
hb_paint_image_nil (hb_paint_funcs_t *funcs, void *paint_data,
hb_codepoint_t glyph,
void *user_data) {}
static void static void
hb_paint_linear_gradient_nil (hb_paint_funcs_t *funcs, void *paint_data, hb_paint_linear_gradient_nil (hb_paint_funcs_t *funcs, void *paint_data,
hb_color_line_t *color_line, hb_color_line_t *color_line,
@ -337,6 +342,13 @@ hb_paint_color (hb_paint_funcs_t *funcs, void *paint_data,
funcs->color (paint_data, color_index, alpha); funcs->color (paint_data, color_index, alpha);
} }
void
hb_paint_image (hb_paint_funcs_t *funcs, void *paint_data,
hb_codepoint_t glyph)
{
funcs->image (paint_data, glyph);
}
void void
hb_paint_linear_gradient (hb_paint_funcs_t *funcs, void *paint_data, hb_paint_linear_gradient (hb_paint_funcs_t *funcs, void *paint_data,
hb_color_line_t *color_line, hb_color_line_t *color_line,

View File

@ -56,6 +56,9 @@ HB_BEGIN_DECLS
* For rendering COLRv0 or non-color outline glyphs, the * For rendering COLRv0 or non-color outline glyphs, the
* gradient and composite callbacks are not needed. * gradient and composite callbacks are not needed.
* *
* The paint-image callback is only needed for glyphs
* with blobs in the CBDT, sbix or SVG tables.
*
* Since: REPLACEME * Since: REPLACEME
**/ **/
typedef struct hb_paint_funcs_t hb_paint_funcs_t; typedef struct hb_paint_funcs_t hb_paint_funcs_t;
@ -218,6 +221,25 @@ typedef void (*hb_paint_color_func_t) (hb_paint_funcs_t *funcs,
float alpha, float alpha,
void *user_data); void *user_data);
/**
* hb_paint_image_func_t:
* @funcs: paint functions object
* @paint_data: The data accompanying the paint functions
* @glyph: the glyph ID
* @user_data: user data passed to the hb_font_paint_glyph() call
*
* A virtual method for the #hb_paint_funcs_t to paint the
* glyph image.
*
* This method is intended for glyphs with image blobs in the CBDT,
* sbix or SVG tables.
*
* Since: REPLACEME
*/
typedef void (*hb_paint_image_func_t) (hb_paint_funcs_t *funcs,
void *paint_data,
hb_codepoint_t glyph,
void *user_data);
/** /**
* hb_color_line_t: * hb_color_line_t:
@ -532,6 +554,23 @@ hb_paint_funcs_set_color_func (hb_paint_funcs_t *funcs,
void *user_data, void *user_data,
hb_destroy_func_t destroy); hb_destroy_func_t destroy);
/**
* hb_paint_funcs_set_image_func:
* @funcs: A paint functions struct
* @func: (closure user_data) (destroy destroy) (scope notified): The paint-image callback
* @user_data: Data to pass to @func
* @destroy: (nullable): Function to call when @user_data is no longer needed
*
* Sets the paint-image callback on the paint functions struct.
*
* Since: REPLACEME
*/
HB_EXTERN void
hb_paint_funcs_set_image_func (hb_paint_funcs_t *funcs,
hb_paint_image_func_t func,
void *user_data,
hb_destroy_func_t destroy);
/** /**
* hb_paint_funcs_set_linear_gradient_func: * hb_paint_funcs_set_linear_gradient_func:
* @funcs: A paint functions struct * @funcs: A paint functions struct
@ -643,6 +682,10 @@ hb_paint_color (hb_paint_funcs_t *funcs, void *paint_data,
unsigned int color_index, unsigned int color_index,
float alpha); float alpha);
HB_EXTERN void
hb_paint_image (hb_paint_funcs_t *funcs, void *paint_data,
hb_codepoint_t glyph);
HB_EXTERN void HB_EXTERN void
hb_paint_linear_gradient (hb_paint_funcs_t *funcs, void *paint_data, hb_paint_linear_gradient (hb_paint_funcs_t *funcs, void *paint_data,
hb_color_line_t *color_line, hb_color_line_t *color_line,

View File

@ -34,6 +34,7 @@
HB_PAINT_FUNC_IMPLEMENT (push_clip_rect) \ HB_PAINT_FUNC_IMPLEMENT (push_clip_rect) \
HB_PAINT_FUNC_IMPLEMENT (pop_clip) \ HB_PAINT_FUNC_IMPLEMENT (pop_clip) \
HB_PAINT_FUNC_IMPLEMENT (color) \ HB_PAINT_FUNC_IMPLEMENT (color) \
HB_PAINT_FUNC_IMPLEMENT (image) \
HB_PAINT_FUNC_IMPLEMENT (linear_gradient) \ HB_PAINT_FUNC_IMPLEMENT (linear_gradient) \
HB_PAINT_FUNC_IMPLEMENT (radial_gradient) \ HB_PAINT_FUNC_IMPLEMENT (radial_gradient) \
HB_PAINT_FUNC_IMPLEMENT (sweep_gradient) \ HB_PAINT_FUNC_IMPLEMENT (sweep_gradient) \
@ -92,6 +93,11 @@ struct hb_paint_funcs_t
{ func.color (this, paint_data, { func.color (this, paint_data,
color_index, alpha, color_index, alpha,
!user_data ? nullptr : user_data->color); } !user_data ? nullptr : user_data->color); }
void image (void *paint_data,
hb_codepoint_t glyph)
{ func.image (this, paint_data,
glyph,
!user_data ? nullptr : user_data->image); }
void linear_gradient (void *paint_data, void linear_gradient (void *paint_data,
hb_color_line_t *color_line, hb_color_line_t *color_line,
float x0, float y0, float x0, float y0,