提交 36608941 编写于 作者: B Behdad Esfahbod

Add GSUB "would_apply" API

To be used in the Indic shaper later.  Unused for now.
上级 a0d4caeb
...@@ -39,6 +39,11 @@ struct SingleSubstFormat1 ...@@ -39,6 +39,11 @@ struct SingleSubstFormat1
private: private:
inline bool would_apply (hb_codepoint_t glyph_id) const
{
return (this+coverage) (glyph_id) != NOT_COVERED;
}
inline bool apply (hb_apply_context_t *c) const inline bool apply (hb_apply_context_t *c) const
{ {
TRACE_APPLY (); TRACE_APPLY ();
...@@ -78,6 +83,11 @@ struct SingleSubstFormat2 ...@@ -78,6 +83,11 @@ struct SingleSubstFormat2
private: private:
inline bool would_apply (hb_codepoint_t glyph_id) const
{
return (this+coverage) (glyph_id) != NOT_COVERED;
}
inline bool apply (hb_apply_context_t *c) const inline bool apply (hb_apply_context_t *c) const
{ {
TRACE_APPLY (); TRACE_APPLY ();
...@@ -119,6 +129,15 @@ struct SingleSubst ...@@ -119,6 +129,15 @@ struct SingleSubst
private: private:
inline bool would_apply (hb_codepoint_t glyph_id) const
{
switch (u.format) {
case 1: return u.format1.would_apply (glyph_id);
case 2: return u.format2.would_apply (glyph_id);
default:return false;
}
}
inline bool apply (hb_apply_context_t *c) const inline bool apply (hb_apply_context_t *c) const
{ {
TRACE_APPLY (); TRACE_APPLY ();
...@@ -185,6 +204,11 @@ struct MultipleSubstFormat1 ...@@ -185,6 +204,11 @@ struct MultipleSubstFormat1
private: private:
inline bool would_apply (hb_codepoint_t glyph_id) const
{
return (this+coverage) (glyph_id) != NOT_COVERED;
}
inline bool apply (hb_apply_context_t *c) const inline bool apply (hb_apply_context_t *c) const
{ {
TRACE_APPLY (); TRACE_APPLY ();
...@@ -220,6 +244,14 @@ struct MultipleSubst ...@@ -220,6 +244,14 @@ struct MultipleSubst
private: private:
inline bool would_apply (hb_codepoint_t glyph_id) const
{
switch (u.format) {
case 1: return u.format1.would_apply (glyph_id);
default:return false;
}
}
inline bool apply (hb_apply_context_t *c) const inline bool apply (hb_apply_context_t *c) const
{ {
TRACE_APPLY (); TRACE_APPLY ();
...@@ -255,12 +287,15 @@ struct AlternateSubstFormat1 ...@@ -255,12 +287,15 @@ struct AlternateSubstFormat1
private: private:
inline bool would_apply (hb_codepoint_t glyph_id) const
{
return (this+coverage) (glyph_id) != NOT_COVERED;
}
inline bool apply (hb_apply_context_t *c) const inline bool apply (hb_apply_context_t *c) const
{ {
TRACE_APPLY (); TRACE_APPLY ();
hb_codepoint_t glyph_id = c->buffer->info[c->buffer->idx].codepoint; hb_codepoint_t glyph_id = c->buffer->info[c->buffer->idx].codepoint;
hb_mask_t glyph_mask = c->buffer->info[c->buffer->idx].mask;
hb_mask_t lookup_mask = c->lookup_mask;
unsigned int index = (this+coverage) (glyph_id); unsigned int index = (this+coverage) (glyph_id);
if (likely (index == NOT_COVERED)) if (likely (index == NOT_COVERED))
...@@ -271,6 +306,9 @@ struct AlternateSubstFormat1 ...@@ -271,6 +306,9 @@ struct AlternateSubstFormat1
if (unlikely (!alt_set.len)) if (unlikely (!alt_set.len))
return false; return false;
hb_mask_t glyph_mask = c->buffer->info[c->buffer->idx].mask;
hb_mask_t lookup_mask = c->lookup_mask;
/* Note: This breaks badly if two features enabled this lookup together. */ /* Note: This breaks badly if two features enabled this lookup together. */
unsigned int shift = _hb_ctz (lookup_mask); unsigned int shift = _hb_ctz (lookup_mask);
unsigned int alt_index = ((lookup_mask & glyph_mask) >> shift); unsigned int alt_index = ((lookup_mask & glyph_mask) >> shift);
...@@ -309,6 +347,14 @@ struct AlternateSubst ...@@ -309,6 +347,14 @@ struct AlternateSubst
private: private:
inline bool would_apply (hb_codepoint_t glyph_id) const
{
switch (u.format) {
case 1: return u.format1.would_apply (glyph_id);
default:return false;
}
}
inline bool apply (hb_apply_context_t *c) const inline bool apply (hb_apply_context_t *c) const
{ {
TRACE_APPLY (); TRACE_APPLY ();
...@@ -340,6 +386,12 @@ struct Ligature ...@@ -340,6 +386,12 @@ struct Ligature
friend struct LigatureSet; friend struct LigatureSet;
private: private:
inline bool would_apply (hb_codepoint_t second) const
{
return component.len == 2 && component[1] == second;
}
inline bool apply (hb_apply_context_t *c) const inline bool apply (hb_apply_context_t *c) const
{ {
TRACE_APPLY (); TRACE_APPLY ();
...@@ -429,6 +481,19 @@ struct LigatureSet ...@@ -429,6 +481,19 @@ struct LigatureSet
friend struct LigatureSubstFormat1; friend struct LigatureSubstFormat1;
private: private:
inline bool would_apply (hb_codepoint_t second) const
{
unsigned int num_ligs = ligature.len;
for (unsigned int i = 0; i < num_ligs; i++)
{
const Ligature &lig = this+ligature[i];
if (lig.would_apply (second))
return true;
}
return false;
}
inline bool apply (hb_apply_context_t *c) const inline bool apply (hb_apply_context_t *c) const
{ {
TRACE_APPLY (); TRACE_APPLY ();
...@@ -462,6 +527,14 @@ struct LigatureSubstFormat1 ...@@ -462,6 +527,14 @@ struct LigatureSubstFormat1
friend struct LigatureSubst; friend struct LigatureSubst;
private: private:
inline bool would_apply (hb_codepoint_t first, hb_codepoint_t second) const
{
unsigned int index;
return (index = (this+coverage) (first)) != NOT_COVERED &&
(this+ligatureSet[index]).would_apply (second);
}
inline bool apply (hb_apply_context_t *c) const inline bool apply (hb_apply_context_t *c) const
{ {
TRACE_APPLY (); TRACE_APPLY ();
...@@ -498,6 +571,15 @@ struct LigatureSubst ...@@ -498,6 +571,15 @@ struct LigatureSubst
friend struct SubstLookupSubTable; friend struct SubstLookupSubTable;
private: private:
inline bool would_apply (hb_codepoint_t first, hb_codepoint_t second) const
{
switch (u.format) {
case 1: return u.format1.would_apply (first, second);
default:return false;
}
}
inline bool apply (hb_apply_context_t *c) const inline bool apply (hb_apply_context_t *c) const
{ {
TRACE_APPLY (); TRACE_APPLY ();
...@@ -564,6 +646,9 @@ struct ExtensionSubst : Extension ...@@ -564,6 +646,9 @@ struct ExtensionSubst : Extension
return StructAtOffset<SubstLookupSubTable> (this, offset); return StructAtOffset<SubstLookupSubTable> (this, offset);
} }
inline bool would_apply (hb_codepoint_t glyph_id) const;
inline bool would_apply (hb_codepoint_t first, hb_codepoint_t second) const;
inline bool apply (hb_apply_context_t *c) const; inline bool apply (hb_apply_context_t *c) const;
inline bool sanitize (hb_sanitize_context_t *c); inline bool sanitize (hb_sanitize_context_t *c);
...@@ -689,6 +774,28 @@ struct SubstLookupSubTable ...@@ -689,6 +774,28 @@ struct SubstLookupSubTable
ReverseChainSingle = 8 ReverseChainSingle = 8
}; };
inline bool would_apply (hb_codepoint_t glyph_id,
unsigned int lookup_type) const
{
switch (lookup_type) {
case Single: return u.single.would_apply (glyph_id);
case Multiple: return u.multiple.would_apply (glyph_id);
case Alternate: return u.alternate.would_apply (glyph_id);
case Extension: return u.extension.would_apply (glyph_id);
default:return false;
}
}
inline bool would_apply (hb_codepoint_t first,
hb_codepoint_t second,
unsigned int lookup_type) const
{
switch (lookup_type) {
case Ligature: return u.ligature.would_apply (first, second);
case Extension: return u.extension.would_apply (first, second);
default:return false;
}
}
inline bool apply (hb_apply_context_t *c, unsigned int lookup_type) const inline bool apply (hb_apply_context_t *c, unsigned int lookup_type) const
{ {
TRACE_APPLY (); TRACE_APPLY ();
...@@ -754,6 +861,25 @@ struct SubstLookup : Lookup ...@@ -754,6 +861,25 @@ struct SubstLookup : Lookup
} }
inline bool would_apply (hb_codepoint_t glyph_id) const
{
unsigned int lookup_type = get_type ();
unsigned int count = get_subtable_count ();
for (unsigned int i = 0; i < count; i++)
if (get_subtable (i).would_apply (glyph_id, lookup_type))
return true;
return false;
}
inline bool would_apply (hb_codepoint_t first, hb_codepoint_t second) const
{
unsigned int lookup_type = get_type ();
unsigned int count = get_subtable_count ();
for (unsigned int i = 0; i < count; i++)
if (get_subtable (i).would_apply (first, second, lookup_type))
return true;
return false;
}
inline bool apply_once (hb_apply_context_t *c) const inline bool apply_once (hb_apply_context_t *c) const
{ {
unsigned int lookup_type = get_type (); unsigned int lookup_type = get_type ();
...@@ -889,6 +1015,16 @@ GSUB::substitute_finish (hb_buffer_t *buffer) ...@@ -889,6 +1015,16 @@ GSUB::substitute_finish (hb_buffer_t *buffer)
/* Out-of-class implementation for methods recursing */ /* Out-of-class implementation for methods recursing */
inline bool ExtensionSubst::would_apply (hb_codepoint_t glyph_id) const
{
return get_subtable ().would_apply (glyph_id, get_type ());
}
inline bool ExtensionSubst::would_apply (hb_codepoint_t first, hb_codepoint_t second) const
{
return get_subtable ().would_apply (first, second, get_type ());
}
inline bool ExtensionSubst::apply (hb_apply_context_t *c) const inline bool ExtensionSubst::apply (hb_apply_context_t *c) const
{ {
TRACE_APPLY (); TRACE_APPLY ();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册