[paint] Preserve foreground information

This commit is contained in:
Matthias Clasen 2022-12-21 18:39:27 -05:00 committed by Behdad Esfahbod
parent f146299a40
commit c221933977
9 changed files with 29 additions and 10 deletions

View File

@ -338,7 +338,7 @@ struct glyf_accelerator_t
funcs->push_root_transform (data, font); funcs->push_root_transform (data, font);
funcs->push_clip_glyph (data, gid, font); funcs->push_clip_glyph (data, gid, font);
funcs->color (data, foreground); funcs->color (data, true, foreground);
funcs->pop_clip (data); funcs->pop_clip (data);
funcs->pop_root_transform (data); funcs->pop_root_transform (data);

View File

@ -558,7 +558,7 @@ bool OT::cff1::accelerator_t::paint_glyph (hb_font_t *font, hb_codepoint_t glyph
funcs->push_root_transform (data, font); funcs->push_root_transform (data, font);
funcs->push_clip_glyph (data, glyph, font); funcs->push_clip_glyph (data, glyph, font);
funcs->color (data, foreground); funcs->color (data, true, foreground);
funcs->pop_clip (data); funcs->pop_clip (data);
funcs->pop_root_transform (data); funcs->pop_root_transform (data);

View File

@ -148,7 +148,7 @@ bool OT::cff2::accelerator_t::paint_glyph (hb_font_t *font, hb_codepoint_t glyph
funcs->push_root_transform (data, font); funcs->push_root_transform (data, font);
funcs->push_clip_glyph (data, glyph, font); funcs->push_clip_glyph (data, glyph, font);
funcs->color (data, foreground); funcs->color (data, true, foreground);
funcs->pop_clip (data); funcs->pop_clip (data);
funcs->pop_root_transform (data); funcs->pop_root_transform (data);

View File

@ -97,16 +97,19 @@ public:
instancer (instancer_) instancer (instancer_)
{ } { }
hb_color_t get_color (unsigned int color_index, float alpha) hb_color_t get_color (unsigned int color_index, float alpha, hb_bool_t *is_foreground)
{ {
hb_color_t color = foreground; hb_color_t color = foreground;
*is_foreground = true;
if (color_index != 0xffff) if (color_index != 0xffff)
{ {
unsigned int clen = 1; unsigned int clen = 1;
hb_face_t *face = hb_font_get_face (font); hb_face_t *face = hb_font_get_face (font);
hb_ot_color_palette_get_colors (face, palette, color_index, &clen, &color); hb_ot_color_palette_get_colors (face, palette, color_index, &clen, &color);
*is_foreground = false;
} }
return HB_COLOR (hb_color_get_blue (color), return HB_COLOR (hb_color_get_blue (color),
@ -360,7 +363,9 @@ struct ColorStop
const VarStoreInstancer &instancer) const const VarStoreInstancer &instancer) const
{ {
out->offset = stopOffset.to_float(instancer (varIdx, 0)); out->offset = stopOffset.to_float(instancer (varIdx, 0));
out->color = c->get_color (paletteIndex, alpha.to_float (instancer (varIdx, 1))); out->color = c->get_color (paletteIndex,
alpha.to_float (instancer (varIdx, 1)),
&out->is_foreground);
} }
F2DOT14 stopOffset; F2DOT14 stopOffset;
@ -576,9 +581,13 @@ struct PaintSolid
void paint_glyph (hb_paint_context_t *c, uint32_t varIdxBase) const void paint_glyph (hb_paint_context_t *c, uint32_t varIdxBase) const
{ {
c->funcs->color (c->data, hb_bool_t is_foreground;
c->get_color (paletteIndex, hb_color_t color;
alpha.to_float (c->instancer (varIdxBase, 0))));
color = c->get_color (paletteIndex,
alpha.to_float (c->instancer (varIdxBase, 0)),
&is_foreground);
c->funcs->color (c->data, is_foreground, color);
} }
HBUINT8 format; /* format = 2(noVar) or 3(Var)*/ HBUINT8 format; /* format = 2(noVar) or 3(Var)*/
@ -1992,8 +2001,10 @@ struct COLR
for (const auto &r : (this+layersZ).as_array (numLayers) for (const auto &r : (this+layersZ).as_array (numLayers)
.sub_array (record->firstLayerIdx, record->numLayers)) .sub_array (record->firstLayerIdx, record->numLayers))
{ {
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->push_clip_glyph (c.data, r.glyphId, c.font);
c.funcs->color (c.data, c.get_color (r.colorIdx, 1.)); c.funcs->color (c.data, is_foreground, color);
c.funcs->pop_clip (c.data); c.funcs->pop_clip (c.data);
} }

View File

@ -70,6 +70,7 @@ hb_paint_pop_clip_nil (hb_paint_funcs_t *funcs, void *paint_data,
static void static void
hb_paint_color_nil (hb_paint_funcs_t *funcs, void *paint_data, hb_paint_color_nil (hb_paint_funcs_t *funcs, void *paint_data,
hb_bool_t is_foreground,
hb_color_t color, hb_color_t color,
void *user_data) {} void *user_data) {}

View File

@ -209,6 +209,7 @@ typedef void (*hb_paint_pop_clip_func_t) (hb_paint_funcs_t *funcs,
* hb_paint_color_func_t: * hb_paint_color_func_t:
* @funcs: paint functions object * @funcs: paint functions object
* @paint_data: The data accompanying the paint functions in hb_font_paint_glyph() * @paint_data: The data accompanying the paint functions in hb_font_paint_glyph()
* @is_foreground: whether the color is the foreground
* @color: The color to use * @color: The color to use
* @user_data: User data pointer passed to hb_paint_funcs_set_color_func() * @user_data: User data pointer passed to hb_paint_funcs_set_color_func()
* *
@ -219,6 +220,7 @@ typedef void (*hb_paint_pop_clip_func_t) (hb_paint_funcs_t *funcs,
*/ */
typedef void (*hb_paint_color_func_t) (hb_paint_funcs_t *funcs, typedef void (*hb_paint_color_func_t) (hb_paint_funcs_t *funcs,
void *paint_data, void *paint_data,
hb_bool_t is_foreground,
hb_color_t color, hb_color_t color,
void *user_data); void *user_data);
@ -277,6 +279,7 @@ typedef struct hb_color_line_t hb_color_line_t;
/** /**
* hb_color_stop_t: * hb_color_stop_t:
* @offset: the offset of the color stop * @offset: the offset of the color stop
* @is_foreground: whether the color is the foreground
* @color: the color * @color: the color
* *
* Information about a color stop on a color line. * Information about a color stop on a color line.
@ -288,6 +291,7 @@ typedef struct hb_color_line_t hb_color_line_t;
*/ */
typedef struct { typedef struct {
float offset; float offset;
hb_bool_t is_foreground;
hb_color_t color; hb_color_t color;
} hb_color_stop_t; } hb_color_stop_t;

View File

@ -92,9 +92,10 @@ struct hb_paint_funcs_t
{ func.pop_clip (this, paint_data, { func.pop_clip (this, paint_data,
!user_data ? nullptr : user_data->pop_clip); } !user_data ? nullptr : user_data->pop_clip); }
void color (void *paint_data, void color (void *paint_data,
hb_bool_t is_foreground,
hb_color_t color) hb_color_t color)
{ func.color (this, paint_data, { func.color (this, paint_data,
color, is_foreground, color,
!user_data ? nullptr : user_data->color); } !user_data ? nullptr : user_data->color); }
void image (void *paint_data, void image (void *paint_data,
hb_blob_t *image, hb_blob_t *image,

View File

@ -542,6 +542,7 @@ pop_clip (hb_paint_funcs_t *funcs,
static void static void
paint_color (hb_paint_funcs_t *funcs, paint_color (hb_paint_funcs_t *funcs,
void *paint_data, void *paint_data,
hb_bool_t use_foreground,
hb_color_t color, hb_color_t color,
void *user_data) void *user_data)
{ {

View File

@ -203,6 +203,7 @@ pop_group (hb_paint_funcs_t *funcs,
static void static void
paint_color (hb_paint_funcs_t *funcs, paint_color (hb_paint_funcs_t *funcs,
void *paint_data, void *paint_data,
hb_bool_t use_foreground,
hb_color_t color, hb_color_t color,
void *user_data) void *user_data)
{ {