2 * Copyright © 2007,2008,2009 Red Hat, Inc.
3 * Copyright © 2010,2011,2012 Google, Inc.
5 * This is part of HarfBuzz, a text shaping library.
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.
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
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.
25 * Red Hat Author(s): Behdad Esfahbod
26 * Google Author(s): Behdad Esfahbod
29 #ifndef HB_OT_LAYOUT_GDEF_TABLE_HH
30 #define HB_OT_LAYOUT_GDEF_TABLE_HH
32 #include "hb-ot-layout-common.hh"
41 * Attachment List Table
44 typedef ArrayOf<HBUINT16> AttachPoint; /* Array of contour point indices--in
45 * increasing numerical order */
49 unsigned int get_attach_points (hb_codepoint_t glyph_id,
50 unsigned int start_offset,
51 unsigned int *point_count /* IN/OUT */,
52 unsigned int *point_array /* OUT */) const
54 unsigned int index = (this+coverage).get_coverage (glyph_id);
55 if (index == NOT_COVERED)
62 const AttachPoint &points = this+attachPoint[index];
66 hb_array_t<const HBUINT16> array = points.sub_array (start_offset, point_count);
67 unsigned int count = array.length;
68 for (unsigned int i = 0; i < count; i++)
69 point_array[i] = array[i];
75 bool sanitize (hb_sanitize_context_t *c) const
77 TRACE_SANITIZE (this);
78 return_trace (coverage.sanitize (c, this) && attachPoint.sanitize (c, this));
83 coverage; /* Offset to Coverage table -- from
84 * beginning of AttachList table */
85 OffsetArrayOf<AttachPoint>
86 attachPoint; /* Array of AttachPoint tables
87 * in Coverage Index order */
89 DEFINE_SIZE_ARRAY (4, attachPoint);
93 * Ligature Caret Table
96 struct CaretValueFormat1
98 friend struct CaretValue;
101 hb_position_t get_caret_value (hb_font_t *font, hb_direction_t direction) const
103 return HB_DIRECTION_IS_HORIZONTAL (direction) ? font->em_scale_x (coordinate) : font->em_scale_y (coordinate);
106 bool sanitize (hb_sanitize_context_t *c) const
108 TRACE_SANITIZE (this);
109 return_trace (c->check_struct (this));
113 HBUINT16 caretValueFormat; /* Format identifier--format = 1 */
114 FWORD coordinate; /* X or Y value, in design units */
116 DEFINE_SIZE_STATIC (4);
119 struct CaretValueFormat2
121 friend struct CaretValue;
124 hb_position_t get_caret_value (hb_font_t *font, hb_direction_t direction, hb_codepoint_t glyph_id) const
127 font->get_glyph_contour_point_for_origin (glyph_id, caretValuePoint, direction, &x, &y);
128 return HB_DIRECTION_IS_HORIZONTAL (direction) ? x : y;
131 bool sanitize (hb_sanitize_context_t *c) const
133 TRACE_SANITIZE (this);
134 return_trace (c->check_struct (this));
138 HBUINT16 caretValueFormat; /* Format identifier--format = 2 */
139 HBUINT16 caretValuePoint; /* Contour point index on glyph */
141 DEFINE_SIZE_STATIC (4);
144 struct CaretValueFormat3
146 friend struct CaretValue;
148 hb_position_t get_caret_value (hb_font_t *font, hb_direction_t direction,
149 const VariationStore &var_store) const
151 return HB_DIRECTION_IS_HORIZONTAL (direction) ?
152 font->em_scale_x (coordinate) + (this+deviceTable).get_x_delta (font, var_store) :
153 font->em_scale_y (coordinate) + (this+deviceTable).get_y_delta (font, var_store);
156 bool sanitize (hb_sanitize_context_t *c) const
158 TRACE_SANITIZE (this);
159 return_trace (c->check_struct (this) && deviceTable.sanitize (c, this));
163 HBUINT16 caretValueFormat; /* Format identifier--format = 3 */
164 FWORD coordinate; /* X or Y value, in design units */
166 deviceTable; /* Offset to Device table for X or Y
167 * value--from beginning of CaretValue
170 DEFINE_SIZE_STATIC (6);
175 hb_position_t get_caret_value (hb_font_t *font,
176 hb_direction_t direction,
177 hb_codepoint_t glyph_id,
178 const VariationStore &var_store) const
181 case 1: return u.format1.get_caret_value (font, direction);
182 case 2: return u.format2.get_caret_value (font, direction, glyph_id);
183 case 3: return u.format3.get_caret_value (font, direction, var_store);
188 bool sanitize (hb_sanitize_context_t *c) const
190 TRACE_SANITIZE (this);
191 if (!u.format.sanitize (c)) return_trace (false);
193 case 1: return_trace (u.format1.sanitize (c));
194 case 2: return_trace (u.format2.sanitize (c));
195 case 3: return_trace (u.format3.sanitize (c));
196 default:return_trace (true);
202 HBUINT16 format; /* Format identifier */
203 CaretValueFormat1 format1;
204 CaretValueFormat2 format2;
205 CaretValueFormat3 format3;
208 DEFINE_SIZE_UNION (2, format);
213 unsigned int get_lig_carets (hb_font_t *font,
214 hb_direction_t direction,
215 hb_codepoint_t glyph_id,
216 const VariationStore &var_store,
217 unsigned int start_offset,
218 unsigned int *caret_count /* IN/OUT */,
219 hb_position_t *caret_array /* OUT */) const
223 hb_array_t <const OffsetTo<CaretValue>> array = carets.sub_array (start_offset, caret_count);
224 unsigned int count = array.length;
225 for (unsigned int i = 0; i < count; i++)
226 caret_array[i] = (this+array[i]).get_caret_value (font, direction, glyph_id, var_store);
232 bool sanitize (hb_sanitize_context_t *c) const
234 TRACE_SANITIZE (this);
235 return_trace (carets.sanitize (c, this));
239 OffsetArrayOf<CaretValue>
240 carets; /* Offset array of CaretValue tables
241 * --from beginning of LigGlyph table
242 * --in increasing coordinate order */
244 DEFINE_SIZE_ARRAY (2, carets);
249 unsigned int get_lig_carets (hb_font_t *font,
250 hb_direction_t direction,
251 hb_codepoint_t glyph_id,
252 const VariationStore &var_store,
253 unsigned int start_offset,
254 unsigned int *caret_count /* IN/OUT */,
255 hb_position_t *caret_array /* OUT */) const
257 unsigned int index = (this+coverage).get_coverage (glyph_id);
258 if (index == NOT_COVERED)
264 const LigGlyph &lig_glyph = this+ligGlyph[index];
265 return lig_glyph.get_lig_carets (font, direction, glyph_id, var_store, start_offset, caret_count, caret_array);
268 bool sanitize (hb_sanitize_context_t *c) const
270 TRACE_SANITIZE (this);
271 return_trace (coverage.sanitize (c, this) && ligGlyph.sanitize (c, this));
276 coverage; /* Offset to Coverage table--from
277 * beginning of LigCaretList table */
278 OffsetArrayOf<LigGlyph>
279 ligGlyph; /* Array of LigGlyph tables
280 * in Coverage Index order */
282 DEFINE_SIZE_ARRAY (4, ligGlyph);
286 struct MarkGlyphSetsFormat1
288 bool covers (unsigned int set_index, hb_codepoint_t glyph_id) const
289 { return (this+coverage[set_index]).get_coverage (glyph_id) != NOT_COVERED; }
291 bool sanitize (hb_sanitize_context_t *c) const
293 TRACE_SANITIZE (this);
294 return_trace (coverage.sanitize (c, this));
298 HBUINT16 format; /* Format identifier--format = 1 */
299 ArrayOf<LOffsetTo<Coverage>>
300 coverage; /* Array of long offsets to mark set
303 DEFINE_SIZE_ARRAY (4, coverage);
308 bool covers (unsigned int set_index, hb_codepoint_t glyph_id) const
311 case 1: return u.format1.covers (set_index, glyph_id);
312 default:return false;
316 bool sanitize (hb_sanitize_context_t *c) const
318 TRACE_SANITIZE (this);
319 if (!u.format.sanitize (c)) return_trace (false);
321 case 1: return_trace (u.format1.sanitize (c));
322 default:return_trace (true);
328 HBUINT16 format; /* Format identifier */
329 MarkGlyphSetsFormat1 format1;
332 DEFINE_SIZE_UNION (2, format);
337 * GDEF -- Glyph Definition
338 * https://docs.microsoft.com/en-us/typography/opentype/spec/gdef
344 static constexpr hb_tag_t tableTag = HB_OT_TAG_GDEF;
347 UnclassifiedGlyph = 0,
354 bool has_data () const { return version.to_int (); }
355 bool has_glyph_classes () const { return glyphClassDef != 0; }
356 unsigned int get_glyph_class (hb_codepoint_t glyph) const
357 { return (this+glyphClassDef).get_class (glyph); }
358 void get_glyphs_in_class (unsigned int klass, hb_set_t *glyphs) const
359 { (this+glyphClassDef).add_class (glyphs, klass); }
361 bool has_mark_attachment_types () const { return markAttachClassDef != 0; }
362 unsigned int get_mark_attachment_type (hb_codepoint_t glyph) const
363 { return (this+markAttachClassDef).get_class (glyph); }
365 bool has_attach_points () const { return attachList != 0; }
366 unsigned int get_attach_points (hb_codepoint_t glyph_id,
367 unsigned int start_offset,
368 unsigned int *point_count /* IN/OUT */,
369 unsigned int *point_array /* OUT */) const
370 { return (this+attachList).get_attach_points (glyph_id, start_offset, point_count, point_array); }
372 bool has_lig_carets () const { return ligCaretList != 0; }
373 unsigned int get_lig_carets (hb_font_t *font,
374 hb_direction_t direction,
375 hb_codepoint_t glyph_id,
376 unsigned int start_offset,
377 unsigned int *caret_count /* IN/OUT */,
378 hb_position_t *caret_array /* OUT */) const
379 { return (this+ligCaretList).get_lig_carets (font,
380 direction, glyph_id, get_var_store(),
381 start_offset, caret_count, caret_array); }
383 bool has_mark_sets () const { return version.to_int () >= 0x00010002u && markGlyphSetsDef != 0; }
384 bool mark_set_covers (unsigned int set_index, hb_codepoint_t glyph_id) const
385 { return version.to_int () >= 0x00010002u && (this+markGlyphSetsDef).covers (set_index, glyph_id); }
387 bool has_var_store () const { return version.to_int () >= 0x00010003u && varStore != 0; }
388 const VariationStore &get_var_store () const
389 { return version.to_int () >= 0x00010003u ? this+varStore : Null(VariationStore); }
391 /* glyph_props is a 16-bit integer where the lower 8-bit have bits representing
392 * glyph class and other bits, and high 8-bit the mark attachment type (if any).
393 * Not to be confused with lookup_props which is very similar. */
394 unsigned int get_glyph_props (hb_codepoint_t glyph) const
396 unsigned int klass = get_glyph_class (glyph);
398 static_assert (((unsigned int) HB_OT_LAYOUT_GLYPH_PROPS_BASE_GLYPH == (unsigned int) LookupFlag::IgnoreBaseGlyphs), "");
399 static_assert (((unsigned int) HB_OT_LAYOUT_GLYPH_PROPS_LIGATURE == (unsigned int) LookupFlag::IgnoreLigatures), "");
400 static_assert (((unsigned int) HB_OT_LAYOUT_GLYPH_PROPS_MARK == (unsigned int) LookupFlag::IgnoreMarks), "");
404 case BaseGlyph: return HB_OT_LAYOUT_GLYPH_PROPS_BASE_GLYPH;
405 case LigatureGlyph: return HB_OT_LAYOUT_GLYPH_PROPS_LIGATURE;
407 klass = get_mark_attachment_type (glyph);
408 return HB_OT_LAYOUT_GLYPH_PROPS_MARK | (klass << 8);
412 HB_INTERNAL bool is_blacklisted (hb_blob_t *blob,
413 hb_face_t *face) const;
417 void init (hb_face_t *face)
419 this->table = hb_sanitize_context_t().reference_table<GDEF> (face);
420 if (unlikely (this->table->is_blacklisted (this->table.get_blob (), face)))
422 hb_blob_destroy (this->table.get_blob ());
423 this->table = hb_blob_get_empty ();
427 void fini () { this->table.destroy (); }
429 hb_blob_ptr_t<GDEF> table;
432 unsigned int get_size () const
435 (version.to_int () >= 0x00010002u ? markGlyphSetsDef.static_size : 0) +
436 (version.to_int () >= 0x00010003u ? varStore.static_size : 0);
439 bool subset (hb_subset_context_t *c) const
442 auto *out = c->serializer->embed (*this);
443 if (unlikely (!out)) return_trace (false);
445 out->glyphClassDef.serialize_subset (c, glyphClassDef, this, out);
446 out->attachList = 0;//TODO(subset) serialize_subset (c, attachList, this, out);
447 out->ligCaretList = 0;//TODO(subset) serialize_subset (c, ligCaretList, this, out);
448 out->markAttachClassDef.serialize_subset (c, markAttachClassDef, this, out);
450 if (version.to_int () >= 0x00010002u)
451 out->markGlyphSetsDef = 0;// TODO(subset) serialize_subset (c, markGlyphSetsDef, this, out);
453 if (version.to_int () >= 0x00010003u)
454 out->varStore = 0;// TODO(subset) serialize_subset (c, varStore, this, out);
459 bool sanitize (hb_sanitize_context_t *c) const
461 TRACE_SANITIZE (this);
462 return_trace (version.sanitize (c) &&
463 likely (version.major == 1) &&
464 glyphClassDef.sanitize (c, this) &&
465 attachList.sanitize (c, this) &&
466 ligCaretList.sanitize (c, this) &&
467 markAttachClassDef.sanitize (c, this) &&
468 (version.to_int () < 0x00010002u || markGlyphSetsDef.sanitize (c, this)) &&
469 (version.to_int () < 0x00010003u || varStore.sanitize (c, this)));
473 FixedVersion<>version; /* Version of the GDEF table--currently
476 glyphClassDef; /* Offset to class definition table
477 * for glyph type--from beginning of
478 * GDEF header (may be Null) */
480 attachList; /* Offset to list of glyphs with
481 * attachment points--from beginning
482 * of GDEF header (may be Null) */
483 OffsetTo<LigCaretList>
484 ligCaretList; /* Offset to list of positioning points
485 * for ligature carets--from beginning
486 * of GDEF header (may be Null) */
488 markAttachClassDef; /* Offset to class definition table for
489 * mark attachment type--from beginning
490 * of GDEF header (may be Null) */
491 OffsetTo<MarkGlyphSets>
492 markGlyphSetsDef; /* Offset to the table of mark set
493 * definitions--from beginning of GDEF
494 * header (may be NULL). Introduced
495 * in version 0x00010002. */
496 LOffsetTo<VariationStore>
497 varStore; /* Offset to the table of Item Variation
498 * Store--from beginning of GDEF
499 * header (may be NULL). Introduced
500 * in version 0x00010003. */
502 DEFINE_SIZE_MIN (12);
505 struct GDEF_accelerator_t : GDEF::accelerator_t {};
510 #endif /* HB_OT_LAYOUT_GDEF_TABLE_HH */