[paint] Add hb_paint_fill_glyph()

Instead of painting COLRv0 and outline fallback layers with
push_clip_glyph + color + pop_clip, add a dedicated callback for this
common paint operation.

The default (*_nil) implementation uses the decomposed sequence, so
existing clients without a fill_glyph implementation continue to work as
before.
This commit is contained in:
Khaled Hosny committed 2026-07-08 20:29:31 +03:00
1 parent f7a8ef5022
commit 421cc8f5a7
6 files changed
+100 -6

No files matched your search

+3
View File
@@ -266,6 +266,8 @@ hb_paint_pop_transform_func_t
hb_paint_funcs_set_pop_transform_func
hb_paint_color_glyph_func_t
hb_paint_funcs_set_color_glyph_func
hb_paint_fill_glyph_func_t
hb_paint_funcs_set_fill_glyph_func
hb_paint_push_clip_glyph_func_t
hb_paint_funcs_set_push_clip_glyph_func
hb_paint_push_clip_rectangle_func_t
@@ -311,6 +313,7 @@ hb_paint_push_font_transform
hb_paint_push_inverse_font_transform
hb_paint_pop_transform
hb_paint_color_glyph
hb_paint_fill_glyph
hb_paint_push_clip_glyph
hb_paint_push_clip_rectangle
hb_paint_push_clip_path_start
+1 -3
View File
@@ -2761,9 +2761,7 @@ struct COLR
{
hb_bool_t is_foreground;
hb_color_t color = c.get_color (r.colorIdx, 1., &is_foreground);
c.funcs->push_clip_glyph (c.data, r.glyphId, c.font);
c.funcs->color (c.data, is_foreground, color);
c.funcs->pop_clip (c.data);
c.funcs->fill_glyph (c.data, r.glyphId, c.font, is_foreground, color);
}
return true;
+1 -3
View File
@@ -1670,9 +1670,7 @@ hb_font_t::paint_glyph (hb_codepoint_t glyph,
return;
/* Fallback for outline glyph. */
paint_funcs->push_clip_glyph (paint_data, glyph, this);
paint_funcs->color (paint_data, true, foreground);
paint_funcs->pop_clip (paint_data);
paint_funcs->fill_glyph (paint_data, glyph, this, true, foreground);
}
+38
View File
@@ -60,6 +60,20 @@ hb_paint_color_glyph_nil (hb_paint_funcs_t *funcs, void *paint_data,
hb_font_t *font,
void *user_data) { return false; }
static void
hb_paint_fill_glyph_nil (hb_paint_funcs_t *funcs, void *paint_data,
hb_codepoint_t glyph,
hb_font_t *font,
hb_bool_t is_foreground,
hb_color_t color,
void *user_data)
{
/* Decompose into the equivalent general sequence. */
funcs->push_clip_glyph (paint_data, glyph, font);
funcs->color (paint_data, is_foreground, color);
funcs->pop_clip (paint_data);
}
static void
hb_paint_push_clip_glyph_nil (hb_paint_funcs_t *funcs, void *paint_data,
hb_codepoint_t glyph,
@@ -551,6 +565,30 @@ hb_paint_color_glyph (hb_paint_funcs_t *funcs, void *paint_data,
return funcs->color_glyph (paint_data, glyph, font);
}
/**
* hb_paint_fill_glyph:
* @funcs: paint functions
* @paint_data: associated data passed by the caller
* @glyph: the glyph ID
* @font: the font
* @is_foreground: whether the color is the foreground
* @color: The color to use
*
* Perform a "fill-glyph" paint operation: fill the glyph's shape
* with a solid color.
*
* XSince: REPLACEME
*/
void
hb_paint_fill_glyph (hb_paint_funcs_t *funcs, void *paint_data,
hb_codepoint_t glyph,
hb_font_t *font,
hb_bool_t is_foreground,
hb_color_t color)
{
funcs->fill_glyph (paint_data, glyph, font, is_foreground, color);
}
/**
* hb_paint_push_clip_glyph:
* @funcs: paint functions
+47
View File
@@ -157,6 +157,29 @@ typedef hb_bool_t (*hb_paint_color_glyph_func_t) (hb_paint_funcs_t *funcs,
hb_font_t *font,
void *user_data);
/**
* hb_paint_fill_glyph_func_t:
* @funcs: paint functions object
* @paint_data: The data accompanying the paint functions in hb_font_paint_glyph()
* @glyph: the glyph ID
* @font: the font
* @is_foreground: whether the color is the foreground
* @color: The color to use, unpremultiplied
* @user_data: User data pointer passed to hb_paint_funcs_set_fill_glyph_func()
*
* A virtual method for the #hb_paint_funcs_t to fill a glyph's
* shape with a solid color.
*
* XSince: REPLACEME
*/
typedef void (*hb_paint_fill_glyph_func_t) (hb_paint_funcs_t *funcs,
void *paint_data,
hb_codepoint_t glyph,
hb_font_t *font,
hb_bool_t is_foreground,
hb_color_t color,
void *user_data);
/**
* hb_paint_push_clip_glyph_func_t:
* @funcs: paint functions object
@@ -854,6 +877,23 @@ hb_paint_funcs_set_color_glyph_func (hb_paint_funcs_t *funcs,
void *user_data,
hb_destroy_func_t destroy);
/**
* hb_paint_funcs_set_fill_glyph_func:
* @funcs: A paint functions struct
* @func: (closure user_data) (destroy destroy) (scope notified): The fill-glyph callback
* @user_data: Data to pass to @func
* @destroy: (nullable): Function to call when @user_data is no longer needed
*
* Sets the fill-glyph callback on the paint functions struct.
*
* XSince: REPLACEME
*/
HB_EXTERN void
hb_paint_funcs_set_fill_glyph_func (hb_paint_funcs_t *funcs,
hb_paint_fill_glyph_func_t func,
void *user_data,
hb_destroy_func_t destroy);
/**
* hb_paint_funcs_set_push_clip_glyph_func:
* @funcs: A paint functions struct
@@ -1117,6 +1157,13 @@ hb_paint_color_glyph (hb_paint_funcs_t *funcs, void *paint_data,
hb_codepoint_t glyph,
hb_font_t *font);
HB_EXTERN void
hb_paint_fill_glyph (hb_paint_funcs_t *funcs, void *paint_data,
hb_codepoint_t glyph,
hb_font_t *font,
hb_bool_t is_foreground,
hb_color_t color);
HB_EXTERN void
hb_paint_push_clip_glyph (hb_paint_funcs_t *funcs, void *paint_data,
hb_codepoint_t glyph,
+10
View File
@@ -48,6 +48,7 @@
HB_PAINT_FUNC_IMPLEMENT (push_group_for) \
HB_PAINT_FUNC_IMPLEMENT (pop_group) \
HB_PAINT_FUNC_IMPLEMENT (custom_palette_color) \
HB_PAINT_FUNC_IMPLEMENT (fill_glyph) \
/* ^--- Add new callbacks here */
struct hb_paint_funcs_t
@@ -121,6 +122,15 @@ struct hb_paint_funcs_t
{ func.color (this, paint_data,
is_foreground, color,
!user_data ? nullptr : user_data->color); }
void fill_glyph (void *paint_data,
hb_codepoint_t glyph,
hb_font_t *font,
hb_bool_t is_foreground,
hb_color_t color)
{ func.fill_glyph (this, paint_data,
glyph, font,
is_foreground, color,
!user_data ? nullptr : user_data->fill_glyph); }
bool image (void *paint_data,
hb_blob_t *image,
unsigned width, unsigned height,