/src/harfbuzz/src/hb-ot-layout-gdef-table.hh
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright © 2007,2008,2009 Red Hat, Inc. |
3 | | * Copyright © 2010,2011,2012 Google, Inc. |
4 | | * |
5 | | * This is part of HarfBuzz, a text shaping library. |
6 | | * |
7 | | * Permission is hereby granted, without written agreement and without |
8 | | * license or royalty fees, to use, copy, modify, and distribute this |
9 | | * software and its documentation for any purpose, provided that the |
10 | | * above copyright notice and the following two paragraphs appear in |
11 | | * all copies of this software. |
12 | | * |
13 | | * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR |
14 | | * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES |
15 | | * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN |
16 | | * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH |
17 | | * DAMAGE. |
18 | | * |
19 | | * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, |
20 | | * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND |
21 | | * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS |
22 | | * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO |
23 | | * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
24 | | * |
25 | | * Red Hat Author(s): Behdad Esfahbod |
26 | | * Google Author(s): Behdad Esfahbod |
27 | | */ |
28 | | |
29 | | #ifndef HB_OT_LAYOUT_GDEF_TABLE_HH |
30 | | #define HB_OT_LAYOUT_GDEF_TABLE_HH |
31 | | |
32 | | #include "hb-ot-layout-common.hh" |
33 | | |
34 | | #include "hb-font.hh" |
35 | | |
36 | | |
37 | | namespace OT { |
38 | | |
39 | | |
40 | | /* |
41 | | * Attachment List Table |
42 | | */ |
43 | | |
44 | | /* Array of contour point indices--in increasing numerical order */ |
45 | | struct AttachPoint : Array16Of<HBUINT16> |
46 | | { |
47 | | bool subset (hb_subset_context_t *c) const |
48 | 0 | { |
49 | 0 | TRACE_SUBSET (this); |
50 | 0 | auto *out = c->serializer->start_embed (*this); |
51 | 0 | if (unlikely (!out)) return_trace (false); |
52 | 0 |
|
53 | 0 | return_trace (out->serialize (c->serializer, + iter ())); |
54 | 0 | } |
55 | | }; |
56 | | |
57 | | struct AttachList |
58 | | { |
59 | | unsigned int get_attach_points (hb_codepoint_t glyph_id, |
60 | | unsigned int start_offset, |
61 | | unsigned int *point_count /* IN/OUT */, |
62 | | unsigned int *point_array /* OUT */) const |
63 | 0 | { |
64 | 0 | unsigned int index = (this+coverage).get_coverage (glyph_id); |
65 | 0 | if (index == NOT_COVERED) |
66 | 0 | { |
67 | 0 | if (point_count) |
68 | 0 | *point_count = 0; |
69 | 0 | return 0; |
70 | 0 | } |
71 | | |
72 | 0 | const AttachPoint &points = this+attachPoint[index]; |
73 | |
|
74 | 0 | if (point_count) |
75 | 0 | { |
76 | 0 | + points.sub_array (start_offset, point_count) |
77 | 0 | | hb_sink (hb_array (point_array, *point_count)) |
78 | 0 | ; |
79 | 0 | } |
80 | |
|
81 | 0 | return points.len; |
82 | 0 | } |
83 | | |
84 | | bool subset (hb_subset_context_t *c) const |
85 | 0 | { |
86 | 0 | TRACE_SUBSET (this); |
87 | 0 | const hb_set_t &glyphset = *c->plan->glyphset_gsub (); |
88 | 0 | const hb_map_t &glyph_map = *c->plan->glyph_map; |
89 | 0 |
|
90 | 0 | auto *out = c->serializer->start_embed (*this); |
91 | 0 | if (unlikely (!c->serializer->extend_min (out))) return_trace (false); |
92 | 0 |
|
93 | 0 | hb_sorted_vector_t<hb_codepoint_t> new_coverage; |
94 | 0 | + hb_zip (this+coverage, attachPoint) |
95 | 0 | | hb_filter (glyphset, hb_first) |
96 | 0 | | hb_filter (subset_offset_array (c, out->attachPoint, this), hb_second) |
97 | 0 | | hb_map (hb_first) |
98 | 0 | | hb_map (glyph_map) |
99 | 0 | | hb_sink (new_coverage) |
100 | 0 | ; |
101 | 0 | out->coverage.serialize_serialize (c->serializer, new_coverage.iter ()); |
102 | 0 | return_trace (bool (new_coverage)); |
103 | 0 | } |
104 | | |
105 | | bool sanitize (hb_sanitize_context_t *c) const |
106 | 11.7k | { |
107 | 11.7k | TRACE_SANITIZE (this); |
108 | 11.7k | return_trace (coverage.sanitize (c, this) && attachPoint.sanitize (c, this)); |
109 | 11.7k | } |
110 | | |
111 | | protected: |
112 | | Offset16To<Coverage> |
113 | | coverage; /* Offset to Coverage table -- from |
114 | | * beginning of AttachList table */ |
115 | | Array16OfOffset16To<AttachPoint> |
116 | | attachPoint; /* Array of AttachPoint tables |
117 | | * in Coverage Index order */ |
118 | | public: |
119 | | DEFINE_SIZE_ARRAY (4, attachPoint); |
120 | | }; |
121 | | |
122 | | /* |
123 | | * Ligature Caret Table |
124 | | */ |
125 | | |
126 | | struct CaretValueFormat1 |
127 | | { |
128 | | friend struct CaretValue; |
129 | | bool subset (hb_subset_context_t *c) const |
130 | 0 | { |
131 | 0 | TRACE_SUBSET (this); |
132 | 0 | auto *out = c->serializer->embed (this); |
133 | 0 | if (unlikely (!out)) return_trace (false); |
134 | 0 | return_trace (true); |
135 | 0 | } |
136 | | |
137 | | private: |
138 | | hb_position_t get_caret_value (hb_font_t *font, hb_direction_t direction) const |
139 | 0 | { |
140 | 0 | return HB_DIRECTION_IS_HORIZONTAL (direction) ? font->em_scale_x (coordinate) : font->em_scale_y (coordinate); |
141 | 0 | } |
142 | | |
143 | | bool sanitize (hb_sanitize_context_t *c) const |
144 | 8.87M | { |
145 | 8.87M | TRACE_SANITIZE (this); |
146 | 8.87M | return_trace (c->check_struct (this)); |
147 | 8.87M | } |
148 | | |
149 | | protected: |
150 | | HBUINT16 caretValueFormat; /* Format identifier--format = 1 */ |
151 | | FWORD coordinate; /* X or Y value, in design units */ |
152 | | public: |
153 | | DEFINE_SIZE_STATIC (4); |
154 | | }; |
155 | | |
156 | | struct CaretValueFormat2 |
157 | | { |
158 | | friend struct CaretValue; |
159 | | bool subset (hb_subset_context_t *c) const |
160 | 0 | { |
161 | 0 | TRACE_SUBSET (this); |
162 | 0 | auto *out = c->serializer->embed (this); |
163 | 0 | if (unlikely (!out)) return_trace (false); |
164 | 0 | return_trace (true); |
165 | 0 | } |
166 | | |
167 | | private: |
168 | | hb_position_t get_caret_value (hb_font_t *font, hb_direction_t direction, hb_codepoint_t glyph_id) const |
169 | 0 | { |
170 | 0 | hb_position_t x, y; |
171 | 0 | font->get_glyph_contour_point_for_origin (glyph_id, caretValuePoint, direction, &x, &y); |
172 | 0 | return HB_DIRECTION_IS_HORIZONTAL (direction) ? x : y; |
173 | 0 | } |
174 | | |
175 | | bool sanitize (hb_sanitize_context_t *c) const |
176 | 2.37M | { |
177 | 2.37M | TRACE_SANITIZE (this); |
178 | 2.37M | return_trace (c->check_struct (this)); |
179 | 2.37M | } |
180 | | |
181 | | protected: |
182 | | HBUINT16 caretValueFormat; /* Format identifier--format = 2 */ |
183 | | HBUINT16 caretValuePoint; /* Contour point index on glyph */ |
184 | | public: |
185 | | DEFINE_SIZE_STATIC (4); |
186 | | }; |
187 | | |
188 | | struct CaretValueFormat3 |
189 | | { |
190 | | friend struct CaretValue; |
191 | | |
192 | | hb_position_t get_caret_value (hb_font_t *font, hb_direction_t direction, |
193 | | const VariationStore &var_store) const |
194 | 0 | { |
195 | 0 | return HB_DIRECTION_IS_HORIZONTAL (direction) ? |
196 | 0 | font->em_scale_x (coordinate) + (this+deviceTable).get_x_delta (font, var_store) : |
197 | 0 | font->em_scale_y (coordinate) + (this+deviceTable).get_y_delta (font, var_store); |
198 | 0 | } |
199 | | |
200 | | bool subset (hb_subset_context_t *c) const |
201 | 0 | { |
202 | 0 | TRACE_SUBSET (this); |
203 | 0 | auto *out = c->serializer->embed (this); |
204 | 0 | if (unlikely (!out)) return_trace (false); |
205 | 0 |
|
206 | 0 | return_trace (out->deviceTable.serialize_copy (c->serializer, deviceTable, this, c->serializer->to_bias (out), |
207 | 0 | hb_serialize_context_t::Head, c->plan->layout_variation_idx_map)); |
208 | 0 | } |
209 | | |
210 | | void collect_variation_indices (hb_set_t *layout_variation_indices) const |
211 | 0 | { (this+deviceTable).collect_variation_indices (layout_variation_indices); } |
212 | | |
213 | | bool sanitize (hb_sanitize_context_t *c) const |
214 | 2.03M | { |
215 | 2.03M | TRACE_SANITIZE (this); |
216 | 2.03M | return_trace (c->check_struct (this) && deviceTable.sanitize (c, this)); |
217 | 2.03M | } |
218 | | |
219 | | protected: |
220 | | HBUINT16 caretValueFormat; /* Format identifier--format = 3 */ |
221 | | FWORD coordinate; /* X or Y value, in design units */ |
222 | | Offset16To<Device> |
223 | | deviceTable; /* Offset to Device table for X or Y |
224 | | * value--from beginning of CaretValue |
225 | | * table */ |
226 | | public: |
227 | | DEFINE_SIZE_STATIC (6); |
228 | | }; |
229 | | |
230 | | struct CaretValue |
231 | | { |
232 | | hb_position_t get_caret_value (hb_font_t *font, |
233 | | hb_direction_t direction, |
234 | | hb_codepoint_t glyph_id, |
235 | | const VariationStore &var_store) const |
236 | 0 | { |
237 | 0 | switch (u.format) { |
238 | 0 | case 1: return u.format1.get_caret_value (font, direction); |
239 | 0 | case 2: return u.format2.get_caret_value (font, direction, glyph_id); |
240 | 0 | case 3: return u.format3.get_caret_value (font, direction, var_store); |
241 | 0 | default:return 0; |
242 | 0 | } |
243 | 0 | } |
244 | | |
245 | | template <typename context_t, typename ...Ts> |
246 | | typename context_t::return_t dispatch (context_t *c, Ts&&... ds) const |
247 | 0 | { |
248 | 0 | TRACE_DISPATCH (this, u.format); |
249 | 0 | if (unlikely (!c->may_dispatch (this, &u.format))) return_trace (c->no_dispatch_return_value ()); |
250 | 0 | switch (u.format) { |
251 | 0 | case 1: return_trace (c->dispatch (u.format1, std::forward<Ts> (ds)...)); |
252 | 0 | case 2: return_trace (c->dispatch (u.format2, std::forward<Ts> (ds)...)); |
253 | 0 | case 3: return_trace (c->dispatch (u.format3, std::forward<Ts> (ds)...)); |
254 | 0 | default:return_trace (c->default_return_value ()); |
255 | 0 | } |
256 | 0 | } |
257 | | |
258 | | void collect_variation_indices (hb_set_t *layout_variation_indices) const |
259 | 0 | { |
260 | 0 | switch (u.format) { |
261 | 0 | case 1: |
262 | 0 | case 2: |
263 | 0 | return; |
264 | 0 | case 3: |
265 | 0 | u.format3.collect_variation_indices (layout_variation_indices); |
266 | 0 | return; |
267 | 0 | default: return; |
268 | 0 | } |
269 | 0 | } |
270 | | |
271 | | bool sanitize (hb_sanitize_context_t *c) const |
272 | 370M | { |
273 | 370M | TRACE_SANITIZE (this); |
274 | 370M | if (!u.format.sanitize (c)) return_trace (false); |
275 | 370M | switch (u.format) { |
276 | 8.87M | case 1: return_trace (u.format1.sanitize (c)); |
277 | 2.37M | case 2: return_trace (u.format2.sanitize (c)); |
278 | 2.03M | case 3: return_trace (u.format3.sanitize (c)); |
279 | 357M | default:return_trace (true); |
280 | 370M | } |
281 | 370M | } |
282 | | |
283 | | protected: |
284 | | union { |
285 | | HBUINT16 format; /* Format identifier */ |
286 | | CaretValueFormat1 format1; |
287 | | CaretValueFormat2 format2; |
288 | | CaretValueFormat3 format3; |
289 | | } u; |
290 | | public: |
291 | | DEFINE_SIZE_UNION (2, format); |
292 | | }; |
293 | | |
294 | | struct LigGlyph |
295 | | { |
296 | | unsigned get_lig_carets (hb_font_t *font, |
297 | | hb_direction_t direction, |
298 | | hb_codepoint_t glyph_id, |
299 | | const VariationStore &var_store, |
300 | | unsigned start_offset, |
301 | | unsigned *caret_count /* IN/OUT */, |
302 | | hb_position_t *caret_array /* OUT */) const |
303 | 155 | { |
304 | 155 | if (caret_count) |
305 | 0 | { |
306 | 0 | + carets.sub_array (start_offset, caret_count) |
307 | 0 | | hb_map (hb_add (this)) |
308 | 0 | | hb_map ([&] (const CaretValue &value) { return value.get_caret_value (font, direction, glyph_id, var_store); }) |
309 | 0 | | hb_sink (hb_array (caret_array, *caret_count)) |
310 | 0 | ; |
311 | 0 | } |
312 | | |
313 | 155 | return carets.len; |
314 | 155 | } |
315 | | |
316 | | bool subset (hb_subset_context_t *c) const |
317 | 0 | { |
318 | 0 | TRACE_SUBSET (this); |
319 | 0 | auto *out = c->serializer->start_embed (*this); |
320 | 0 | if (unlikely (!c->serializer->extend_min (out))) return_trace (false); |
321 | 0 |
|
322 | 0 | + hb_iter (carets) |
323 | 0 | | hb_apply (subset_offset_array (c, out->carets, this)) |
324 | 0 | ; |
325 | 0 |
|
326 | 0 | return_trace (bool (out->carets)); |
327 | 0 | } |
328 | | |
329 | | void collect_variation_indices (hb_collect_variation_indices_context_t *c) const |
330 | 0 | { |
331 | 0 | for (const Offset16To<CaretValue>& offset : carets.iter ()) |
332 | 0 | (this+offset).collect_variation_indices (c->layout_variation_indices); |
333 | 0 | } |
334 | | |
335 | | bool sanitize (hb_sanitize_context_t *c) const |
336 | 114k | { |
337 | 114k | TRACE_SANITIZE (this); |
338 | 114k | return_trace (carets.sanitize (c, this)); |
339 | 114k | } |
340 | | |
341 | | protected: |
342 | | Array16OfOffset16To<CaretValue> |
343 | | carets; /* Offset array of CaretValue tables |
344 | | * --from beginning of LigGlyph table |
345 | | * --in increasing coordinate order */ |
346 | | public: |
347 | | DEFINE_SIZE_ARRAY (2, carets); |
348 | | }; |
349 | | |
350 | | struct LigCaretList |
351 | | { |
352 | | unsigned int get_lig_carets (hb_font_t *font, |
353 | | hb_direction_t direction, |
354 | | hb_codepoint_t glyph_id, |
355 | | const VariationStore &var_store, |
356 | | unsigned int start_offset, |
357 | | unsigned int *caret_count /* IN/OUT */, |
358 | | hb_position_t *caret_array /* OUT */) const |
359 | 153k | { |
360 | 153k | unsigned int index = (this+coverage).get_coverage (glyph_id); |
361 | 153k | if (index == NOT_COVERED) |
362 | 153k | { |
363 | 153k | if (caret_count) |
364 | 0 | *caret_count = 0; |
365 | 153k | return 0; |
366 | 153k | } |
367 | 155 | const LigGlyph &lig_glyph = this+ligGlyph[index]; |
368 | 155 | return lig_glyph.get_lig_carets (font, direction, glyph_id, var_store, start_offset, caret_count, caret_array); |
369 | 153k | } |
370 | | |
371 | | bool subset (hb_subset_context_t *c) const |
372 | 0 | { |
373 | 0 | TRACE_SUBSET (this); |
374 | 0 | const hb_set_t &glyphset = *c->plan->glyphset_gsub (); |
375 | 0 | const hb_map_t &glyph_map = *c->plan->glyph_map; |
376 | 0 |
|
377 | 0 | auto *out = c->serializer->start_embed (*this); |
378 | 0 | if (unlikely (!c->serializer->extend_min (out))) return_trace (false); |
379 | 0 |
|
380 | 0 | hb_sorted_vector_t<hb_codepoint_t> new_coverage; |
381 | 0 | + hb_zip (this+coverage, ligGlyph) |
382 | 0 | | hb_filter (glyphset, hb_first) |
383 | 0 | | hb_filter (subset_offset_array (c, out->ligGlyph, this), hb_second) |
384 | 0 | | hb_map (hb_first) |
385 | 0 | | hb_map (glyph_map) |
386 | 0 | | hb_sink (new_coverage) |
387 | 0 | ; |
388 | 0 | out->coverage.serialize_serialize (c->serializer, new_coverage.iter ()); |
389 | 0 | return_trace (bool (new_coverage)); |
390 | 0 | } |
391 | | |
392 | | void collect_variation_indices (hb_collect_variation_indices_context_t *c) const |
393 | 0 | { |
394 | 0 | + hb_zip (this+coverage, ligGlyph) |
395 | 0 | | hb_filter (c->glyph_set, hb_first) |
396 | 0 | | hb_map (hb_second) |
397 | 0 | | hb_map (hb_add (this)) |
398 | 0 | | hb_apply ([c] (const LigGlyph& _) { _.collect_variation_indices (c); }) |
399 | 0 | ; |
400 | 0 | } |
401 | | |
402 | | bool sanitize (hb_sanitize_context_t *c) const |
403 | 15.0k | { |
404 | 15.0k | TRACE_SANITIZE (this); |
405 | 15.0k | return_trace (coverage.sanitize (c, this) && ligGlyph.sanitize (c, this)); |
406 | 15.0k | } |
407 | | |
408 | | protected: |
409 | | Offset16To<Coverage> |
410 | | coverage; /* Offset to Coverage table--from |
411 | | * beginning of LigCaretList table */ |
412 | | Array16OfOffset16To<LigGlyph> |
413 | | ligGlyph; /* Array of LigGlyph tables |
414 | | * in Coverage Index order */ |
415 | | public: |
416 | | DEFINE_SIZE_ARRAY (4, ligGlyph); |
417 | | }; |
418 | | |
419 | | |
420 | | struct MarkGlyphSetsFormat1 |
421 | | { |
422 | | bool covers (unsigned int set_index, hb_codepoint_t glyph_id) const |
423 | 3.77k | { return (this+coverage[set_index]).get_coverage (glyph_id) != NOT_COVERED; } |
424 | | |
425 | | bool subset (hb_subset_context_t *c) const |
426 | 0 | { |
427 | 0 | TRACE_SUBSET (this); |
428 | 0 | auto *out = c->serializer->start_embed (*this); |
429 | 0 | if (unlikely (!c->serializer->extend_min (out))) return_trace (false); |
430 | 0 | out->format = format; |
431 | 0 |
|
432 | 0 | bool ret = true; |
433 | 0 | for (const Offset32To<Coverage>& offset : coverage.iter ()) |
434 | 0 | { |
435 | 0 | auto *o = out->coverage.serialize_append (c->serializer); |
436 | 0 | if (unlikely (!o)) |
437 | 0 | { |
438 | 0 | ret = false; |
439 | 0 | break; |
440 | 0 | } |
441 | 0 |
|
442 | 0 | //not using o->serialize_subset (c, offset, this, out) here because |
443 | 0 | //OTS doesn't allow null offset. |
444 | 0 | //See issue: https://github.com/khaledhosny/ots/issues/172 |
445 | 0 | c->serializer->push (); |
446 | 0 | c->dispatch (this+offset); |
447 | 0 | c->serializer->add_link (*o, c->serializer->pop_pack ()); |
448 | 0 | } |
449 | 0 |
|
450 | 0 | return_trace (ret && out->coverage.len); |
451 | 0 | } |
452 | | |
453 | | bool sanitize (hb_sanitize_context_t *c) const |
454 | 10.0k | { |
455 | 10.0k | TRACE_SANITIZE (this); |
456 | 10.0k | return_trace (coverage.sanitize (c, this)); |
457 | 10.0k | } |
458 | | |
459 | | protected: |
460 | | HBUINT16 format; /* Format identifier--format = 1 */ |
461 | | Array16Of<Offset32To<Coverage>> |
462 | | coverage; /* Array of long offsets to mark set |
463 | | * coverage tables */ |
464 | | public: |
465 | | DEFINE_SIZE_ARRAY (4, coverage); |
466 | | }; |
467 | | |
468 | | struct MarkGlyphSets |
469 | | { |
470 | | bool covers (unsigned int set_index, hb_codepoint_t glyph_id) const |
471 | 103k | { |
472 | 103k | switch (u.format) { |
473 | 3.77k | case 1: return u.format1.covers (set_index, glyph_id); |
474 | 99.2k | default:return false; |
475 | 103k | } |
476 | 103k | } |
477 | | |
478 | | bool subset (hb_subset_context_t *c) const |
479 | 0 | { |
480 | 0 | TRACE_SUBSET (this); |
481 | 0 | switch (u.format) { |
482 | 0 | case 1: return_trace (u.format1.subset (c)); |
483 | 0 | default:return_trace (false); |
484 | 0 | } |
485 | 0 | } |
486 | | |
487 | | bool sanitize (hb_sanitize_context_t *c) const |
488 | 14.1k | { |
489 | 14.1k | TRACE_SANITIZE (this); |
490 | 14.1k | if (!u.format.sanitize (c)) return_trace (false); |
491 | 13.2k | switch (u.format) { |
492 | 10.0k | case 1: return_trace (u.format1.sanitize (c)); |
493 | 3.17k | default:return_trace (true); |
494 | 13.2k | } |
495 | 13.2k | } |
496 | | |
497 | | protected: |
498 | | union { |
499 | | HBUINT16 format; /* Format identifier */ |
500 | | MarkGlyphSetsFormat1 format1; |
501 | | } u; |
502 | | public: |
503 | | DEFINE_SIZE_UNION (2, format); |
504 | | }; |
505 | | |
506 | | |
507 | | /* |
508 | | * GDEF -- Glyph Definition |
509 | | * https://docs.microsoft.com/en-us/typography/opentype/spec/gdef |
510 | | */ |
511 | | |
512 | | |
513 | | template <typename Types> |
514 | | struct GDEFVersion1_2 |
515 | | { |
516 | | friend struct GDEF; |
517 | | |
518 | | protected: |
519 | | FixedVersion<>version; /* Version of the GDEF table--currently |
520 | | * 0x00010003u */ |
521 | | typename Types::template OffsetTo<ClassDef> |
522 | | glyphClassDef; /* Offset to class definition table |
523 | | * for glyph type--from beginning of |
524 | | * GDEF header (may be Null) */ |
525 | | typename Types::template OffsetTo<AttachList> |
526 | | attachList; /* Offset to list of glyphs with |
527 | | * attachment points--from beginning |
528 | | * of GDEF header (may be Null) */ |
529 | | typename Types::template OffsetTo<LigCaretList> |
530 | | ligCaretList; /* Offset to list of positioning points |
531 | | * for ligature carets--from beginning |
532 | | * of GDEF header (may be Null) */ |
533 | | typename Types::template OffsetTo<ClassDef> |
534 | | markAttachClassDef; /* Offset to class definition table for |
535 | | * mark attachment type--from beginning |
536 | | * of GDEF header (may be Null) */ |
537 | | typename Types::template OffsetTo<MarkGlyphSets> |
538 | | markGlyphSetsDef; /* Offset to the table of mark set |
539 | | * definitions--from beginning of GDEF |
540 | | * header (may be NULL). Introduced |
541 | | * in version 0x00010002. */ |
542 | | Offset32To<VariationStore> |
543 | | varStore; /* Offset to the table of Item Variation |
544 | | * Store--from beginning of GDEF |
545 | | * header (may be NULL). Introduced |
546 | | * in version 0x00010003. */ |
547 | | public: |
548 | | DEFINE_SIZE_MIN (4 + 4 * Types::size); |
549 | | |
550 | | unsigned int get_size () const |
551 | 0 | { |
552 | 0 | return min_size + |
553 | 0 | (version.to_int () >= 0x00010002u ? markGlyphSetsDef.static_size : 0) + |
554 | 0 | (version.to_int () >= 0x00010003u ? varStore.static_size : 0); |
555 | 0 | } Unexecuted instantiation: OT::GDEFVersion1_2<OT::Layout::SmallTypes>::get_size() const Unexecuted instantiation: OT::GDEFVersion1_2<OT::Layout::MediumTypes>::get_size() const |
556 | | |
557 | | bool sanitize (hb_sanitize_context_t *c) const |
558 | 73.6k | { |
559 | 73.6k | TRACE_SANITIZE (this); |
560 | 73.6k | return_trace (version.sanitize (c) && |
561 | 73.6k | glyphClassDef.sanitize (c, this) && |
562 | 73.6k | attachList.sanitize (c, this) && |
563 | 73.6k | ligCaretList.sanitize (c, this) && |
564 | 73.6k | markAttachClassDef.sanitize (c, this) && |
565 | 73.6k | (version.to_int () < 0x00010002u || markGlyphSetsDef.sanitize (c, this)) && |
566 | 73.6k | (version.to_int () < 0x00010003u || varStore.sanitize (c, this))); |
567 | 73.6k | } OT::GDEFVersion1_2<OT::Layout::SmallTypes>::sanitize(hb_sanitize_context_t*) const Line | Count | Source | 558 | 68.3k | { | 559 | 68.3k | TRACE_SANITIZE (this); | 560 | 68.3k | return_trace (version.sanitize (c) && | 561 | 68.3k | glyphClassDef.sanitize (c, this) && | 562 | 68.3k | attachList.sanitize (c, this) && | 563 | 68.3k | ligCaretList.sanitize (c, this) && | 564 | 68.3k | markAttachClassDef.sanitize (c, this) && | 565 | 68.3k | (version.to_int () < 0x00010002u || markGlyphSetsDef.sanitize (c, this)) && | 566 | 68.3k | (version.to_int () < 0x00010003u || varStore.sanitize (c, this))); | 567 | 68.3k | } |
OT::GDEFVersion1_2<OT::Layout::MediumTypes>::sanitize(hb_sanitize_context_t*) const Line | Count | Source | 558 | 5.29k | { | 559 | 5.29k | TRACE_SANITIZE (this); | 560 | 5.29k | return_trace (version.sanitize (c) && | 561 | 5.29k | glyphClassDef.sanitize (c, this) && | 562 | 5.29k | attachList.sanitize (c, this) && | 563 | 5.29k | ligCaretList.sanitize (c, this) && | 564 | 5.29k | markAttachClassDef.sanitize (c, this) && | 565 | 5.29k | (version.to_int () < 0x00010002u || markGlyphSetsDef.sanitize (c, this)) && | 566 | 5.29k | (version.to_int () < 0x00010003u || varStore.sanitize (c, this))); | 567 | 5.29k | } |
|
568 | | |
569 | | bool subset (hb_subset_context_t *c) const |
570 | 0 | { |
571 | 0 | TRACE_SUBSET (this); |
572 | 0 | auto *out = c->serializer->embed (*this); |
573 | 0 | if (unlikely (!out)) return_trace (false); |
574 | 0 |
|
575 | 0 | bool subset_glyphclassdef = out->glyphClassDef.serialize_subset (c, glyphClassDef, this, nullptr, false, true); |
576 | 0 | bool subset_attachlist = out->attachList.serialize_subset (c, attachList, this); |
577 | 0 | bool subset_ligcaretlist = out->ligCaretList.serialize_subset (c, ligCaretList, this); |
578 | 0 | bool subset_markattachclassdef = out->markAttachClassDef.serialize_subset (c, markAttachClassDef, this, nullptr, false, true); |
579 | 0 |
|
580 | 0 | bool subset_markglyphsetsdef = false; |
581 | 0 | if (version.to_int () >= 0x00010002u) |
582 | 0 | { |
583 | 0 | subset_markglyphsetsdef = out->markGlyphSetsDef.serialize_subset (c, markGlyphSetsDef, this); |
584 | 0 | } |
585 | 0 |
|
586 | 0 | bool subset_varstore = false; |
587 | 0 | if (version.to_int () >= 0x00010003u) |
588 | 0 | { |
589 | 0 | subset_varstore = out->varStore.serialize_subset (c, varStore, this); |
590 | 0 | } |
591 | 0 |
|
592 | 0 | if (subset_varstore) |
593 | 0 | { |
594 | 0 | out->version.minor = 3; |
595 | 0 | } else if (subset_markglyphsetsdef) { |
596 | 0 | out->version.minor = 2; |
597 | 0 | } else { |
598 | 0 | out->version.minor = 0; |
599 | 0 | } |
600 | 0 |
|
601 | 0 | return_trace (subset_glyphclassdef || subset_attachlist || |
602 | 0 | subset_ligcaretlist || subset_markattachclassdef || |
603 | 0 | (out->version.to_int () >= 0x00010002u && subset_markglyphsetsdef) || |
604 | 0 | (out->version.to_int () >= 0x00010003u && subset_varstore)); |
605 | 0 | } Unexecuted instantiation: OT::GDEFVersion1_2<OT::Layout::SmallTypes>::subset(hb_subset_context_t*) const Unexecuted instantiation: OT::GDEFVersion1_2<OT::Layout::MediumTypes>::subset(hb_subset_context_t*) const |
606 | | }; |
607 | | |
608 | | struct GDEF |
609 | | { |
610 | | static constexpr hb_tag_t tableTag = HB_OT_TAG_GDEF; |
611 | | |
612 | | enum GlyphClasses { |
613 | | UnclassifiedGlyph = 0, |
614 | | BaseGlyph = 1, |
615 | | LigatureGlyph = 2, |
616 | | MarkGlyph = 3, |
617 | | ComponentGlyph = 4 |
618 | | }; |
619 | | |
620 | | unsigned int get_size () const |
621 | 0 | { |
622 | 0 | switch (u.version.major) { |
623 | 0 | case 1: return u.version1.get_size (); |
624 | 0 | #ifndef HB_NO_BEYOND_64K |
625 | 0 | case 2: return u.version2.get_size (); |
626 | 0 | #endif |
627 | 0 | default: return u.version.static_size; |
628 | 0 | } |
629 | 0 | } |
630 | | |
631 | | bool sanitize (hb_sanitize_context_t *c) const |
632 | 83.4k | { |
633 | 83.4k | TRACE_SANITIZE (this); |
634 | 83.4k | if (unlikely (!u.version.sanitize (c))) return_trace (false); |
635 | 83.4k | switch (u.version.major) { |
636 | 68.3k | case 1: return_trace (u.version1.sanitize (c)); |
637 | 0 | #ifndef HB_NO_BEYOND_64K |
638 | 5.29k | case 2: return_trace (u.version2.sanitize (c)); |
639 | 0 | #endif |
640 | 9.72k | default: return_trace (true); |
641 | 83.4k | } |
642 | 83.4k | } |
643 | | |
644 | | bool subset (hb_subset_context_t *c) const |
645 | 0 | { |
646 | 0 | switch (u.version.major) { |
647 | 0 | case 1: return u.version1.subset (c); |
648 | 0 | #ifndef HB_NO_BEYOND_64K |
649 | 0 | case 2: return u.version2.subset (c); |
650 | 0 | #endif |
651 | 0 | default: return false; |
652 | 0 | } |
653 | 0 | } |
654 | | |
655 | | bool has_glyph_classes () const |
656 | 4.30M | { |
657 | 4.30M | switch (u.version.major) { |
658 | 1.90M | case 1: return u.version1.glyphClassDef != 0; |
659 | 0 | #ifndef HB_NO_BEYOND_64K |
660 | 62.8k | case 2: return u.version2.glyphClassDef != 0; |
661 | 0 | #endif |
662 | 2.33M | default: return false; |
663 | 4.30M | } |
664 | 4.30M | } |
665 | | const ClassDef &get_glyph_class_def () const |
666 | 11.0M | { |
667 | 11.0M | switch (u.version.major) { |
668 | 5.91M | case 1: return this+u.version1.glyphClassDef; |
669 | 0 | #ifndef HB_NO_BEYOND_64K |
670 | 114k | case 2: return this+u.version2.glyphClassDef; |
671 | 0 | #endif |
672 | 5.02M | default: return Null(ClassDef); |
673 | 11.0M | } |
674 | 11.0M | } |
675 | | bool has_attach_list () const |
676 | 0 | { |
677 | 0 | switch (u.version.major) { |
678 | 0 | case 1: return u.version1.attachList != 0; |
679 | 0 | #ifndef HB_NO_BEYOND_64K |
680 | 0 | case 2: return u.version2.attachList != 0; |
681 | 0 | #endif |
682 | 0 | default: return false; |
683 | 0 | } |
684 | 0 | } |
685 | | const AttachList &get_attach_list () const |
686 | 0 | { |
687 | 0 | switch (u.version.major) { |
688 | 0 | case 1: return this+u.version1.attachList; |
689 | 0 | #ifndef HB_NO_BEYOND_64K |
690 | 0 | case 2: return this+u.version2.attachList; |
691 | 0 | #endif |
692 | 0 | default: return Null(AttachList); |
693 | 0 | } |
694 | 0 | } |
695 | | bool has_lig_carets () const |
696 | 0 | { |
697 | 0 | switch (u.version.major) { |
698 | 0 | case 1: return u.version1.ligCaretList != 0; |
699 | 0 | #ifndef HB_NO_BEYOND_64K |
700 | 0 | case 2: return u.version2.ligCaretList != 0; |
701 | 0 | #endif |
702 | 0 | default: return false; |
703 | 0 | } |
704 | 0 | } |
705 | | const LigCaretList &get_lig_caret_list () const |
706 | 153k | { |
707 | 153k | switch (u.version.major) { |
708 | 50.7k | case 1: return this+u.version1.ligCaretList; |
709 | 0 | #ifndef HB_NO_BEYOND_64K |
710 | 1.60k | case 2: return this+u.version2.ligCaretList; |
711 | 0 | #endif |
712 | 101k | default: return Null(LigCaretList); |
713 | 153k | } |
714 | 153k | } |
715 | | bool has_mark_attachment_types () const |
716 | 0 | { |
717 | 0 | switch (u.version.major) { |
718 | 0 | case 1: return u.version1.markAttachClassDef != 0; |
719 | 0 | #ifndef HB_NO_BEYOND_64K |
720 | 0 | case 2: return u.version2.markAttachClassDef != 0; |
721 | 0 | #endif |
722 | 0 | default: return false; |
723 | 0 | } |
724 | 0 | } |
725 | | const ClassDef &get_mark_attach_class_def () const |
726 | 668k | { |
727 | 668k | switch (u.version.major) { |
728 | 667k | case 1: return this+u.version1.markAttachClassDef; |
729 | 0 | #ifndef HB_NO_BEYOND_64K |
730 | 54 | case 2: return this+u.version2.markAttachClassDef; |
731 | 0 | #endif |
732 | 0 | default: return Null(ClassDef); |
733 | 668k | } |
734 | 668k | } |
735 | | bool has_mark_glyph_sets () const |
736 | 0 | { |
737 | 0 | switch (u.version.major) { |
738 | 0 | case 1: return u.version.to_int () >= 0x00010002u && u.version1.markGlyphSetsDef != 0; |
739 | 0 | #ifndef HB_NO_BEYOND_64K |
740 | 0 | case 2: return u.version2.markGlyphSetsDef != 0; |
741 | 0 | #endif |
742 | 0 | default: return false; |
743 | 0 | } |
744 | 0 | } |
745 | | const MarkGlyphSets &get_mark_glyph_sets () const |
746 | 103k | { |
747 | 103k | switch (u.version.major) { |
748 | 22.8k | case 1: return u.version.to_int () >= 0x00010002u ? this+u.version1.markGlyphSetsDef : Null(MarkGlyphSets); |
749 | 0 | #ifndef HB_NO_BEYOND_64K |
750 | 457 | case 2: return this+u.version2.markGlyphSetsDef; |
751 | 0 | #endif |
752 | 79.7k | default: return Null(MarkGlyphSets); |
753 | 103k | } |
754 | 103k | } |
755 | | bool has_var_store () const |
756 | 0 | { |
757 | 0 | switch (u.version.major) { |
758 | 0 | case 1: return u.version.to_int () >= 0x00010003u && u.version1.varStore != 0; |
759 | 0 | #ifndef HB_NO_BEYOND_64K |
760 | 0 | case 2: return u.version2.varStore != 0; |
761 | 0 | #endif |
762 | 0 | default: return false; |
763 | 0 | } |
764 | 0 | } |
765 | | const VariationStore &get_var_store () const |
766 | 4.02M | { |
767 | 4.02M | switch (u.version.major) { |
768 | 1.80M | case 1: return u.version.to_int () >= 0x00010003u ? this+u.version1.varStore : Null(VariationStore); |
769 | 0 | #ifndef HB_NO_BEYOND_64K |
770 | 59.9k | case 2: return this+u.version2.varStore; |
771 | 0 | #endif |
772 | 2.15M | default: return Null(VariationStore); |
773 | 4.02M | } |
774 | 4.02M | } |
775 | | |
776 | | |
777 | 0 | bool has_data () const { return u.version.to_int (); } |
778 | | unsigned int get_glyph_class (hb_codepoint_t glyph) const |
779 | 11.0M | { return get_glyph_class_def ().get_class (glyph); } |
780 | | void get_glyphs_in_class (unsigned int klass, hb_set_t *glyphs) const |
781 | 0 | { get_glyph_class_def ().collect_class (glyphs, klass); } |
782 | | |
783 | | unsigned int get_mark_attachment_type (hb_codepoint_t glyph) const |
784 | 668k | { return get_mark_attach_class_def ().get_class (glyph); } |
785 | | |
786 | | unsigned int get_attach_points (hb_codepoint_t glyph_id, |
787 | | unsigned int start_offset, |
788 | | unsigned int *point_count /* IN/OUT */, |
789 | | unsigned int *point_array /* OUT */) const |
790 | 0 | { return get_attach_list ().get_attach_points (glyph_id, start_offset, point_count, point_array); } |
791 | | |
792 | | unsigned int get_lig_carets (hb_font_t *font, |
793 | | hb_direction_t direction, |
794 | | hb_codepoint_t glyph_id, |
795 | | unsigned int start_offset, |
796 | | unsigned int *caret_count /* IN/OUT */, |
797 | | hb_position_t *caret_array /* OUT */) const |
798 | 153k | { return get_lig_caret_list ().get_lig_carets (font, |
799 | 153k | direction, glyph_id, get_var_store(), |
800 | 153k | start_offset, caret_count, caret_array); } |
801 | | |
802 | | bool mark_set_covers (unsigned int set_index, hb_codepoint_t glyph_id) const |
803 | 103k | { return get_mark_glyph_sets ().covers (set_index, glyph_id); } |
804 | | |
805 | | /* glyph_props is a 16-bit integer where the lower 8-bit have bits representing |
806 | | * glyph class and other bits, and high 8-bit the mark attachment type (if any). |
807 | | * Not to be confused with lookup_props which is very similar. */ |
808 | | unsigned int get_glyph_props (hb_codepoint_t glyph) const |
809 | 11.0M | { |
810 | 11.0M | unsigned int klass = get_glyph_class (glyph); |
811 | | |
812 | 11.0M | static_assert (((unsigned int) HB_OT_LAYOUT_GLYPH_PROPS_BASE_GLYPH == (unsigned int) LookupFlag::IgnoreBaseGlyphs), ""); |
813 | 11.0M | static_assert (((unsigned int) HB_OT_LAYOUT_GLYPH_PROPS_LIGATURE == (unsigned int) LookupFlag::IgnoreLigatures), ""); |
814 | 11.0M | static_assert (((unsigned int) HB_OT_LAYOUT_GLYPH_PROPS_MARK == (unsigned int) LookupFlag::IgnoreMarks), ""); |
815 | | |
816 | 11.0M | switch (klass) { |
817 | 9.41M | default: return HB_OT_LAYOUT_GLYPH_CLASS_UNCLASSIFIED; |
818 | 866k | case BaseGlyph: return HB_OT_LAYOUT_GLYPH_PROPS_BASE_GLYPH; |
819 | 101k | case LigatureGlyph: return HB_OT_LAYOUT_GLYPH_PROPS_LIGATURE; |
820 | 668k | case MarkGlyph: |
821 | 668k | klass = get_mark_attachment_type (glyph); |
822 | 668k | return HB_OT_LAYOUT_GLYPH_PROPS_MARK | (klass << 8); |
823 | 11.0M | } |
824 | 11.0M | } |
825 | | |
826 | | HB_INTERNAL bool is_blocklisted (hb_blob_t *blob, |
827 | | hb_face_t *face) const; |
828 | | |
829 | | struct accelerator_t |
830 | | { |
831 | | accelerator_t (hb_face_t *face) |
832 | 151k | { |
833 | 151k | table = hb_sanitize_context_t ().reference_table<GDEF> (face); |
834 | 151k | if (unlikely (table->is_blocklisted (table.get_blob (), face))) |
835 | 0 | { |
836 | 0 | hb_blob_destroy (table.get_blob ()); |
837 | 0 | table = hb_blob_get_empty (); |
838 | 0 | } |
839 | 151k | } |
840 | 150k | ~accelerator_t () { table.destroy (); } |
841 | | |
842 | | hb_blob_ptr_t<GDEF> table; |
843 | | }; |
844 | | |
845 | | void collect_variation_indices (hb_collect_variation_indices_context_t *c) const |
846 | 0 | { get_lig_caret_list ().collect_variation_indices (c); } |
847 | | |
848 | | void remap_layout_variation_indices (const hb_set_t *layout_variation_indices, |
849 | | hb_map_t *layout_variation_idx_map /* OUT */) const |
850 | 0 | { |
851 | 0 | if (!has_var_store ()) return; |
852 | 0 | if (layout_variation_indices->is_empty ()) return; |
853 | 0 |
|
854 | 0 | unsigned new_major = 0, new_minor = 0; |
855 | 0 | unsigned last_major = (layout_variation_indices->get_min ()) >> 16; |
856 | 0 | for (unsigned idx : layout_variation_indices->iter ()) |
857 | 0 | { |
858 | 0 | uint16_t major = idx >> 16; |
859 | 0 | if (major >= get_var_store ().get_sub_table_count ()) break; |
860 | 0 | if (major != last_major) |
861 | 0 | { |
862 | 0 | new_minor = 0; |
863 | 0 | ++new_major; |
864 | 0 | } |
865 | 0 |
|
866 | 0 | unsigned new_idx = (new_major << 16) + new_minor; |
867 | 0 | layout_variation_idx_map->set (idx, new_idx); |
868 | 0 | ++new_minor; |
869 | 0 | last_major = major; |
870 | 0 | } |
871 | 0 | } |
872 | | |
873 | | protected: |
874 | | union { |
875 | | FixedVersion<> version; /* Version identifier */ |
876 | | GDEFVersion1_2<SmallTypes> version1; |
877 | | #ifndef HB_NO_BEYOND_64K |
878 | | GDEFVersion1_2<MediumTypes> version2; |
879 | | #endif |
880 | | } u; |
881 | | public: |
882 | | DEFINE_SIZE_MIN (4); |
883 | | }; |
884 | | |
885 | | struct GDEF_accelerator_t : GDEF::accelerator_t { |
886 | 151k | GDEF_accelerator_t (hb_face_t *face) : GDEF::accelerator_t (face) {} |
887 | | }; |
888 | | |
889 | | } /* namespace OT */ |
890 | | |
891 | | |
892 | | #endif /* HB_OT_LAYOUT_GDEF_TABLE_HH */ |