[ligature] Add a set-digest on the second component (#5464)

This commit is contained in:
Behdad Esfahbod authored and GitHub committed 2025-08-14 22:26:40 -06:00
1 parent 8268473a02
commit dae2c8bbbd
3 files changed
+32 -7

No files matched your search

+6
View File
@@ -44,6 +44,12 @@ struct Ligature
c->output->add (ligGlyph);
}
template <typename set_t>
void collect_second (set_t &s) const
{
s.add (component[1]); // This adds codepoint 0 if component array is empty.
}
bool would_apply (hb_would_apply_context_t *c) const
{
if (c->len != component.lenP1)
+16 -6
View File
@@ -62,6 +62,15 @@ struct LigatureSet
;
}
template <typename set_t>
void collect_seconds (set_t &s) const
{
+ hb_iter (ligature)
| hb_map (hb_add (this))
| hb_apply ([&s] (const Ligature<Types> &_) { _.collect_second (s); })
;
}
bool would_apply (hb_would_apply_context_t *c) const
{
return
@@ -72,7 +81,7 @@ struct LigatureSet
;
}
bool apply (hb_ot_apply_context_t *c) const
bool apply (hb_ot_apply_context_t *c, const hb_set_digest_t *seconds = nullptr) const
{
TRACE_APPLY (this);
@@ -91,7 +100,7 @@ struct LigatureSet
return_trace (false);
}
/* This version is optimized for speed by matching the first component
/* This version is optimized for speed by matching the second component
* of the ligature here, instead of calling into the ligation code.
*
* This is replicated in ChainRuleSet and RuleSet. */
@@ -101,11 +110,11 @@ struct LigatureSet
skippy_iter.set_match_func (match_always, nullptr);
skippy_iter.set_glyph_data ((HBUINT16 *) nullptr);
unsigned unsafe_to;
hb_codepoint_t first = (unsigned) -1;
hb_codepoint_t second = (unsigned) -1;
bool matched = skippy_iter.next (&unsafe_to);
if (likely (matched))
{
first = c->buffer->info[skippy_iter.idx].codepoint;
second = c->buffer->info[skippy_iter.idx].codepoint;
unsafe_to = skippy_iter.idx + 1;
if (skippy_iter.may_skip (c->buffer->info[skippy_iter.idx]))
@@ -118,13 +127,14 @@ struct LigatureSet
else
goto slow;
if (seconds && !seconds->may_have (second))
return_trace (false);
bool unsafe_to_concat = false;
for (unsigned int i = 0; i < num_ligs; i++)
{
const auto &lig = this+ligature.arrayZ[i];
if (unlikely (lig.component.lenP1 <= 1) ||
lig.component.arrayZ[0] == first)
lig.component.arrayZ[0] == second)
{
if (lig.apply (c))
{
+10 -1
View File
@@ -81,6 +81,7 @@ struct LigatureSubstFormat1_2
struct external_cache_t
{
hb_ot_layout_mapping_cache_t coverage;
hb_set_digest_t seconds;
};
void *external_cache_create () const
{
@@ -88,6 +89,12 @@ struct LigatureSubstFormat1_2
if (likely (cache))
{
cache->coverage.clear ();
cache->seconds.init ();
+ hb_iter (ligatureSet)
| hb_map (hb_add (this))
| hb_apply ([cache] (const LigatureSet<Types> &_) { _.collect_seconds (cache->seconds); })
;
}
return cache;
}
@@ -99,14 +106,16 @@ struct LigatureSubstFormat1_2
#ifndef HB_NO_OT_LAYOUT_LOOKUP_CACHE
external_cache_t *cache = (external_cache_t *) external_cache;
const hb_set_digest_t *seconds = cache ? &cache->seconds : nullptr;
unsigned int index = (this+coverage).get_coverage (buffer->cur().codepoint, cache ? &cache->coverage : nullptr);
#else
const hb_set_digest_t *seconds = nullptr;
unsigned int index = (this+coverage).get_coverage (buffer->cur().codepoint);
#endif
if (index == NOT_COVERED) return_trace (false);
const auto &lig_set = this+ligatureSet[index];
return_trace (lig_set.apply (c));
return_trace (lig_set.apply (c, seconds));
}
bool serialize (hb_serialize_context_t *c,