1 #ifndef OT_LAYOUT_GSUB_LIGATURE_HH
2 #define OT_LAYOUT_GSUB_LIGATURE_HH
10 template <typename Types>
14 typename Types::HBGlyphID
15 ligGlyph; /* GlyphID of ligature to substitute */
16 HeadlessArray16Of<typename Types::HBGlyphID>
17 component; /* Array of component GlyphIDs--start
18 * with the second component--ordered
19 * in writing direction */
21 DEFINE_SIZE_ARRAY (Types::size + 2, component);
23 bool sanitize (hb_sanitize_context_t *c) const
25 TRACE_SANITIZE (this);
26 return_trace (ligGlyph.sanitize (c) && component.sanitize (c));
29 bool intersects (const hb_set_t *glyphs) const
30 { return hb_all (component, glyphs); }
32 bool intersects_lig_glyph (const hb_set_t *glyphs) const
33 { return glyphs->has(ligGlyph); }
35 void closure (hb_closure_context_t *c) const
37 if (!intersects (c->glyphs)) return;
38 c->output->add (ligGlyph);
41 void collect_glyphs (hb_collect_glyphs_context_t *c) const
43 c->input->add_array (component.arrayZ, component.get_length ());
44 c->output->add (ligGlyph);
47 bool would_apply (hb_would_apply_context_t *c) const
49 if (c->len != component.lenP1)
52 for (unsigned int i = 1; i < c->len; i++)
53 if (likely (c->glyphs[i] != component[i]))
59 bool apply (hb_ot_apply_context_t *c) const
62 unsigned int count = component.lenP1;
64 if (unlikely (!count)) return_trace (false);
66 /* Special-case to make it in-place and not consider this
67 * as a "ligated" substitution. */
68 if (unlikely (count == 1))
71 if (HB_BUFFER_MESSAGE_MORE && c->buffer->messaging ())
73 c->buffer->sync_so_far ();
74 c->buffer->message (c->font,
75 "replacing glyph at %u (ligature substitution)",
79 c->replace_glyph (ligGlyph);
81 if (HB_BUFFER_MESSAGE_MORE && c->buffer->messaging ())
83 c->buffer->message (c->font,
84 "replaced glyph at %u (ligature substitution)",
91 unsigned int total_component_count = 0;
93 unsigned int match_end = 0;
94 unsigned int match_positions[HB_MAX_CONTEXT_LENGTH];
96 if (likely (!match_input (c, count,
102 &total_component_count)))
104 c->buffer->unsafe_to_concat (c->buffer->idx, match_end);
105 return_trace (false);
109 if (HB_BUFFER_MESSAGE_MORE && c->buffer->messaging ())
111 unsigned delta = c->buffer->sync_so_far ();
113 pos = c->buffer->idx;
115 char buf[HB_MAX_CONTEXT_LENGTH * 16] = {0};
119 for (unsigned i = 0; i < count; i++)
121 match_positions[i] += delta;
124 snprintf (p, sizeof(buf) - (p - buf), "%u", match_positions[i]);
128 c->buffer->message (c->font,
129 "ligating glyphs at %s",
138 total_component_count);
140 if (HB_BUFFER_MESSAGE_MORE && c->buffer->messaging ())
142 c->buffer->sync_so_far ();
143 c->buffer->message (c->font,
144 "ligated glyph at %u",
151 template <typename Iterator,
152 hb_requires (hb_is_source_of (Iterator, hb_codepoint_t))>
153 bool serialize (hb_serialize_context_t *c,
154 hb_codepoint_t ligature,
155 Iterator components /* Starting from second */)
157 TRACE_SERIALIZE (this);
158 if (unlikely (!c->extend_min (this))) return_trace (false);
160 if (unlikely (!component.serialize (c, components))) return_trace (false);
164 bool subset (hb_subset_context_t *c, unsigned coverage_idx) const
167 const hb_set_t &glyphset = *c->plan->glyphset_gsub ();
168 const hb_map_t &glyph_map = *c->plan->glyph_map;
170 if (!intersects (&glyphset) || !glyphset.has (ligGlyph)) return_trace (false);
171 // Ensure Coverage table is always packed after this.
172 c->serializer->add_virtual_link (coverage_idx);
175 + hb_iter (component)
179 auto *out = c->serializer->start_embed (*this);
180 return_trace (out->serialize (c->serializer,
190 #endif /* OT_LAYOUT_GSUB_LIGATURE_HH */