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"
38 * Attachment List Table
41 typedef ArrayOf<USHORT> AttachPoint; /* Array of contour point indices--in
42 * increasing numerical order */
46 inline unsigned int get_attach_points (hb_codepoint_t glyph_id,
47 unsigned int start_offset,
48 unsigned int *point_count /* IN/OUT */,
49 unsigned int *point_array /* OUT */) const
51 unsigned int index = (this+coverage) (glyph_id);
52 if (index == NOT_COVERED)
59 const AttachPoint &points = this+attachPoint[index];
62 const USHORT *array = points.sub_array (start_offset, point_count);
63 unsigned int count = *point_count;
64 for (unsigned int i = 0; i < count; i++)
65 point_array[i] = array[i];
71 inline bool sanitize (hb_sanitize_context_t *c) {
73 return coverage.sanitize (c, this)
74 && attachPoint.sanitize (c, this);
79 coverage; /* Offset to Coverage table -- from
80 * beginning of AttachList table */
81 OffsetArrayOf<AttachPoint>
82 attachPoint; /* Array of AttachPoint tables
83 * in Coverage Index order */
85 DEFINE_SIZE_ARRAY (4, attachPoint);
89 * Ligature Caret Table
92 struct CaretValueFormat1
94 friend struct CaretValue;
97 inline int get_caret_value (hb_ot_layout_context_t *c, hb_direction_t direction, hb_codepoint_t glyph_id HB_UNUSED) const
99 return HB_DIRECTION_IS_HORIZONTAL (direction) ? c->scale_x (coordinate) : c->scale_y (coordinate);
102 inline bool sanitize (hb_sanitize_context_t *c) {
104 return c->check_struct (this);
108 USHORT caretValueFormat; /* Format identifier--format = 1 */
109 SHORT coordinate; /* X or Y value, in design units */
111 DEFINE_SIZE_STATIC (4);
114 struct CaretValueFormat2
116 friend struct CaretValue;
119 inline int get_caret_value (hb_ot_layout_context_t *c, hb_direction_t direction, hb_codepoint_t glyph_id) const
122 if (hb_font_get_contour_point (c->font, c->face, caretValuePoint, glyph_id, &x, &y))
123 return HB_DIRECTION_IS_HORIZONTAL (direction) ? x : y;
128 inline bool sanitize (hb_sanitize_context_t *c) {
130 return c->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 *c, hb_direction_t direction, hb_codepoint_t glyph_id) const
146 return HB_DIRECTION_IS_HORIZONTAL (direction) ?
147 c->scale_x (coordinate) + (this+deviceTable).get_x_delta (c) :
148 c->scale_y (coordinate) + (this+deviceTable).get_y_delta (c);
151 inline bool sanitize (hb_sanitize_context_t *c) {
153 return c->check_struct (this)
154 && deviceTable.sanitize (c, 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 *c, hb_direction_t direction, hb_codepoint_t glyph_id) const
173 case 1: return u.format1.get_caret_value (c, direction, glyph_id);
174 case 2: return u.format2.get_caret_value (c, direction, glyph_id);
175 case 3: return u.format3.get_caret_value (c, direction, glyph_id);
180 inline bool sanitize (hb_sanitize_context_t *c) {
182 if (!u.format.sanitize (c)) return false;
184 case 1: return u.format1.sanitize (c);
185 case 2: return u.format2.sanitize (c);
186 case 3: return u.format3.sanitize (c);
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 *c,
205 hb_direction_t direction,
206 hb_codepoint_t glyph_id,
207 unsigned int start_offset,
208 unsigned int *caret_count /* IN/OUT */,
209 int *caret_array /* OUT */) const
212 const OffsetTo<CaretValue> *array = carets.sub_array (start_offset, caret_count);
213 unsigned int count = *caret_count;
214 for (unsigned int i = 0; i < count; i++)
215 caret_array[i] = (this+array[i]).get_caret_value (c, direction, glyph_id);
221 inline bool sanitize (hb_sanitize_context_t *c) {
223 return carets.sanitize (c, this);
227 OffsetArrayOf<CaretValue>
228 carets; /* Offset array of CaretValue tables
229 * --from beginning of LigGlyph table
230 * --in increasing coordinate order */
232 DEFINE_SIZE_ARRAY (2, carets);
237 inline unsigned int get_lig_carets (hb_ot_layout_context_t *c,
238 hb_direction_t direction,
239 hb_codepoint_t glyph_id,
240 unsigned int start_offset,
241 unsigned int *caret_count /* IN/OUT */,
242 int *caret_array /* OUT */) const
244 unsigned int index = (this+coverage) (glyph_id);
245 if (index == NOT_COVERED)
251 const LigGlyph &lig_glyph = this+ligGlyph[index];
252 return lig_glyph.get_lig_carets (c, direction, glyph_id, start_offset, caret_count, caret_array);
255 inline bool sanitize (hb_sanitize_context_t *c) {
257 return coverage.sanitize (c, this)
258 && ligGlyph.sanitize (c, this);
263 coverage; /* Offset to Coverage table--from
264 * beginning of LigCaretList table */
265 OffsetArrayOf<LigGlyph>
266 ligGlyph; /* Array of LigGlyph tables
267 * in Coverage Index order */
269 DEFINE_SIZE_ARRAY (4, ligGlyph);
273 struct MarkGlyphSetsFormat1
275 inline bool covers (unsigned int set_index, hb_codepoint_t glyph_id) const
276 { return (this+coverage[set_index]).get_coverage (glyph_id) != NOT_COVERED; }
278 inline bool sanitize (hb_sanitize_context_t *c) {
280 return coverage.sanitize (c, this);
284 USHORT format; /* Format identifier--format = 1 */
285 LongOffsetArrayOf<Coverage>
286 coverage; /* Array of long offsets to mark set
289 DEFINE_SIZE_ARRAY (4, coverage);
294 inline bool covers (unsigned int set_index, hb_codepoint_t glyph_id) const
297 case 1: return u.format1.covers (set_index, glyph_id);
298 default:return false;
302 inline bool sanitize (hb_sanitize_context_t *c) {
304 if (!u.format.sanitize (c)) return false;
306 case 1: return u.format1.sanitize (c);
313 USHORT format; /* Format identifier */
314 MarkGlyphSetsFormat1 format1;
317 DEFINE_SIZE_UNION (2, format);
327 static const hb_tag_t Tag = HB_OT_TAG_GDEF;
330 UnclassifiedGlyph = 0,
337 inline bool has_glyph_classes (void) const { return glyphClassDef != 0; }
338 inline hb_ot_layout_class_t get_glyph_class (hb_codepoint_t glyph) const
339 { return (this+glyphClassDef).get_class (glyph); }
341 inline bool has_mark_attachment_types (void) const { return markAttachClassDef != 0; }
342 inline hb_ot_layout_class_t get_mark_attachment_type (hb_codepoint_t glyph) const
343 { return (this+markAttachClassDef).get_class (glyph); }
345 inline bool has_attach_points (void) const { return attachList != 0; }
346 inline unsigned int get_attach_points (hb_codepoint_t glyph_id,
347 unsigned int start_offset,
348 unsigned int *point_count /* IN/OUT */,
349 unsigned int *point_array /* OUT */) const
350 { return (this+attachList).get_attach_points (glyph_id, start_offset, point_count, point_array); }
352 inline bool has_lig_carets (void) const { return ligCaretList != 0; }
353 inline unsigned int get_lig_carets (hb_ot_layout_context_t *c,
354 hb_direction_t direction,
355 hb_codepoint_t glyph_id,
356 unsigned int start_offset,
357 unsigned int *caret_count /* IN/OUT */,
358 int *caret_array /* OUT */) const
359 { return (this+ligCaretList).get_lig_carets (c, direction, glyph_id, start_offset, caret_count, caret_array); }
361 inline bool has_mark_sets (void) const { return version >= 0x00010002 && markGlyphSetsDef[0] != 0; }
362 inline bool mark_set_covers (unsigned int set_index, hb_codepoint_t glyph_id) const
363 { return version >= 0x00010002 && (this+markGlyphSetsDef[0]).covers (set_index, glyph_id); }
365 inline bool sanitize (hb_sanitize_context_t *c) {
367 return version.sanitize (c) && likely (version.major == 1)
368 && glyphClassDef.sanitize (c, this)
369 && attachList.sanitize (c, this)
370 && ligCaretList.sanitize (c, this)
371 && markAttachClassDef.sanitize (c, this)
372 && (version < 0x00010002 || markGlyphSetsDef[0].sanitize (c, this));
376 FixedVersion version; /* Version of the GDEF table--currently
379 glyphClassDef; /* Offset to class definition table
380 * for glyph type--from beginning of
381 * GDEF header (may be Null) */
383 attachList; /* Offset to list of glyphs with
384 * attachment points--from beginning
385 * of GDEF header (may be Null) */
386 OffsetTo<LigCaretList>
387 ligCaretList; /* Offset to list of positioning points
388 * for ligature carets--from beginning
389 * of GDEF header (may be Null) */
391 markAttachClassDef; /* Offset to class definition table for
392 * mark attachment type--from beginning
393 * of GDEF header (may be Null) */
394 OffsetTo<MarkGlyphSets>
395 markGlyphSetsDef[VAR]; /* Offset to the table of mark set
396 * definitions--from beginning of GDEF
397 * header (may be NULL). Introduced
398 * in version 00010002. */
400 DEFINE_SIZE_ARRAY (12, markGlyphSetsDef);
406 #endif /* HB_OT_LAYOUT_GDEF_PRIVATE_HH */