From b9314400eccb2dadce788f6af5d843d5341f2c11 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 17 Dec 2022 10:58:52 -0700 Subject: [PATCH] [colr] Hook up color-line variation --- src/hb-ot-color-colr-table.cc | 4 ++-- src/hb-ot-color-colr-table.hh | 37 +++++++++++++++++++++++------------ 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/hb-ot-color-colr-table.cc b/src/hb-ot-color-colr-table.cc index 2172eb61c..ff6c4714b 100644 --- a/src/hb-ot-color-colr-table.cc +++ b/src/hb-ot-color-colr-table.cc @@ -32,9 +32,9 @@ hb_color_line_get_color_stops (hb_color_line_t *cl, hb_color_stop_t *color_stops) { if (cl->is_variable) - return reinterpret_cast *>(cl->base)->get_color_stops (start, count, color_stops); + return reinterpret_cast *>(cl->base)->get_color_stops (start, count, color_stops, cl->c->instancer); else - return reinterpret_cast *>(cl->base)->get_color_stops (start, count, color_stops); + return reinterpret_cast *>(cl->base)->get_color_stops (start, count, color_stops, cl->c->instancer); } hb_paint_extend_t diff --git a/src/hb-ot-color-colr-table.hh b/src/hb-ot-color-colr-table.hh index ab968e188..3dc7c6f6a 100644 --- a/src/hb-ot-color-colr-table.hh +++ b/src/hb-ot-color-colr-table.hh @@ -45,7 +45,12 @@ #endif +namespace OT { +struct hb_paint_context_t; +} + struct hb_color_line_t { + struct OT::hb_paint_context_t *c; const void *base; bool is_variable; }; @@ -230,9 +235,10 @@ struct Variable value.paint_glyph (c, varIdxBase); } - void get_color_stop (hb_color_stop_t *c) const + void get_color_stop (hb_color_stop_t *c, + const VarStoreInstancer &instancer) const { - value.get_color_stop (c); + value.get_color_stop (c, varIdxBase, instancer); } hb_paint_extend_t get_extend () const @@ -281,9 +287,10 @@ struct NoVariable value.paint_glyph (c, varIdxBase); } - void get_color_stop (hb_color_stop_t *c) const + void get_color_stop (hb_color_stop_t *c, + const VarStoreInstancer &instancer) const { - value.get_color_stop (c); + value.get_color_stop (c, VarIdx::NO_VARIATION, instancer); } hb_paint_extend_t get_extend () const @@ -318,11 +325,13 @@ struct ColorStop return_trace (c->check_struct (this)); } - void get_color_stop (hb_color_stop_t *out) const + void get_color_stop (hb_color_stop_t *out, + uint32_t varIdx, + const VarStoreInstancer &instancer) const { - out->offset = stopOffset.to_float(); + out->offset = stopOffset.to_float(instancer (varIdx, 0)); out->color_index = paletteIndex; - out->alpha = alpha.to_float(); + out->alpha = alpha.to_float(instancer (varIdx, 1)); } F2DOT14 stopOffset; @@ -379,8 +388,9 @@ struct ColorLine /* get up to count stops from start */ unsigned int get_color_stops (unsigned int start, - unsigned int *count, - hb_color_stop_t *color_stops) const + unsigned int *count, + hb_color_stop_t *color_stops, + const VarStoreInstancer &instancer) const { unsigned int len = stops.len; @@ -388,7 +398,8 @@ struct ColorLine { unsigned int i; for (i = 0; i < *count && start + i < len; i++) - stops[start + i].get_color_stop (&color_stops[i]); + stops[start + i].get_color_stop (&color_stops[i], + instancer); *count = i; } @@ -571,7 +582,7 @@ struct PaintLinearGradient void paint_glyph (hb_paint_context_t *c, uint32_t varIdxBase) const { - hb_color_line_t cl = { &(this+colorLine), Var::is_variable }; + hb_color_line_t cl = { c, &(this+colorLine), Var::is_variable }; c->funcs->linear_gradient (c->data, &cl, x0 + c->instancer (varIdxBase, 0), @@ -618,7 +629,7 @@ struct PaintRadialGradient void paint_glyph (hb_paint_context_t *c, uint32_t varIdxBase) const { - hb_color_line_t cl = { &(this+colorLine), Var::is_variable }; + hb_color_line_t cl = { c, &(this+colorLine), Var::is_variable }; c->funcs->radial_gradient (c->data, &cl, x0 + c->instancer (varIdxBase, 0), @@ -665,7 +676,7 @@ struct PaintSweepGradient void paint_glyph (hb_paint_context_t *c, uint32_t varIdxBase) const { - hb_color_line_t cl = { &(this+colorLine), Var::is_variable }; + hb_color_line_t cl = { c, &(this+colorLine), Var::is_variable }; c->funcs->sweep_gradient (c->data, &cl, centerX + c->instancer (varIdxBase, 0),