/src/harfbuzz/src/OT/Layout/GPOS/PairSet.hh
Line | Count | Source (jump to first uncovered line) |
1 | | #ifndef OT_LAYOUT_GPOS_PAIRSET_HH |
2 | | #define OT_LAYOUT_GPOS_PAIRSET_HH |
3 | | |
4 | | #include "PairValueRecord.hh" |
5 | | |
6 | | namespace OT { |
7 | | namespace Layout { |
8 | | namespace GPOS_impl { |
9 | | |
10 | | |
11 | | template <typename Types> |
12 | | struct PairSet : ValueBase |
13 | | { |
14 | | template <typename Types2> |
15 | | friend struct PairPosFormat1_3; |
16 | | |
17 | | using PairValueRecord = GPOS_impl::PairValueRecord<Types>; |
18 | | |
19 | | protected: |
20 | | HBUINT16 len; /* Number of PairValueRecords */ |
21 | | PairValueRecord firstPairValueRecord; |
22 | | /* Array of PairValueRecords--ordered |
23 | | * by GlyphID of the second glyph */ |
24 | | public: |
25 | | DEFINE_SIZE_MIN (2); |
26 | | |
27 | | static unsigned get_size (unsigned len1, unsigned len2) |
28 | 0 | { |
29 | 0 | return Types::HBGlyphID::static_size + Value::static_size * (len1 + len2); |
30 | 0 | } |
31 | | static unsigned get_size (const ValueFormat valueFormats[2]) |
32 | 0 | { |
33 | 0 | unsigned len1 = valueFormats[0].get_len (); |
34 | 0 | unsigned len2 = valueFormats[1].get_len (); |
35 | 0 | return get_size (len1, len2); |
36 | 0 | } |
37 | | |
38 | | struct sanitize_closure_t |
39 | | { |
40 | | const ValueFormat *valueFormats; |
41 | | unsigned int len1; /* valueFormats[0].get_len() */ |
42 | | unsigned int stride; /* bytes */ |
43 | | }; |
44 | | |
45 | | bool sanitize (hb_sanitize_context_t *c, const sanitize_closure_t *closure) const |
46 | 0 | { |
47 | 0 | TRACE_SANITIZE (this); |
48 | 0 | if (!(c->check_struct (this) && |
49 | 0 | hb_barrier () && |
50 | 0 | c->check_range (&firstPairValueRecord, |
51 | 0 | len, |
52 | 0 | closure->stride))) return_trace (false); |
53 | 0 | hb_barrier (); |
54 | |
|
55 | 0 | unsigned int count = len; |
56 | 0 | const PairValueRecord *record = &firstPairValueRecord; |
57 | 0 | return_trace (c->lazy_some_gpos || |
58 | 0 | (closure->valueFormats[0].sanitize_values_stride_unsafe (c, this, &record->values[0], count, closure->stride) && |
59 | 0 | closure->valueFormats[1].sanitize_values_stride_unsafe (c, this, &record->values[closure->len1], count, closure->stride))); |
60 | 0 | } |
61 | | |
62 | | bool intersects (const hb_set_t *glyphs, |
63 | | const ValueFormat *valueFormats) const |
64 | 0 | { |
65 | 0 | unsigned record_size = get_size (valueFormats); |
66 | 0 |
|
67 | 0 | const PairValueRecord *record = &firstPairValueRecord; |
68 | 0 | unsigned int count = len; |
69 | 0 | for (unsigned int i = 0; i < count; i++) |
70 | 0 | { |
71 | 0 | if (glyphs->has (record->secondGlyph)) |
72 | 0 | return true; |
73 | 0 | record = &StructAtOffset<const PairValueRecord> (record, record_size); |
74 | 0 | } |
75 | 0 | return false; |
76 | 0 | } |
77 | | |
78 | | void collect_glyphs (hb_collect_glyphs_context_t *c, |
79 | | const ValueFormat *valueFormats) const |
80 | 0 | { |
81 | 0 | unsigned record_size = get_size (valueFormats); |
82 | |
|
83 | 0 | const PairValueRecord *record = &firstPairValueRecord; |
84 | 0 | c->input->add_array (&record->secondGlyph, len, record_size); |
85 | 0 | } |
86 | | |
87 | | void collect_variation_indices (hb_collect_variation_indices_context_t *c, |
88 | | const ValueFormat *valueFormats) const |
89 | 0 | { |
90 | 0 | unsigned record_size = get_size (valueFormats); |
91 | 0 |
|
92 | 0 | const PairValueRecord *record = &firstPairValueRecord; |
93 | 0 | unsigned count = len; |
94 | 0 | for (unsigned i = 0; i < count; i++) |
95 | 0 | { |
96 | 0 | if (c->glyph_set->has (record->secondGlyph)) |
97 | 0 | { record->collect_variation_indices (c, valueFormats, this); } |
98 | 0 |
|
99 | 0 | record = &StructAtOffset<const PairValueRecord> (record, record_size); |
100 | 0 | } |
101 | 0 | } |
102 | | |
103 | | bool apply (hb_ot_apply_context_t *c, |
104 | | const ValueFormat *valueFormats, |
105 | | unsigned int pos) const |
106 | 0 | { |
107 | 0 | TRACE_APPLY (this); |
108 | 0 | hb_buffer_t *buffer = c->buffer; |
109 | 0 | unsigned int len1 = valueFormats[0].get_len (); |
110 | 0 | unsigned int len2 = valueFormats[1].get_len (); |
111 | 0 | unsigned record_size = get_size (len1, len2); |
112 | |
|
113 | 0 | const PairValueRecord *record = hb_bsearch (buffer->info[pos].codepoint, |
114 | 0 | &firstPairValueRecord, |
115 | 0 | len, |
116 | 0 | record_size); |
117 | 0 | if (record) |
118 | 0 | { |
119 | 0 | if (HB_BUFFER_MESSAGE_MORE && c->buffer->messaging ()) |
120 | 0 | { |
121 | 0 | c->buffer->message (c->font, |
122 | 0 | "try kerning glyphs at %u,%u", |
123 | 0 | c->buffer->idx, pos); |
124 | 0 | } |
125 | |
|
126 | 0 | bool applied_first = len1 && valueFormats[0].apply_value (c, this, &record->values[0], buffer->cur_pos()); |
127 | 0 | bool applied_second = len2 && valueFormats[1].apply_value (c, this, &record->values[len1], buffer->pos[pos]); |
128 | |
|
129 | 0 | if (applied_first || applied_second) |
130 | 0 | if (HB_BUFFER_MESSAGE_MORE && c->buffer->messaging ()) |
131 | 0 | { |
132 | 0 | c->buffer->message (c->font, |
133 | 0 | "kerned glyphs at %u,%u", |
134 | 0 | c->buffer->idx, pos); |
135 | 0 | } |
136 | |
|
137 | 0 | if (HB_BUFFER_MESSAGE_MORE && c->buffer->messaging ()) |
138 | 0 | { |
139 | 0 | c->buffer->message (c->font, |
140 | 0 | "tried kerning glyphs at %u,%u", |
141 | 0 | c->buffer->idx, pos); |
142 | 0 | } |
143 | |
|
144 | 0 | if (applied_first || applied_second) |
145 | 0 | buffer->unsafe_to_break (buffer->idx, pos + 1); |
146 | |
|
147 | 0 | if (len2) |
148 | 0 | { |
149 | 0 | pos++; |
150 | | // https://github.com/harfbuzz/harfbuzz/issues/3824 |
151 | | // https://github.com/harfbuzz/harfbuzz/issues/3888#issuecomment-1326781116 |
152 | 0 | buffer->unsafe_to_break (buffer->idx, pos + 1); |
153 | 0 | } |
154 | |
|
155 | 0 | buffer->idx = pos; |
156 | 0 | return_trace (true); |
157 | 0 | } |
158 | 0 | buffer->unsafe_to_concat (buffer->idx, pos + 1); |
159 | 0 | return_trace (false); |
160 | 0 | } |
161 | | |
162 | | bool subset (hb_subset_context_t *c, |
163 | | const ValueFormat valueFormats[2], |
164 | | const ValueFormat newFormats[2]) const |
165 | 0 | { |
166 | 0 | TRACE_SUBSET (this); |
167 | 0 | auto snap = c->serializer->snapshot (); |
168 | 0 |
|
169 | 0 | auto *out = c->serializer->start_embed (*this); |
170 | 0 | if (unlikely (!c->serializer->extend_min (out))) return_trace (false); |
171 | 0 | out->len = 0; |
172 | 0 |
|
173 | 0 | const hb_set_t &glyphset = *c->plan->glyphset_gsub (); |
174 | 0 | const hb_map_t &glyph_map = *c->plan->glyph_map; |
175 | 0 |
|
176 | 0 | unsigned len1 = valueFormats[0].get_len (); |
177 | 0 | unsigned len2 = valueFormats[1].get_len (); |
178 | 0 | unsigned record_size = get_size (len1, len2); |
179 | 0 |
|
180 | 0 | typename PairValueRecord::context_t context = |
181 | 0 | { |
182 | 0 | this, |
183 | 0 | valueFormats, |
184 | 0 | newFormats, |
185 | 0 | len1, |
186 | 0 | &glyph_map, |
187 | 0 | &c->plan->layout_variation_idx_delta_map |
188 | 0 | }; |
189 | 0 |
|
190 | 0 | const PairValueRecord *record = &firstPairValueRecord; |
191 | 0 | unsigned count = len, num = 0; |
192 | 0 | for (unsigned i = 0; i < count; i++) |
193 | 0 | { |
194 | 0 | if (glyphset.has (record->secondGlyph) |
195 | 0 | && record->subset (c, &context)) num++; |
196 | 0 | record = &StructAtOffset<const PairValueRecord> (record, record_size); |
197 | 0 | } |
198 | 0 |
|
199 | 0 | out->len = num; |
200 | 0 | if (!num) c->serializer->revert (snap); |
201 | 0 | return_trace (num); |
202 | 0 | } |
203 | | }; |
204 | | |
205 | | |
206 | | } |
207 | | } |
208 | | } |
209 | | |
210 | | #endif // OT_LAYOUT_GPOS_PAIRSET_HH |