[colr] Simplify color-stop handling

This commit is contained in:
Behdad Esfahbod 2022-12-17 10:38:23 -07:00
parent 485ba9beb3
commit c6dd56cc64
2 changed files with 17 additions and 74 deletions

View File

@ -31,43 +31,17 @@ hb_color_line_get_color_stops (hb_color_line_t *cl,
unsigned int *count,
hb_color_stop_t *color_stops)
{
switch (cl->format)
{
case 4:
return reinterpret_cast<const OT::PaintLinearGradient<OT::NoVariable> *>(cl->base)->get_color_stops (start, count, color_stops);
case 5:
return reinterpret_cast<const OT::PaintLinearGradient<OT::Variable> *>(cl->base)->get_color_stops (start, count, color_stops);
case 6:
return reinterpret_cast<const OT::PaintRadialGradient<OT::NoVariable> *>(cl->base)->get_color_stops (start, count, color_stops);
case 7:
return reinterpret_cast<const OT::PaintRadialGradient<OT::Variable> *>(cl->base)->get_color_stops (start, count, color_stops);
case 8:
return reinterpret_cast<const OT::PaintSweepGradient<OT::NoVariable> *>(cl->base)->get_color_stops (start, count, color_stops);
case 9:
return reinterpret_cast<const OT::PaintSweepGradient<OT::Variable> *>(cl->base)->get_color_stops (start, count, color_stops);
default: assert (0);
}
return 0;
if (cl->is_variable)
return reinterpret_cast<const OT::ColorLine<OT::Variable> *>(cl->base)->get_color_stops (start, count, color_stops);
else
return reinterpret_cast<const OT::ColorLine<OT::NoVariable> *>(cl->base)->get_color_stops (start, count, color_stops);
}
hb_paint_extend_t
hb_color_line_get_extend (hb_color_line_t *cl)
{
switch (cl->format)
{
case 4:
return reinterpret_cast<const OT::PaintLinearGradient<OT::NoVariable> *>(cl->base)->get_extend ();
case 5:
return reinterpret_cast<const OT::PaintLinearGradient<OT::Variable> *>(cl->base)->get_extend ();
case 6:
return reinterpret_cast<const OT::PaintRadialGradient<OT::NoVariable> *>(cl->base)->get_extend ();
case 7:
return reinterpret_cast<const OT::PaintRadialGradient<OT::Variable> *>(cl->base)->get_extend ();
case 8:
return reinterpret_cast<const OT::PaintSweepGradient<OT::NoVariable> *>(cl->base)->get_extend ();
case 9:
return reinterpret_cast<const OT::PaintSweepGradient<OT::Variable> *>(cl->base)->get_extend ();
default: assert (0);
}
return HB_PAINT_EXTEND_PAD;
if (cl->is_variable)
return reinterpret_cast<const OT::ColorLine<OT::Variable> *>(cl->base)->get_extend ();
else
return reinterpret_cast<const OT::ColorLine<OT::NoVariable> *>(cl->base)->get_extend ();
}

View File

@ -44,9 +44,10 @@
#define HB_COLRV1_MAX_NESTING_LEVEL 128
#endif
struct hb_color_line_t {
const void *base;
OT::HBUINT8 format;
bool is_variable;
};
namespace OT {
@ -200,6 +201,8 @@ struct BaseGlyphRecord
template <typename T>
struct Variable
{
static constexpr bool is_variable = true;
Variable<T>* copy (hb_serialize_context_t *c) const
{
TRACE_SERIALIZE (this);
@ -248,6 +251,8 @@ struct Variable
template <typename T>
struct NoVariable
{
static constexpr bool is_variable = false;
static constexpr uint32_t varIdxBase = VarIdx::NO_VARIATION;
NoVariable<T>* copy (hb_serialize_context_t *c) const
@ -566,7 +571,7 @@ struct PaintLinearGradient
void paint_glyph (hb_paint_context_t *c, uint32_t varIdxBase) const
{
hb_color_line_t cl = { this, format };
hb_color_line_t cl = { &(this+colorLine), Var<ColorLine<Var>>::is_variable };
c->funcs->linear_gradient (c->data, &cl,
x0 + c->instancer (varIdxBase, 0),
@ -577,18 +582,6 @@ struct PaintLinearGradient
y2 + c->instancer (varIdxBase, 5));
}
unsigned int get_color_stops (unsigned int start,
unsigned int *count,
hb_color_stop_t *stops) const
{
return (this+colorLine).get_color_stops (start, count, stops);
}
hb_paint_extend_t get_extend () const
{
return (this+colorLine).get_extend ();
}
HBUINT8 format; /* format = 4(noVar) or 5 (Var) */
Offset24To<ColorLine<Var>> colorLine; /* Offset (from beginning of PaintLinearGradient
* table) to ColorLine subtable. */
@ -625,7 +618,7 @@ struct PaintRadialGradient
void paint_glyph (hb_paint_context_t *c, uint32_t varIdxBase) const
{
hb_color_line_t cl = { this, format };
hb_color_line_t cl = { &(this+colorLine), Var<ColorLine<Var>>::is_variable };
c->funcs->radial_gradient (c->data, &cl,
x0 + c->instancer (varIdxBase, 0),
@ -636,18 +629,6 @@ struct PaintRadialGradient
radius1 + c->instancer (varIdxBase, 5));
}
unsigned int get_color_stops (unsigned int start,
unsigned int *count,
hb_color_stop_t *stops) const
{
return (this+colorLine).get_color_stops (start, count, stops);
}
hb_paint_extend_t get_extend () const
{
return (this+colorLine).get_extend ();
}
HBUINT8 format; /* format = 6(noVar) or 7 (Var) */
Offset24To<ColorLine<Var>> colorLine; /* Offset (from beginning of PaintRadialGradient
* table) to ColorLine subtable. */
@ -684,7 +665,7 @@ struct PaintSweepGradient
void paint_glyph (hb_paint_context_t *c, uint32_t varIdxBase) const
{
hb_color_line_t cl = { this, format };
hb_color_line_t cl = { &(this+colorLine), Var<ColorLine<Var>>::is_variable };
c->funcs->sweep_gradient (c->data, &cl,
centerX + c->instancer (varIdxBase, 0),
@ -693,18 +674,6 @@ struct PaintSweepGradient
(endAngle.to_float (c->instancer (varIdxBase, 3)) + 1) * (float) M_PI);
}
unsigned int get_color_stops (unsigned int start,
unsigned int *count,
hb_color_stop_t *stops) const
{
return (this+colorLine).get_color_stops (start, count, stops);
}
hb_paint_extend_t get_extend () const
{
return (this+colorLine).get_extend ();
}
HBUINT8 format; /* format = 8(noVar) or 9 (Var) */
Offset24To<ColorLine<Var>> colorLine; /* Offset (from beginning of PaintSweepGradient
* table) to ColorLine subtable. */