diff --git a/src/OT/glyf/glyf.hh b/src/OT/glyf/glyf.hh index 39ce65608..0923814d0 100644 --- a/src/OT/glyf/glyf.hh +++ b/src/OT/glyf/glyf.hh @@ -338,7 +338,7 @@ struct glyf_accelerator_t funcs->push_root_transform (data, font); funcs->push_clip_glyph (data, gid, font); - funcs->color (data, foreground); + funcs->color (data, true, foreground); funcs->pop_clip (data); funcs->pop_root_transform (data); diff --git a/src/hb-ot-cff1-table.cc b/src/hb-ot-cff1-table.cc index b00441fe5..da403c366 100644 --- a/src/hb-ot-cff1-table.cc +++ b/src/hb-ot-cff1-table.cc @@ -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_clip_glyph (data, glyph, font); - funcs->color (data, foreground); + funcs->color (data, true, foreground); funcs->pop_clip (data); funcs->pop_root_transform (data); diff --git a/src/hb-ot-cff2-table.cc b/src/hb-ot-cff2-table.cc index 6bbd5383a..6fb43cf63 100644 --- a/src/hb-ot-cff2-table.cc +++ b/src/hb-ot-cff2-table.cc @@ -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_clip_glyph (data, glyph, font); - funcs->color (data, foreground); + funcs->color (data, true, foreground); funcs->pop_clip (data); funcs->pop_root_transform (data); diff --git a/src/hb-ot-color-colr-table.hh b/src/hb-ot-color-colr-table.hh index d5f233df7..e3893f91c 100644 --- a/src/hb-ot-color-colr-table.hh +++ b/src/hb-ot-color-colr-table.hh @@ -97,16 +97,19 @@ public: 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; + *is_foreground = true; + if (color_index != 0xffff) { 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); + *is_foreground = false; } return HB_COLOR (hb_color_get_blue (color), @@ -360,7 +363,9 @@ struct ColorStop const VarStoreInstancer &instancer) const { 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; @@ -576,9 +581,13 @@ struct PaintSolid void paint_glyph (hb_paint_context_t *c, uint32_t varIdxBase) const { - c->funcs->color (c->data, - c->get_color (paletteIndex, - alpha.to_float (c->instancer (varIdxBase, 0)))); + hb_bool_t is_foreground; + hb_color_t color; + + 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)*/ @@ -1992,8 +2001,10 @@ struct COLR for (const auto &r : (this+layersZ).as_array (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->color (c.data, c.get_color (r.colorIdx, 1.)); + c.funcs->color (c.data, is_foreground, color); c.funcs->pop_clip (c.data); } diff --git a/src/hb-paint.cc b/src/hb-paint.cc index 72af14092..f59266f8a 100644 --- a/src/hb-paint.cc +++ b/src/hb-paint.cc @@ -70,6 +70,7 @@ hb_paint_pop_clip_nil (hb_paint_funcs_t *funcs, void *paint_data, static void hb_paint_color_nil (hb_paint_funcs_t *funcs, void *paint_data, + hb_bool_t is_foreground, hb_color_t color, void *user_data) {} diff --git a/src/hb-paint.h b/src/hb-paint.h index 11616006d..af36e36a0 100644 --- a/src/hb-paint.h +++ b/src/hb-paint.h @@ -209,6 +209,7 @@ typedef void (*hb_paint_pop_clip_func_t) (hb_paint_funcs_t *funcs, * hb_paint_color_func_t: * @funcs: paint functions object * @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 * @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, void *paint_data, + hb_bool_t is_foreground, hb_color_t color, void *user_data); @@ -277,6 +279,7 @@ typedef struct hb_color_line_t hb_color_line_t; /** * hb_color_stop_t: * @offset: the offset of the color stop + * @is_foreground: whether the color is the foreground * @color: the color * * 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 { float offset; + hb_bool_t is_foreground; hb_color_t color; } hb_color_stop_t; diff --git a/src/hb-paint.hh b/src/hb-paint.hh index 29bce0536..401c3016e 100644 --- a/src/hb-paint.hh +++ b/src/hb-paint.hh @@ -92,9 +92,10 @@ struct hb_paint_funcs_t { func.pop_clip (this, paint_data, !user_data ? nullptr : user_data->pop_clip); } void color (void *paint_data, + hb_bool_t is_foreground, hb_color_t color) { func.color (this, paint_data, - color, + is_foreground, color, !user_data ? nullptr : user_data->color); } void image (void *paint_data, hb_blob_t *image, diff --git a/test/api/test-ot-color.c b/test/api/test-ot-color.c index a317f46fa..604efbabb 100644 --- a/test/api/test-ot-color.c +++ b/test/api/test-ot-color.c @@ -542,6 +542,7 @@ pop_clip (hb_paint_funcs_t *funcs, static void paint_color (hb_paint_funcs_t *funcs, void *paint_data, + hb_bool_t use_foreground, hb_color_t color, void *user_data) { diff --git a/util/helper-cairo-user.hh b/util/helper-cairo-user.hh index 57b365b3c..d7edea2c6 100644 --- a/util/helper-cairo-user.hh +++ b/util/helper-cairo-user.hh @@ -203,6 +203,7 @@ pop_group (hb_paint_funcs_t *funcs, static void paint_color (hb_paint_funcs_t *funcs, void *paint_data, + hb_bool_t use_foreground, hb_color_t color, void *user_data) {