[COLRv1] Hook up custom palette colors

This commit is contained in:
Behdad Esfahbod 2023-01-18 20:49:06 -07:00
parent d695cc8735
commit 7aca3b5090
2 changed files with 46 additions and 16 deletions

View File

@ -96,11 +96,17 @@ public:
*is_foreground = true;
if (color_index != 0xffff)
{
if (palette != HB_PAINT_PALETTE_INDEX_CUSTOM)
{
unsigned int clen = 1;
hb_face_t *face = hb_font_get_face (font);
hb_ot_color_palette_get_colors (face, palette, color_index, &clen, &color);
}
else
color = funcs->custom_palette_color (data, color_index);
*is_foreground = false;
}

View File

@ -83,10 +83,11 @@ struct hb_ft_paint_context_t
hb_font_t *font,
hb_paint_funcs_t *paint_funcs, void *paint_data,
FT_Color *palette,
unsigned palette_index,
hb_color_t foreground) :
ft_font (ft_font), font(font),
funcs (paint_funcs), data (paint_data),
palette (palette), foreground (foreground) {}
palette (palette), palette_index (palette_index), foreground (foreground) {}
void recurse (FT_OpaquePaint paint)
{
@ -102,6 +103,7 @@ struct hb_ft_paint_context_t
hb_paint_funcs_t *funcs;
void *data;
FT_Color *palette;
unsigned palette_index;
hb_color_t foreground;
int depth_left = HB_MAX_NESTING_LEVEL;
int edge_count = HB_COLRV1_MAX_EDGE_COUNT;
@ -153,6 +155,16 @@ _hb_ft_color_line_get_color_stops (hb_color_line_t *color_line,
hb_color_get_red (c->foreground),
(hb_color_get_alpha (c->foreground) * stop.color.alpha) >> 14);
else
{
if (c->palette_index == HB_PAINT_PALETTE_INDEX_CUSTOM)
{
hb_color_t color = c->funcs->custom_palette_color (c->data, stop.color.palette_index);
color_stops->color = HB_COLOR (hb_color_get_blue (color),
hb_color_get_green (color),
hb_color_get_red (color),
(hb_color_get_alpha (color) * stop.color.alpha) >> 14);
}
else
{
FT_Color ft_color = c->palette[stop.color.palette_index];
color_stops->color = HB_COLOR (ft_color.blue,
@ -160,6 +172,7 @@ _hb_ft_color_line_get_color_stops (hb_color_line_t *color_line,
ft_color.red,
(ft_color.alpha * stop.color.alpha) >> 14);
}
}
color_stops++;
wrote++;
@ -223,6 +236,16 @@ _hb_ft_paint (hb_ft_paint_context_t *c,
hb_color_get_red (c->foreground),
(hb_color_get_alpha (c->foreground) * paint.u.solid.color.alpha) >> 14);
else
{
if (c->palette_index == HB_PAINT_PALETTE_INDEX_CUSTOM)
{
color = c->funcs->custom_palette_color (c->data, paint.u.solid.color.palette_index);
color = HB_COLOR (hb_color_get_blue (color),
hb_color_get_green (color),
hb_color_get_red (color),
(hb_color_get_alpha (color) * paint.u.solid.color.alpha) >> 14);
}
else
{
FT_Color ft_color = c->palette[paint.u.solid.color.palette_index];
color = HB_COLOR (ft_color.blue,
@ -230,6 +253,7 @@ _hb_ft_paint (hb_ft_paint_context_t *c,
ft_color.red,
(ft_color.alpha * paint.u.solid.color.alpha) >> 14);
}
}
c->funcs->color (c->data, is_foreground, color);
}
break;
@ -450,7 +474,7 @@ hb_ft_paint_glyph_colr (hb_font_t *font,
{
hb_ft_paint_context_t c (ft_font, font,
paint_funcs, paint_data,
palette, foreground);
palette, palette_index, foreground);
bool is_bounded = true;
FT_ClipBox clip_box;
@ -473,7 +497,7 @@ hb_ft_paint_glyph_colr (hb_font_t *font,
hb_paint_extents_context_t extents_data;
hb_ft_paint_context_t ce (ft_font, font,
extents_funcs, &extents_data,
palette, foreground);
palette, palette_index, foreground);
ce.funcs->push_root_transform (ce.data, font);
ce.recurse (paint);
ce.funcs->pop_transform (ce.data);