Simplify get_glyph_alternates() dispatcher
Trying to make it **very simple** to add a specialized dispatcher for one API to be routed to just a few objects (one in this case).
This commit is contained in:
parent
ffe8d3f39d
commit
b2a1acccd9
|
@ -643,9 +643,12 @@ struct AlternateSubstFormat1
|
||||||
{ return c->len == 1 && (this+coverage).get_coverage (c->glyphs[0]) != NOT_COVERED; }
|
{ return c->len == 1 && (this+coverage).get_coverage (c->glyphs[0]) != NOT_COVERED; }
|
||||||
|
|
||||||
unsigned
|
unsigned
|
||||||
get_glyph_alternates (hb_get_glyph_alternates_context_t *c) const
|
get_glyph_alternates (hb_codepoint_t gid,
|
||||||
{ return (this+alternateSet[(this+coverage).get_coverage (c->gid)])
|
unsigned start_offset,
|
||||||
.get_alternates (c->start_offset, c->alternate_count, c->alternate_glyphs); }
|
unsigned *alternate_count /* IN/OUT. May be NULL. */,
|
||||||
|
hb_codepoint_t *alternate_glyphs /* OUT. May be NULL. */) const
|
||||||
|
{ return (this+alternateSet[(this+coverage).get_coverage (gid)])
|
||||||
|
.get_alternates (start_offset, alternate_count, alternate_glyphs); }
|
||||||
|
|
||||||
bool apply (hb_ot_apply_context_t *c) const
|
bool apply (hb_ot_apply_context_t *c) const
|
||||||
{
|
{
|
||||||
|
|
|
@ -227,46 +227,6 @@ struct hb_would_apply_context_t :
|
||||||
debug_depth (0) {}
|
debug_depth (0) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct hb_get_glyph_alternates_context_t :
|
|
||||||
hb_dispatch_context_t<hb_get_glyph_alternates_context_t, unsigned, 0>
|
|
||||||
{
|
|
||||||
const char *get_name () { return "GET_GLYPH_ALTERNATES"; }
|
|
||||||
static return_t default_return_value () { return 0; }
|
|
||||||
bool stop_sublookup_iteration (return_t r) const { return r; }
|
|
||||||
|
|
||||||
hb_face_t *face;
|
|
||||||
hb_codepoint_t gid;
|
|
||||||
unsigned start_offset;
|
|
||||||
unsigned *alternate_count;
|
|
||||||
hb_codepoint_t *alternate_glyphs;
|
|
||||||
unsigned int debug_depth;
|
|
||||||
|
|
||||||
hb_get_glyph_alternates_context_t (hb_face_t *face_,
|
|
||||||
hb_codepoint_t gid_,
|
|
||||||
unsigned start_offset_,
|
|
||||||
unsigned *alternate_count_,
|
|
||||||
hb_codepoint_t *alternate_glyphs_) :
|
|
||||||
face (face_),
|
|
||||||
gid (gid_),
|
|
||||||
start_offset (start_offset_),
|
|
||||||
alternate_count (alternate_count_),
|
|
||||||
alternate_glyphs (alternate_glyphs_),
|
|
||||||
debug_depth (0) {}
|
|
||||||
|
|
||||||
private:
|
|
||||||
template <typename T> auto
|
|
||||||
_dispatch (const T &obj, hb_priority<1>) HB_AUTO_RETURN
|
|
||||||
( obj.get_glyph_alternates (this) )
|
|
||||||
template <typename T> auto
|
|
||||||
_dispatch (const T &obj, hb_priority<0>) HB_AUTO_RETURN
|
|
||||||
( default_return_value () )
|
|
||||||
public:
|
|
||||||
template <typename T> auto
|
|
||||||
dispatch (const T &obj) HB_AUTO_RETURN
|
|
||||||
( _dispatch (obj, hb_prioritize) )
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
struct hb_collect_glyphs_context_t :
|
struct hb_collect_glyphs_context_t :
|
||||||
hb_dispatch_context_t<hb_collect_glyphs_context_t, hb_empty_t, 0>
|
hb_dispatch_context_t<hb_collect_glyphs_context_t, hb_empty_t, 0>
|
||||||
{
|
{
|
||||||
|
|
|
@ -1969,6 +1969,34 @@ hb_ot_layout_get_baseline (hb_font_t *font,
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
struct hb_get_glyph_alternates_context_t :
|
||||||
|
hb_dispatch_context_t<hb_get_glyph_alternates_context_t, unsigned, 0>
|
||||||
|
{
|
||||||
|
const char *get_name () { return "GET_GLYPH_ALTERNATES"; }
|
||||||
|
static return_t default_return_value () { return 0; }
|
||||||
|
bool stop_sublookup_iteration (return_t r) const { return r; }
|
||||||
|
|
||||||
|
hb_face_t *face;
|
||||||
|
unsigned int debug_depth;
|
||||||
|
|
||||||
|
hb_get_glyph_alternates_context_t (hb_face_t *face) :
|
||||||
|
face (face),
|
||||||
|
debug_depth (0) {}
|
||||||
|
|
||||||
|
private:
|
||||||
|
template <typename T, typename ...Ts> auto
|
||||||
|
_dispatch (const T &obj, hb_priority<1>, Ts&&... ds) HB_AUTO_RETURN
|
||||||
|
( obj.get_glyph_alternates (hb_forward<Ts> (ds)...) )
|
||||||
|
template <typename T, typename ...Ts> auto
|
||||||
|
_dispatch (const T &obj, hb_priority<0>, Ts&&... ds) HB_AUTO_RETURN
|
||||||
|
( default_return_value () )
|
||||||
|
public:
|
||||||
|
template <typename T, typename ...Ts> auto
|
||||||
|
dispatch (const T &obj, Ts&&... ds) HB_AUTO_RETURN
|
||||||
|
( _dispatch (obj, hb_prioritize, hb_forward<Ts> (ds)...) )
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* hb_ot_layout_lookup_get_glyph_alternates:
|
* hb_ot_layout_lookup_get_glyph_alternates:
|
||||||
* @face: a face.
|
* @face: a face.
|
||||||
|
@ -1994,9 +2022,9 @@ hb_ot_layout_lookup_get_glyph_alternates (hb_face_t *face,
|
||||||
unsigned *alternate_count /* IN/OUT. May be NULL. */,
|
unsigned *alternate_count /* IN/OUT. May be NULL. */,
|
||||||
hb_codepoint_t *alternate_glyphs /* OUT. May be NULL. */)
|
hb_codepoint_t *alternate_glyphs /* OUT. May be NULL. */)
|
||||||
{
|
{
|
||||||
OT::hb_get_glyph_alternates_context_t c (face, glyph, start_offset, alternate_count, alternate_glyphs);
|
hb_get_glyph_alternates_context_t c (face);
|
||||||
const OT::SubstLookup &lookup = face->table.GSUB->table->get_lookup (lookup_index);
|
const OT::SubstLookup &lookup = face->table.GSUB->table->get_lookup (lookup_index);
|
||||||
auto ret = lookup.dispatch (&c);
|
auto ret = lookup.dispatch (&c, glyph, start_offset, alternate_count, alternate_glyphs);
|
||||||
if (!ret && alternate_count) *alternate_count = 0;
|
if (!ret && alternate_count) *alternate_count = 0;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue