[paint] Add API for custom palettes

This commit is contained in:
Behdad Esfahbod 2023-01-18 20:37:21 -07:00
parent ea291493d2
commit bd73314616
3 changed files with 68 additions and 0 deletions

View File

@ -117,6 +117,11 @@ hb_paint_pop_group_nil (hb_paint_funcs_t *funcs, void *paint_data,
hb_paint_composite_mode_t mode,
void *user_data) {}
static hb_color_t
hb_paint_custom_palette_color_nil (hb_paint_funcs_t *funcs, void *paint_data,
unsigned int color_index,
void *user_data) { return HB_COLOR(0,0,0,0); }
static bool
_hb_paint_funcs_set_preamble (hb_paint_funcs_t *funcs,
bool func_is_null,
@ -673,5 +678,23 @@ hb_paint_pop_group (hb_paint_funcs_t *funcs, void *paint_data,
funcs->pop_group (paint_data, mode);
}
/**
* hb_paint_custom_palette_color:
* @funcs: paint functions
* @paint_data: associated data passed by the caller
* @color_index: color index
*
* Gets the custom palette color for @color_index.
*
* Return value: the custom color
*
* Since: REPLACEME
*/
hb_color_t
hb_paint_custom_palette_color (hb_paint_funcs_t *funcs, void *paint_data,
unsigned int color_index)
{
return funcs->custom_palette_color (paint_data, color_index);
}
#endif

View File

@ -655,6 +655,25 @@ typedef void (*hb_paint_pop_group_func_t) (hb_paint_funcs_t *funcs,
hb_paint_composite_mode_t mode,
void *user_data);
/**
* hb_paint_custom_palette_color_func_t:
* @funcs: paint functions object
* @paint_data: The data accompanying the paint functions in hb_font_paint_glyph()
* @color_index: the color index
* @user_data: User data pointer passed to hb_paint_funcs_set_pop_group_func()
*
* A virtual method for the #hb_paint_funcs_t to fetch a color from the custom
* color palette.
*
* Return value: the color
* Since: REPLACEME
*/
typedef hb_color_t (*hb_paint_custom_palette_color_func_t) (hb_paint_funcs_t *funcs,
void *paint_data,
unsigned int color_index,
void *user_data);
/**
* hb_paint_funcs_set_push_transform_func:
* @funcs: A paint functions struct
@ -859,6 +878,22 @@ hb_paint_funcs_set_pop_group_func (hb_paint_funcs_t *funcs,
void *user_data,
hb_destroy_func_t destroy);
/**
* hb_paint_funcs_set_custom_palette_color_func:
* @funcs: A paint functions struct
* @func: (closure user_data) (destroy destroy) (scope notified): The get-custom-palette-color callback
* @user_data: Data to pass to @func
* @destroy: (nullable): Function to call when @user_data is no longer needed
*
* Sets the get-custom-paletter-color callback on the paint functions struct.
*
* Since: REPLACEME
*/
HB_EXTERN void
hb_paint_funcs_set_custom_palette_color_func (hb_paint_funcs_t *funcs,
hb_paint_custom_palette_color_func_t func,
void *user_data,
hb_destroy_func_t destroy);
/*
* Manual API
*/
@ -927,6 +962,10 @@ HB_EXTERN void
hb_paint_pop_group (hb_paint_funcs_t *funcs, void *paint_data,
hb_paint_composite_mode_t mode);
HB_EXTERN hb_color_t
hb_paint_custom_palette_color (hb_paint_funcs_t *funcs, void *paint_data,
unsigned int color_index);
HB_END_DECLS
#endif /* HB_PAINT_H */

View File

@ -42,6 +42,7 @@
HB_PAINT_FUNC_IMPLEMENT (sweep_gradient) \
HB_PAINT_FUNC_IMPLEMENT (push_group) \
HB_PAINT_FUNC_IMPLEMENT (pop_group) \
HB_PAINT_FUNC_IMPLEMENT (custom_palette_color) \
/* ^--- Add new callbacks here */
struct hb_paint_funcs_t
@ -137,6 +138,11 @@ struct hb_paint_funcs_t
{ func.pop_group (this, paint_data,
mode,
!user_data ? nullptr : user_data->pop_group); }
hb_color_t custom_palette_color (void *paint_data,
unsigned int color_index)
{ return func.custom_palette_color (this, paint_data,
color_index,
!user_data ? nullptr : user_data->custom_palette_color); }
/* Internal specializations. */