2 * Copyright (C) 2007,2008,2009 Red Hat, Inc.
4 * This is part of HarfBuzz, a text shaping library.
6 * Permission is hereby granted, without written agreement and without
7 * license or royalty fees, to use, copy, modify, and distribute this
8 * software and its documentation for any purpose, provided that the
9 * above copyright notice and the following two paragraphs appear in
10 * all copies of this software.
12 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
13 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
14 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
15 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
18 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
19 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
21 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
22 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
24 * Red Hat Author(s): Behdad Esfahbod
27 #ifndef HB_OT_LAYOUT_GDEF_PRIVATE_HH
28 #define HB_OT_LAYOUT_GDEF_PRIVATE_HH
30 #include "hb-ot-layout-common-private.hh"
32 #include "hb-font-private.h"
36 * Attachment List Table
39 typedef ArrayOf<USHORT> AttachPoint; /* Array of contour point indices--in
40 * increasing numerical order */
44 inline unsigned int get_attach_points (hb_codepoint_t glyph_id,
45 unsigned int start_offset,
46 unsigned int *point_count /* IN/OUT */,
47 unsigned int *point_array /* OUT */) const
49 unsigned int index = (this+coverage) (glyph_id);
50 if (index == NOT_COVERED)
57 const AttachPoint &points = this+attachPoint[index];
60 const USHORT *array = points.sub_array (start_offset, point_count);
61 unsigned int count = *point_count;
62 for (unsigned int i = 0; i < count; i++)
63 point_array[i] = array[i];
69 inline bool sanitize (hb_sanitize_context_t *context) {
71 return coverage.sanitize (context, this)
72 && attachPoint.sanitize (context, this);
77 coverage; /* Offset to Coverage table -- from
78 * beginning of AttachList table */
79 OffsetArrayOf<AttachPoint>
80 attachPoint; /* Array of AttachPoint tables
81 * in Coverage Index order */
83 DEFINE_SIZE_ARRAY (4, attachPoint);
87 * Ligature Caret Table
90 struct CaretValueFormat1
92 friend struct CaretValue;
95 inline int get_caret_value (hb_ot_layout_context_t *context, hb_codepoint_t glyph_id HB_UNUSED) const
98 return _hb_16dot16_mul_round (context->font->x_scale, coordinate);
101 inline bool sanitize (hb_sanitize_context_t *context) {
103 return context->check_struct (this);
107 USHORT caretValueFormat; /* Format identifier--format = 1 */
108 SHORT coordinate; /* X or Y value, in design units */
110 DEFINE_SIZE_STATIC (4);
113 struct CaretValueFormat2
115 friend struct CaretValue;
118 inline int get_caret_value (hb_ot_layout_context_t *context, hb_codepoint_t glyph_id) const
122 if (hb_font_get_contour_point (context->font, context->face, caretValuePoint, glyph_id, &x, &y))
128 inline bool sanitize (hb_sanitize_context_t *context) {
130 return context->check_struct (this);
134 USHORT caretValueFormat; /* Format identifier--format = 2 */
135 USHORT caretValuePoint; /* Contour point index on glyph */
137 DEFINE_SIZE_STATIC (4);
140 struct CaretValueFormat3
142 friend struct CaretValue;
144 inline int get_caret_value (hb_ot_layout_context_t *context, hb_codepoint_t glyph_id HB_UNUSED) const
147 return _hb_16dot16_mul_round (context->font->x_scale, coordinate) +
148 ((this+deviceTable).get_delta (context->font->x_ppem) << 16);
151 inline bool sanitize (hb_sanitize_context_t *context) {
153 return context->check_struct (this)
154 && deviceTable.sanitize (context, this);
158 USHORT caretValueFormat; /* Format identifier--format = 3 */
159 SHORT coordinate; /* X or Y value, in design units */
161 deviceTable; /* Offset to Device table for X or Y
162 * value--from beginning of CaretValue
165 DEFINE_SIZE_STATIC (6);
170 inline int get_caret_value (hb_ot_layout_context_t *context, hb_codepoint_t glyph_id) const
173 case 1: return u.format1.get_caret_value (context, glyph_id);
174 case 2: return u.format2.get_caret_value (context, glyph_id);
175 case 3: return u.format3.get_caret_value (context, glyph_id);
180 inline bool sanitize (hb_sanitize_context_t *context) {
182 if (!u.format.sanitize (context)) return false;
184 case 1: return u.format1.sanitize (context);
185 case 2: return u.format2.sanitize (context);
186 case 3: return u.format3.sanitize (context);
193 USHORT format; /* Format identifier */
194 CaretValueFormat1 format1;
195 CaretValueFormat2 format2;
196 CaretValueFormat3 format3;
199 DEFINE_SIZE_UNION (2, format);
204 inline unsigned int get_lig_carets (hb_ot_layout_context_t *context,
205 hb_codepoint_t glyph_id,
206 unsigned int start_offset,
207 unsigned int *caret_count /* IN/OUT */,
208 int *caret_array /* OUT */) const
211 const OffsetTo<CaretValue> *array = carets.sub_array (start_offset, caret_count);
212 unsigned int count = *caret_count;
213 for (unsigned int i = 0; i < count; i++)
214 caret_array[i] = (this+array[i]).get_caret_value (context, glyph_id);
220 inline bool sanitize (hb_sanitize_context_t *context) {
222 return carets.sanitize (context, this);
226 OffsetArrayOf<CaretValue>
227 carets; /* Offset array of CaretValue tables
228 * --from beginning of LigGlyph table
229 * --in increasing coordinate order */
231 DEFINE_SIZE_ARRAY (2, carets);
236 inline unsigned int get_lig_carets (hb_ot_layout_context_t *context,
237 hb_codepoint_t glyph_id,
238 unsigned int start_offset,
239 unsigned int *caret_count /* IN/OUT */,
240 int *caret_array /* OUT */) const
242 unsigned int index = (this+coverage) (glyph_id);
243 if (index == NOT_COVERED)
249 const LigGlyph &lig_glyph = this+ligGlyph[index];
250 return lig_glyph.get_lig_carets (context, glyph_id, start_offset, caret_count, caret_array);
253 inline bool sanitize (hb_sanitize_context_t *context) {
255 return coverage.sanitize (context, this)
256 && ligGlyph.sanitize (context, this);
261 coverage; /* Offset to Coverage table--from
262 * beginning of LigCaretList table */
263 OffsetArrayOf<LigGlyph>
264 ligGlyph; /* Array of LigGlyph tables
265 * in Coverage Index order */
267 DEFINE_SIZE_ARRAY (4, ligGlyph);
271 struct MarkGlyphSetsFormat1
273 inline bool covers (unsigned int set_index, hb_codepoint_t glyph_id) const
274 { return (this+coverage[set_index]).get_coverage (glyph_id) != NOT_COVERED; }
276 inline bool sanitize (hb_sanitize_context_t *context) {
278 return coverage.sanitize (context, this);
282 USHORT format; /* Format identifier--format = 1 */
283 LongOffsetArrayOf<Coverage>
284 coverage; /* Array of long offsets to mark set
287 DEFINE_SIZE_ARRAY (4, coverage);
292 inline bool covers (unsigned int set_index, hb_codepoint_t glyph_id) const
295 case 1: return u.format1.covers (set_index, glyph_id);
296 default:return false;
300 inline bool sanitize (hb_sanitize_context_t *context) {
302 if (!u.format.sanitize (context)) return false;
304 case 1: return u.format1.sanitize (context);
311 USHORT format; /* Format identifier */
312 MarkGlyphSetsFormat1 format1;
315 DEFINE_SIZE_UNION (2, format);
325 static const hb_tag_t Tag = HB_OT_TAG_GDEF;
328 UnclassifiedGlyph = 0,
335 inline bool has_glyph_classes () const { return glyphClassDef != 0; }
336 inline hb_ot_layout_class_t get_glyph_class (hb_codepoint_t glyph) const
337 { return (this+glyphClassDef).get_class (glyph); }
339 inline bool has_mark_attachment_types () const { return markAttachClassDef != 0; }
340 inline hb_ot_layout_class_t get_mark_attachment_type (hb_codepoint_t glyph) const
341 { return (this+markAttachClassDef).get_class (glyph); }
343 inline bool has_attach_points () const { return attachList != 0; }
344 inline unsigned int get_attach_points (hb_codepoint_t glyph_id,
345 unsigned int start_offset,
346 unsigned int *point_count /* IN/OUT */,
347 unsigned int *point_array /* OUT */) const
348 { return (this+attachList).get_attach_points (glyph_id, start_offset, point_count, point_array); }
350 inline bool has_lig_carets () const { return ligCaretList != 0; }
351 inline unsigned int get_lig_carets (hb_ot_layout_context_t *context,
352 hb_codepoint_t glyph_id,
353 unsigned int start_offset,
354 unsigned int *caret_count /* IN/OUT */,
355 int *caret_array /* OUT */) const
356 { return (this+ligCaretList).get_lig_carets (context, glyph_id, start_offset, caret_count, caret_array); }
358 inline bool has_mark_sets () const { return version >= 0x00010002 && markGlyphSetsDef[0] != 0; }
359 inline bool mark_set_covers (unsigned int set_index, hb_codepoint_t glyph_id) const
360 { return version >= 0x00010002 && (this+markGlyphSetsDef[0]).covers (set_index, glyph_id); }
362 inline bool sanitize (hb_sanitize_context_t *context) {
364 return version.sanitize (context) && likely (version.major == 1)
365 && glyphClassDef.sanitize (context, this)
366 && attachList.sanitize (context, this)
367 && ligCaretList.sanitize (context, this)
368 && markAttachClassDef.sanitize (context, this)
369 && (version < 0x00010002 || markGlyphSetsDef[0].sanitize (context, this));
373 FixedVersion version; /* Version of the GDEF table--currently
376 glyphClassDef; /* Offset to class definition table
377 * for glyph type--from beginning of
378 * GDEF header (may be Null) */
380 attachList; /* Offset to list of glyphs with
381 * attachment points--from beginning
382 * of GDEF header (may be Null) */
383 OffsetTo<LigCaretList>
384 ligCaretList; /* Offset to list of positioning points
385 * for ligature carets--from beginning
386 * of GDEF header (may be Null) */
388 markAttachClassDef; /* Offset to class definition table for
389 * mark attachment type--from beginning
390 * of GDEF header (may be Null) */
391 OffsetTo<MarkGlyphSets>
392 markGlyphSetsDef[VAR]; /* Offset to the table of mark set
393 * definitions--from beginning of GDEF
394 * header (may be NULL). Introduced
395 * in version 00010002. */
397 DEFINE_SIZE_ARRAY (12, markGlyphSetsDef);
401 #endif /* HB_OT_LAYOUT_GDEF_PRIVATE_HH */