[colr] Simplify color-stop handling
This commit is contained in:
parent
485ba9beb3
commit
c6dd56cc64
|
@ -31,43 +31,17 @@ hb_color_line_get_color_stops (hb_color_line_t *cl,
|
||||||
unsigned int *count,
|
unsigned int *count,
|
||||||
hb_color_stop_t *color_stops)
|
hb_color_stop_t *color_stops)
|
||||||
{
|
{
|
||||||
switch (cl->format)
|
if (cl->is_variable)
|
||||||
{
|
return reinterpret_cast<const OT::ColorLine<OT::Variable> *>(cl->base)->get_color_stops (start, count, color_stops);
|
||||||
case 4:
|
else
|
||||||
return reinterpret_cast<const OT::PaintLinearGradient<OT::NoVariable> *>(cl->base)->get_color_stops (start, count, color_stops);
|
return reinterpret_cast<const OT::ColorLine<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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
hb_paint_extend_t
|
hb_paint_extend_t
|
||||||
hb_color_line_get_extend (hb_color_line_t *cl)
|
hb_color_line_get_extend (hb_color_line_t *cl)
|
||||||
{
|
{
|
||||||
switch (cl->format)
|
if (cl->is_variable)
|
||||||
{
|
return reinterpret_cast<const OT::ColorLine<OT::Variable> *>(cl->base)->get_extend ();
|
||||||
case 4:
|
else
|
||||||
return reinterpret_cast<const OT::PaintLinearGradient<OT::NoVariable> *>(cl->base)->get_extend ();
|
return reinterpret_cast<const OT::ColorLine<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;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,9 +44,10 @@
|
||||||
#define HB_COLRV1_MAX_NESTING_LEVEL 128
|
#define HB_COLRV1_MAX_NESTING_LEVEL 128
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
struct hb_color_line_t {
|
struct hb_color_line_t {
|
||||||
const void *base;
|
const void *base;
|
||||||
OT::HBUINT8 format;
|
bool is_variable;
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace OT {
|
namespace OT {
|
||||||
|
@ -200,6 +201,8 @@ struct BaseGlyphRecord
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct Variable
|
struct Variable
|
||||||
{
|
{
|
||||||
|
static constexpr bool is_variable = true;
|
||||||
|
|
||||||
Variable<T>* copy (hb_serialize_context_t *c) const
|
Variable<T>* copy (hb_serialize_context_t *c) const
|
||||||
{
|
{
|
||||||
TRACE_SERIALIZE (this);
|
TRACE_SERIALIZE (this);
|
||||||
|
@ -248,6 +251,8 @@ struct Variable
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct NoVariable
|
struct NoVariable
|
||||||
{
|
{
|
||||||
|
static constexpr bool is_variable = false;
|
||||||
|
|
||||||
static constexpr uint32_t varIdxBase = VarIdx::NO_VARIATION;
|
static constexpr uint32_t varIdxBase = VarIdx::NO_VARIATION;
|
||||||
|
|
||||||
NoVariable<T>* copy (hb_serialize_context_t *c) const
|
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
|
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,
|
c->funcs->linear_gradient (c->data, &cl,
|
||||||
x0 + c->instancer (varIdxBase, 0),
|
x0 + c->instancer (varIdxBase, 0),
|
||||||
|
@ -577,18 +582,6 @@ struct PaintLinearGradient
|
||||||
y2 + c->instancer (varIdxBase, 5));
|
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) */
|
HBUINT8 format; /* format = 4(noVar) or 5 (Var) */
|
||||||
Offset24To<ColorLine<Var>> colorLine; /* Offset (from beginning of PaintLinearGradient
|
Offset24To<ColorLine<Var>> colorLine; /* Offset (from beginning of PaintLinearGradient
|
||||||
* table) to ColorLine subtable. */
|
* table) to ColorLine subtable. */
|
||||||
|
@ -625,7 +618,7 @@ struct PaintRadialGradient
|
||||||
|
|
||||||
void paint_glyph (hb_paint_context_t *c, uint32_t varIdxBase) const
|
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,
|
c->funcs->radial_gradient (c->data, &cl,
|
||||||
x0 + c->instancer (varIdxBase, 0),
|
x0 + c->instancer (varIdxBase, 0),
|
||||||
|
@ -636,18 +629,6 @@ struct PaintRadialGradient
|
||||||
radius1 + c->instancer (varIdxBase, 5));
|
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) */
|
HBUINT8 format; /* format = 6(noVar) or 7 (Var) */
|
||||||
Offset24To<ColorLine<Var>> colorLine; /* Offset (from beginning of PaintRadialGradient
|
Offset24To<ColorLine<Var>> colorLine; /* Offset (from beginning of PaintRadialGradient
|
||||||
* table) to ColorLine subtable. */
|
* table) to ColorLine subtable. */
|
||||||
|
@ -684,7 +665,7 @@ struct PaintSweepGradient
|
||||||
|
|
||||||
void paint_glyph (hb_paint_context_t *c, uint32_t varIdxBase) const
|
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,
|
c->funcs->sweep_gradient (c->data, &cl,
|
||||||
centerX + c->instancer (varIdxBase, 0),
|
centerX + c->instancer (varIdxBase, 0),
|
||||||
|
@ -693,18 +674,6 @@ struct PaintSweepGradient
|
||||||
(endAngle.to_float (c->instancer (varIdxBase, 3)) + 1) * (float) M_PI);
|
(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) */
|
HBUINT8 format; /* format = 8(noVar) or 9 (Var) */
|
||||||
Offset24To<ColorLine<Var>> colorLine; /* Offset (from beginning of PaintSweepGradient
|
Offset24To<ColorLine<Var>> colorLine; /* Offset (from beginning of PaintSweepGradient
|
||||||
* table) to ColorLine subtable. */
|
* table) to ColorLine subtable. */
|
||||||
|
|
Loading…
Reference in New Issue