/src/harfbuzz/src/OT/Layout/GSUB/AlternateSet.hh
Line | Count | Source (jump to first uncovered line) |
1 | | #ifndef OT_LAYOUT_GSUB_ALTERNATESET_HH |
2 | | #define OT_LAYOUT_GSUB_ALTERNATESET_HH |
3 | | |
4 | | #include "Common.hh" |
5 | | |
6 | | namespace OT { |
7 | | namespace Layout { |
8 | | namespace GSUB_impl { |
9 | | |
10 | | template <typename Types> |
11 | | struct AlternateSet |
12 | | { |
13 | | protected: |
14 | | Array16Of<typename Types::HBGlyphID> |
15 | | alternates; /* Array of alternate GlyphIDs--in |
16 | | * arbitrary order */ |
17 | | public: |
18 | | DEFINE_SIZE_ARRAY (2, alternates); |
19 | | |
20 | | bool sanitize (hb_sanitize_context_t *c) const |
21 | 23.7k | { |
22 | 23.7k | TRACE_SANITIZE (this); |
23 | 23.7k | return_trace (alternates.sanitize (c)); |
24 | 23.7k | } |
25 | | |
26 | | bool intersects (const hb_set_t *glyphs) const |
27 | | { return hb_any (alternates, glyphs); } |
28 | | |
29 | | void closure (hb_closure_context_t *c) const |
30 | 0 | { c->output->add_array (alternates.arrayZ, alternates.len); } |
31 | | |
32 | | void collect_glyphs (hb_collect_glyphs_context_t *c) const |
33 | 0 | { c->output->add_array (alternates.arrayZ, alternates.len); } |
34 | | |
35 | | bool apply (hb_ot_apply_context_t *c) const |
36 | 0 | { |
37 | 0 | TRACE_APPLY (this); |
38 | 0 | unsigned int count = alternates.len; |
39 | |
|
40 | 0 | if (unlikely (!count)) return_trace (false); |
41 | | |
42 | 0 | hb_mask_t glyph_mask = c->buffer->cur().mask; |
43 | 0 | hb_mask_t lookup_mask = c->lookup_mask; |
44 | | |
45 | | /* Note: This breaks badly if two features enabled this lookup together. */ |
46 | 0 | unsigned int shift = hb_ctz (lookup_mask); |
47 | 0 | unsigned int alt_index = ((lookup_mask & glyph_mask) >> shift); |
48 | | |
49 | | /* If alt_index is MAX_VALUE, randomize feature if it is the rand feature. */ |
50 | 0 | if (alt_index == HB_OT_MAP_MAX_VALUE && c->random) |
51 | 0 | { |
52 | | /* Maybe we can do better than unsafe-to-break all; but since we are |
53 | | * changing random state, it would be hard to track that. Good 'nough. */ |
54 | 0 | c->buffer->unsafe_to_break (0, c->buffer->len); |
55 | 0 | alt_index = c->random_number () % count + 1; |
56 | 0 | } |
57 | |
|
58 | 0 | if (unlikely (alt_index > count || alt_index == 0)) return_trace (false); |
59 | | |
60 | 0 | if (HB_BUFFER_MESSAGE_MORE && c->buffer->messaging ()) |
61 | 0 | { |
62 | 0 | c->buffer->sync_so_far (); |
63 | 0 | c->buffer->message (c->font, |
64 | 0 | "replacing glyph at %u (alternate substitution)", |
65 | 0 | c->buffer->idx); |
66 | 0 | } |
67 | |
|
68 | 0 | c->replace_glyph (alternates[alt_index - 1]); |
69 | |
|
70 | 0 | if (HB_BUFFER_MESSAGE_MORE && c->buffer->messaging ()) |
71 | 0 | { |
72 | 0 | c->buffer->message (c->font, |
73 | 0 | "replaced glyph at %u (alternate substitution)", |
74 | 0 | c->buffer->idx - 1u); |
75 | 0 | } |
76 | |
|
77 | 0 | return_trace (true); |
78 | 0 | } |
79 | | |
80 | | unsigned |
81 | | get_alternates (unsigned start_offset, |
82 | | unsigned *alternate_count /* IN/OUT. May be NULL. */, |
83 | | hb_codepoint_t *alternate_glyphs /* OUT. May be NULL. */) const |
84 | 0 | { |
85 | 0 | if (alternates.len && alternate_count) |
86 | 0 | { |
87 | 0 | + alternates.as_array ().sub_array (start_offset, alternate_count) |
88 | 0 | | hb_sink (hb_array (alternate_glyphs, *alternate_count)) |
89 | 0 | ; |
90 | 0 | } |
91 | 0 | return alternates.len; |
92 | 0 | } |
93 | | |
94 | | template <typename Iterator, |
95 | | hb_requires (hb_is_source_of (Iterator, hb_codepoint_t))> |
96 | | bool serialize (hb_serialize_context_t *c, |
97 | | Iterator alts) |
98 | 0 | { |
99 | 0 | TRACE_SERIALIZE (this); |
100 | 0 | return_trace (alternates.serialize (c, alts)); |
101 | 0 | } Unexecuted instantiation: bool OT::Layout::GSUB_impl::AlternateSet<OT::Layout::SmallTypes>::serialize<hb_array_t<OT::HBGlyphID16 const>, (void*)0>(hb_serialize_context_t*, hb_array_t<OT::HBGlyphID16 const>) Unexecuted instantiation: hb-ot-face.cc:bool OT::Layout::GSUB_impl::AlternateSet<OT::Layout::SmallTypes>::serialize<hb_map_iter_t<hb_filter_iter_t<hb_array_t<OT::HBGlyphID16 const>, hb_set_t const&, $_11 const&, (void*)0>, hb_map_t const&, (hb_function_sortedness_t)0, (void*)0>, (void*)0>(hb_serialize_context_t*, hb_map_iter_t<hb_filter_iter_t<hb_array_t<OT::HBGlyphID16 const>, hb_set_t const&, $_11 const&, (void*)0>, hb_map_t const&, (hb_function_sortedness_t)0, (void*)0>) Unexecuted instantiation: hb-ot-layout.cc:bool OT::Layout::GSUB_impl::AlternateSet<OT::Layout::SmallTypes>::serialize<hb_map_iter_t<hb_filter_iter_t<hb_array_t<OT::HBGlyphID16 const>, hb_set_t const&, $_11 const&, (void*)0>, hb_map_t const&, (hb_function_sortedness_t)0, (void*)0>, (void*)0>(hb_serialize_context_t*, hb_map_iter_t<hb_filter_iter_t<hb_array_t<OT::HBGlyphID16 const>, hb_set_t const&, $_11 const&, (void*)0>, hb_map_t const&, (hb_function_sortedness_t)0, (void*)0>) Unexecuted instantiation: hb-ot-shaper-arabic.cc:bool OT::Layout::GSUB_impl::AlternateSet<OT::Layout::SmallTypes>::serialize<hb_map_iter_t<hb_filter_iter_t<hb_array_t<OT::HBGlyphID16 const>, hb_set_t const&, $_11 const&, (void*)0>, hb_map_t const&, (hb_function_sortedness_t)0, (void*)0>, (void*)0>(hb_serialize_context_t*, hb_map_iter_t<hb_filter_iter_t<hb_array_t<OT::HBGlyphID16 const>, hb_set_t const&, $_11 const&, (void*)0>, hb_map_t const&, (hb_function_sortedness_t)0, (void*)0>) |
102 | | |
103 | | bool subset (hb_subset_context_t *c) const |
104 | 0 | { |
105 | 0 | TRACE_SUBSET (this); |
106 | 0 | const hb_set_t &glyphset = *c->plan->glyphset_gsub (); |
107 | 0 | const hb_map_t &glyph_map = *c->plan->glyph_map; |
108 | 0 |
|
109 | 0 | auto it = |
110 | 0 | + hb_iter (alternates) |
111 | 0 | | hb_filter (glyphset) |
112 | 0 | | hb_map (glyph_map) |
113 | 0 | ; |
114 | 0 |
|
115 | 0 | auto *out = c->serializer->start_embed (*this); |
116 | 0 | return_trace (out->serialize (c->serializer, it) && |
117 | 0 | out->alternates); |
118 | 0 | } |
119 | | }; |
120 | | |
121 | | } |
122 | | } |
123 | | } |
124 | | |
125 | | |
126 | | #endif /* OT_LAYOUT_GSUB_ALTERNATESET_HH */ |