Rename 'solid' to 'color'

'solid' does not really describe well what
the function does, and there is no strong
reason to stick 1:1 to the terminology used
in the spec.
This commit is contained in:
Matthias Clasen 2022-12-17 00:07:30 -05:00 committed by Behdad Esfahbod
parent 2c07828603
commit 0d890061d1
6 changed files with 333 additions and 47 deletions

View File

@ -530,7 +530,7 @@ 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->solid (c->data, c->funcs->color (c->data,
paletteIndex, paletteIndex,
alpha.to_float (c->instancer (varIdxBase, 0))); alpha.to_float (c->instancer (varIdxBase, 0)));
} }
@ -1987,7 +1987,7 @@ struct COLR
const LayerRecord *r = &all_layers[record.firstLayerIdx + i]; const LayerRecord *r = &all_layers[record.firstLayerIdx + i];
c.funcs->push_clip_glyph (c.data, r->glyphId); c.funcs->push_clip_glyph (c.data, r->glyphId);
c.funcs->solid (c.data, r->colorIdx, 1.); c.funcs->color (c.data, r->colorIdx, 1.);
c.funcs->pop_clip (c.data); c.funcs->pop_clip (c.data);
} }
} }

View File

@ -0,0 +1,286 @@
/*
* Copyright © 2022 Matthias Clasen
*
* This is part of HarfBuzz, a text shaping library.
*
* Permission is hereby granted, without written agreement and without
* license or royalty fees, to use, copy, modify, and distribute this
* software and its documentation for any purpose, provided that the
* above copyright notice and the following two paragraphs appear in
* all copies of this software.
*
* IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
* IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
* THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
*
*/
#ifndef HB_OT_COLR_COLRV1_PAINT_HH
#define HB_OT_COLR_COLRV1_PAINT_HH
#include "hb-open-type.hh"
#include "hb-ot-layout-common.hh"
#include "hb-ot-color-colr-table.hh"
/*
* COLR -- Color
* https://docs.microsoft.com/en-us/typography/opentype/spec/colr
*/
namespace OT {
struct hb_colrv1_paint_context_t :
hb_dispatch_context_t<hb_colrv1_paint_context_t>
{
template <typename T>
return_t dispatch (const T &obj)
{
obj.paint (this);
return hb_empty_t ();
}
const COLR* get_colr_table () const
{ return reinterpret_cast<const COLR *> (base); }
public:
const void *base;
hb_paint_funcs_t *funcs;
void *paint_data;
hb_colrv1_paint_context_t (const void *base_, hb_paint_funcs_t *funcs_, void *paint_data_)
base (base_), funcs (funcs_), paint_data (paint_data_)
{}
void push_transform (float xx, float yx,
float xy, float yy,
float x0, float y0)
{
funcs->push_transform (paint_data, xx, yx, xy, yy, x0, y0);
}
void pop_transform ()
{
funcs->pop_transform (paint_data);
}
void push_clip (hb_codepoint_t gid)
{
funcs->push_clip (paint_data, gid);
}
void pop_clip ()
{
funcs->pop_clip (paint_data);
}
void solid (unsigned int color_index)
{
funcs->solid (paint_data, color_index);
}
void linear_gradient (hb_color_line *color_line,
float x0, float y0,
float x1, float y1,
float x2, float y2)
{
funcs->linear_gradient (paint_data,
color_line, x0, y0, x1, y1, x2, y2);
}
void radial_gradient (hb_color_line *color_line,
float x0, float y0, float r0,
float x1, float y1, float r1)
{
funcs->radial_gradient (paint_data,
color_line, x0, y0, r0, x1, y1, r1);
}
void sweep_gradient (hb_color_line *color_line,
float x0, float y0,
float start_angle, float end_angle)'
{
funcs->sweep_gradient (paint_data,
color_line, x0, y0, start_angle, end_angle);
}
void push_group ()
{
funcs->push_group (paint_data);
}
void pop_group_and_composite (hb_paint_composite_mode_t mode)
{
funcs->pop_group_and_composite (paint_data, mode);
}
}
HB_INTERNAL void PaintColrLayers::paint (hb_colrv1_paint_context_t *c) const
{
const COLR *colr_table = c->get_colr_table ();
const LayerList &paint_offset_lists = colr_table->get_layerList ();
for (unsigned i = firstLayerIndex; i < firstLayerIndex + numLayers; i++)
{
const Paint &paint = std::addressof (paint_offset_lists) + paint_offset_lists[i];
c->push_group ();
paint.dispatch (c);
c->pop_group_and_composite (HB_PAINT_COMPOSITE_MODE_OVER);
}
}
HB_INTERNAL void PaintGlyph::paint (hb_colrv1_paint_context_t *c) const
{
c->push_clip (gid);
(this+paint).dispatch (c);
c->pop_clip ();
}
HB_INTERNAL void PaintColrGlyph::paint (hb_colrv1_paint_context_t *c) const
{
const COLR *colr_table = c->get_colr_table ();
const BaseGlyphPaintRecord* baseglyph_paintrecord = colr_table->get_base_glyph_paintrecord (gid);
if (!baseglyph_paintrecord) return;
c->push_clip (gid);
const BaseGlyphList &baseglyph_list = colr_table->get_baseglyphList ();
(&baseglyph_list+baseglyph_paintrecord->paint).dispatch (c);
c->pop_clip ();
}
template <template<typename> class Var>
HB_INTERNAL void PaintTransform<Var>::paint (hb_colrv1_paint_context_t* c) const
{
c->push_transform (transform.xx, transform.yx,
transform.xy, transform.yy,
transform.dx, transform.dy);
(this+src).dispatch (c);
c->pop_transform ();
}
HB_INTERNAL void PaintTranslate::paint (hb_colrv1_paint_context_t* c) const
{
c->push_transform (0, 0, 0, 0, dx, dy);
(this+src).dispatch (c);
c->pop_transform ();
}
HB_INTERNAL void PaintScale::paint (hb_colrv1_paint_context_t* c) const
{
c->push_transform (scaleX, 0, 0, scaleY, 0, 0);
(this+src).dispatch (c);
c->pop_transform ();
}
HB_INTERNAL void PaintScaleAroundCenter::paint (hb_colrv1_paint_context_t* c) const
{
c->push_transform (0, 0, 0, 0, - centerX, - centerY);
c->push_transform (scaleX, 0, 0, scaleY, 0, 0);
c->push_transform (0, 0, 0, 0, centerX, centerY);
(this+src).dispatch (c);
c->pop_transform ();
c->pop_transform ();
c->pop_transform ();
}
HB_INTERNAL void PaintScaleUniform::paint (hb_colrv1_paint_context_t* c) const
{
c->push_transform (scale, 0, 0, scale, 0, 0);
(this+src).dispatch (c);
c->pop_transform ();
}
HB_INTERNAL void PaintScaleUniformAroundCenter::paint (hb_colrv1_paint_context_t* c) const
{
c->push_transform (0, 0, 0, 0, - centerX, - centerY);
c->push_transform (scale, 0, 0, scale, 0, 0);
c->push_transform (0, 0, 0, 0, centerX, centerY);
(this+src).dispatch (c);
c->pop_transform ();
c->pop_transform ();
c->pop_transform ();
}
HB_INTERNAL void PaintRotate::paint (hb_colrv1_paint_context_t* c) const
{
c->push_transform (cos (angle), sin (angle),
- sin (angle), cos (angle),
0, 0);
(this+src).dispatch (c);
c->pop_transform ();
}
HB_INTERNAL void PaintRotateAroundCenter::paint (hb_colrv1_paint_context_t* c) const
{
c->push_transform (0, 0, 0, 0, - centerX, - centerY);
c->push_transform (cos (angle), sin (angle),
- sin (angle), cos (angle),
0, 0);
c->push_transform (0, 0, 0, 0, centerX, centerY);
(this+src).dispatch (c);
c->pop_transform ();
c->pop_transform ();
c->pop_transform ();
}
HB_INTERNAL void PaintSkew::paint (hb_colrv1_paint_context_t* c) const
{
c->push_transform (1, tan (ySkewAngle),
- tan (xSkewAngle), 1,
0, 0);
(this+src).dispatch (c);
c->pop_transform ();
}
HB_INTERNAL void PaintSkewAroundCenter::paint (hb_colrv1_paint_context_t* c) const
{
c->push_transform (0, 0, 0, 0, - centerX, - centerY);
c->push_transform (1, tan (ySkewAngle),
- tan (xSkewAngle), 1,
0, 0);
c->push_transform (0, 0, 0, 0, centerX, centerY);
(this+src).dispatch (c);
c->pop_transform ();
c->pop_transform ();
c->pop_transform ();
}
HB_INTERNAL void PaintComposite::paint (hb_colrv1_paint_context_t* c) const
{
c->push_group ();
(this+src).dispatch (c);
c->push_group ();
(this+backdrop).dispatch (c);
c->pop_group_and_composite (mode);
c->pop_group_and_composite (HB_PAINT_COMPOSITE_MODE_OVER);
}
HB_INTERNAL void PaintSolid::paint (hb_colrv1_paint_context_t *c) const
{
c->solid (paletteIndex);
}
HB_INTERNAL void PaintLinearGradient::paint (hb_colrv1_paint_context_t *c) const
{
c->linear_gradient (color_line, x0, y0, x1, y1, x2, y2);
}
HB_INTERNAL void PaintRadialGradient::paint (hb_colrv1_paint_context_t *c) const
{
c->radial_gradient (color_line, x0, y0, radius0, x1, y1, radius1);
}
HB_INTERNAL void PaintSweepGradient::paint (hb_colrv1_paint_context_t *c) const
{
c->sweep_gradient (color_line, centerX, centerY, startAngle, endAngle);
}
} /* namespace OT */
#endif /* HB_OT_COLR_COLRV1_CLOSURE_HH */

View File

@ -63,7 +63,7 @@ hb_paint_pop_clip_nil (hb_paint_funcs_t *funcs, void *paint_data,
void *user_data) {} void *user_data) {}
static void static void
hb_paint_solid_nil (hb_paint_funcs_t *funcs, void *paint_data, hb_paint_color_nil (hb_paint_funcs_t *funcs, void *paint_data,
unsigned int color_index, unsigned int color_index,
float alpha, float alpha,
void *user_data) {} void *user_data) {}
@ -330,11 +330,11 @@ hb_paint_pop_clip (hb_paint_funcs_t *funcs, void *paint_data)
} }
void void
hb_paint_solid (hb_paint_funcs_t *funcs, void *paint_data, hb_paint_color (hb_paint_funcs_t *funcs, void *paint_data,
unsigned int color_index, unsigned int color_index,
float alpha) float alpha)
{ {
funcs->solid (paint_data, color_index, alpha); funcs->color (paint_data, color_index, alpha);
} }
void void

View File

@ -187,14 +187,14 @@ typedef void (*hb_paint_pop_clip_func_t) (hb_paint_funcs_t *funcs,
void *user_data); void *user_data);
/** /**
* hb_paint_solid_func_t: * hb_paint_color_func_t:
* @funcs: paint functions object * @funcs: paint functions object
* @paint_data: The data accompanying the paint functions * @paint_data: The data accompanying the paint functions
* @color_index: Index of a color in the fonts selected color palette * @color_index: Index of a color in the fonts selected color palette
* @alpha: alpha to apply in addition * @alpha: alpha to apply in addition
* @user_data: user data passed to the hb_font_paint_glyph() call * @user_data: user data passed to the hb_font_paint_glyph() call
* *
* A virtual method for the #hb_paint_funcs_t to paint a solid * A virtual method for the #hb_paint_funcs_t to paint a
* color everywhere within the current clip. * color everywhere within the current clip.
* *
* The @color_index can be either an index into one of the fonts * The @color_index can be either an index into one of the fonts
@ -206,7 +206,7 @@ typedef void (*hb_paint_pop_clip_func_t) (hb_paint_funcs_t *funcs,
* *
* Since: REPLACEME * Since: REPLACEME
*/ */
typedef void (*hb_paint_solid_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,
unsigned int color_index, unsigned int color_index,
float alpha, float alpha,
@ -510,19 +510,19 @@ hb_paint_funcs_set_pop_clip_func (hb_paint_funcs_t *funcs,
hb_destroy_func_t destroy); hb_destroy_func_t destroy);
/** /**
* hb_paint_funcs_set_solid_func: * hb_paint_funcs_set_color_func:
* @funcs: A paint functions struct * @funcs: A paint functions struct
* @func: (closure user_data) (destroy destroy) (scope notified): The paint-solid callback * @func: (closure user_data) (destroy destroy) (scope notified): The paint-color callback
* @user_data: Data to pass to @func * @user_data: Data to pass to @func
* @destroy: (nullable): Function to call when @user_data is no longer needed * @destroy: (nullable): Function to call when @user_data is no longer needed
* *
* Sets the paint-solid callback on the paint functions struct. * Sets the paint-color callback on the paint functions struct.
* *
* Since: REPLACEME * Since: REPLACEME
*/ */
HB_EXTERN void HB_EXTERN void
hb_paint_funcs_set_solid_func (hb_paint_funcs_t *funcs, hb_paint_funcs_set_color_func (hb_paint_funcs_t *funcs,
hb_paint_solid_func_t func, hb_paint_color_func_t func,
void *user_data, void *user_data,
hb_destroy_func_t destroy); hb_destroy_func_t destroy);
@ -633,7 +633,7 @@ HB_EXTERN void
hb_paint_pop_clip (hb_paint_funcs_t *funcs, void *paint_data); hb_paint_pop_clip (hb_paint_funcs_t *funcs, void *paint_data);
HB_EXTERN void HB_EXTERN void
hb_paint_solid (hb_paint_funcs_t *funcs, void *paint_data, hb_paint_color (hb_paint_funcs_t *funcs, void *paint_data,
unsigned int color_index, unsigned int color_index,
float alpha); float alpha);

View File

@ -33,7 +33,7 @@
HB_PAINT_FUNC_IMPLEMENT (push_clip_glyph) \ HB_PAINT_FUNC_IMPLEMENT (push_clip_glyph) \
HB_PAINT_FUNC_IMPLEMENT (push_clip_rect) \ HB_PAINT_FUNC_IMPLEMENT (push_clip_rect) \
HB_PAINT_FUNC_IMPLEMENT (pop_clip) \ HB_PAINT_FUNC_IMPLEMENT (pop_clip) \
HB_PAINT_FUNC_IMPLEMENT (solid) \ HB_PAINT_FUNC_IMPLEMENT (color) \
HB_PAINT_FUNC_IMPLEMENT (linear_gradient) \ HB_PAINT_FUNC_IMPLEMENT (linear_gradient) \
HB_PAINT_FUNC_IMPLEMENT (radial_gradient) \ HB_PAINT_FUNC_IMPLEMENT (radial_gradient) \
HB_PAINT_FUNC_IMPLEMENT (sweep_gradient) \ HB_PAINT_FUNC_IMPLEMENT (sweep_gradient) \
@ -86,12 +86,12 @@ struct hb_paint_funcs_t
void pop_clip (void *paint_data) void pop_clip (void *paint_data)
{ 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 solid (void *paint_data, void color (void *paint_data,
unsigned int color_index, unsigned int color_index,
float alpha) float alpha)
{ func.solid (this, paint_data, { func.color (this, paint_data,
color_index, alpha, color_index, alpha,
!user_data ? nullptr : user_data->solid); } !user_data ? nullptr : user_data->color); }
void linear_gradient (void *paint_data, void linear_gradient (void *paint_data,
hb_color_line_t *color_line, hb_color_line_t *color_line,
float x0, float y0, float x0, float y0,

View File

@ -275,7 +275,7 @@ pop_clip (hb_paint_funcs_t *funcs,
} }
static void static void
solid (hb_paint_funcs_t *funcs, paint_color (hb_paint_funcs_t *funcs,
void *paint_data, void *paint_data,
unsigned int color_index, unsigned int color_index,
float alpha, float alpha,
@ -368,7 +368,7 @@ normalize_color_line (hb_color_stop_t *stops,
} }
static void static void
linear_gradient (hb_paint_funcs_t *funcs, paint_linear_gradient (hb_paint_funcs_t *funcs,
void *paint_data, void *paint_data,
hb_color_line_t *color_line, hb_color_line_t *color_line,
float x0, float y0, float x0, float y0,
@ -423,7 +423,7 @@ linear_gradient (hb_paint_funcs_t *funcs,
} }
static void static void
radial_gradient (hb_paint_funcs_t *funcs, paint_radial_gradient (hb_paint_funcs_t *funcs,
void *paint_data, void *paint_data,
hb_color_line_t *color_line, hb_color_line_t *color_line,
float x0, float y0, float r0, float x0, float y0, float r0,
@ -854,7 +854,7 @@ done: ;
} }
static void static void
sweep_gradient (hb_paint_funcs_t *funcs, paint_sweep_gradient (hb_paint_funcs_t *funcs,
void *paint_data, void *paint_data,
hb_color_line_t *color_line, hb_color_line_t *color_line,
float cx, float cy, float cx, float cy,
@ -1007,10 +1007,10 @@ int main (int argc, char *argv[])
hb_paint_funcs_set_pop_clip_func (funcs, pop_clip, &data, NULL); hb_paint_funcs_set_pop_clip_func (funcs, pop_clip, &data, NULL);
hb_paint_funcs_set_push_group_func (funcs, push_group, &data, NULL); hb_paint_funcs_set_push_group_func (funcs, push_group, &data, NULL);
hb_paint_funcs_set_pop_group_func (funcs, pop_group, &data, NULL); hb_paint_funcs_set_pop_group_func (funcs, pop_group, &data, NULL);
hb_paint_funcs_set_solid_func (funcs, solid, &data, NULL); hb_paint_funcs_set_color_func (funcs, paint_color, &data, NULL);
hb_paint_funcs_set_linear_gradient_func (funcs, linear_gradient, &data, NULL); hb_paint_funcs_set_linear_gradient_func (funcs, paint_linear_gradient, &data, NULL);
hb_paint_funcs_set_radial_gradient_func (funcs, radial_gradient, &data, NULL); hb_paint_funcs_set_radial_gradient_func (funcs, paint_radial_gradient, &data, NULL);
hb_paint_funcs_set_sweep_gradient_func (funcs, sweep_gradient, &data, NULL); hb_paint_funcs_set_sweep_gradient_func (funcs, paint_sweep_gradient, &data, NULL);
hb_font_paint_glyph (font, gid, funcs, NULL); hb_font_paint_glyph (font, gid, funcs, NULL);