1 #ifndef OT_LAYOUT_GSUB_ALTERNATESUBSTFORMAT1_HH
2 #define OT_LAYOUT_GSUB_ALTERNATESUBSTFORMAT1_HH
4 #include "AlternateSet.hh"
11 template <typename Types>
12 struct AlternateSubstFormat1_2
15 HBUINT16 format; /* Format identifier--format = 1 */
16 typename Types::template OffsetTo<Coverage>
17 coverage; /* Offset to Coverage table--from
18 * beginning of Substitution table */
19 Array16Of<typename Types::template OffsetTo<AlternateSet<Types>>>
20 alternateSet; /* Array of AlternateSet tables
21 * ordered by Coverage Index */
23 DEFINE_SIZE_ARRAY (2 + 2 * Types::size, alternateSet);
25 bool sanitize (hb_sanitize_context_t *c) const
27 TRACE_SANITIZE (this);
28 return_trace (coverage.sanitize (c, this) && alternateSet.sanitize (c, this));
31 bool intersects (const hb_set_t *glyphs) const
32 { return (this+coverage).intersects (glyphs); }
34 bool may_have_non_1to1 () const
37 void closure (hb_closure_context_t *c) const
39 + hb_zip (this+coverage, alternateSet)
40 | hb_filter (c->parent_active_glyphs (), hb_first)
42 | hb_map (hb_add (this))
43 | hb_apply ([c] (const AlternateSet<Types> &_) { _.closure (c); })
47 void closure_lookups (hb_closure_lookups_context_t *c) const {}
49 void collect_glyphs (hb_collect_glyphs_context_t *c) const
51 if (unlikely (!(this+coverage).collect_coverage (c->input))) return;
52 + hb_zip (this+coverage, alternateSet)
54 | hb_map (hb_add (this))
55 | hb_apply ([c] (const AlternateSet<Types> &_) { _.collect_glyphs (c); })
59 const Coverage &get_coverage () const { return this+coverage; }
61 bool would_apply (hb_would_apply_context_t *c) const
62 { return c->len == 1 && (this+coverage).get_coverage (c->glyphs[0]) != NOT_COVERED; }
65 get_glyph_alternates (hb_codepoint_t gid,
66 unsigned start_offset,
67 unsigned *alternate_count /* IN/OUT. May be NULL. */,
68 hb_codepoint_t *alternate_glyphs /* OUT. May be NULL. */) const
69 { return (this+alternateSet[(this+coverage).get_coverage (gid)])
70 .get_alternates (start_offset, alternate_count, alternate_glyphs); }
72 bool apply (hb_ot_apply_context_t *c) const
76 unsigned int index = (this+coverage).get_coverage (c->buffer->cur().codepoint);
77 if (likely (index == NOT_COVERED)) return_trace (false);
79 return_trace ((this+alternateSet[index]).apply (c));
82 bool serialize (hb_serialize_context_t *c,
83 hb_sorted_array_t<const HBGlyphID16> glyphs,
84 hb_array_t<const unsigned int> alternate_len_list,
85 hb_array_t<const HBGlyphID16> alternate_glyphs_list)
87 TRACE_SERIALIZE (this);
88 if (unlikely (!c->extend_min (this))) return_trace (false);
89 if (unlikely (!alternateSet.serialize (c, glyphs.length))) return_trace (false);
90 for (unsigned int i = 0; i < glyphs.length; i++)
92 unsigned int alternate_len = alternate_len_list[i];
93 if (unlikely (!alternateSet[i]
94 .serialize_serialize (c, alternate_glyphs_list.sub_array (0, alternate_len))))
96 alternate_glyphs_list += alternate_len;
98 return_trace (coverage.serialize_serialize (c, glyphs));
101 bool subset (hb_subset_context_t *c) const
104 const hb_set_t &glyphset = *c->plan->glyphset_gsub ();
105 const hb_map_t &glyph_map = *c->plan->glyph_map;
107 auto *out = c->serializer->start_embed (*this);
108 if (unlikely (!c->serializer->extend_min (out))) return_trace (false);
109 out->format = format;
111 hb_sorted_vector_t<hb_codepoint_t> new_coverage;
112 + hb_zip (this+coverage, alternateSet)
113 | hb_filter (glyphset, hb_first)
114 | hb_filter (subset_offset_array (c, out->alternateSet, this), hb_second)
117 | hb_sink (new_coverage)
119 out->coverage.serialize_serialize (c->serializer, new_coverage.iter ());
120 return_trace (bool (new_coverage));
128 #endif /* OT_LAYOUT_GSUB_ALTERNATESUBSTFORMAT1_HH */