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.hh"
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 *c) {
71 return coverage.sanitize (c, this)
72 && attachPoint.sanitize (c, 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 *c, hb_codepoint_t glyph_id HB_UNUSED) const
98 return c->scale_x (coordinate);
101 inline bool sanitize (hb_sanitize_context_t *c) {
103 return c->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 *c, hb_codepoint_t glyph_id) const
122 if (hb_font_get_contour_point (c->font, c->face, caretValuePoint, glyph_id, &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_codepoint_t glyph_id HB_UNUSED) const
147 return c->scale_x (coordinate) + ((this+deviceTable).get_x_delta (c));
150 inline bool sanitize (hb_sanitize_context_t *c) {
152 return c->check_struct (this)
153 && deviceTable.sanitize (c, this);
157 USHORT caretValueFormat; /* Format identifier--format = 3 */
158 SHORT coordinate; /* X or Y value, in design units */
160 deviceTable; /* Offset to Device table for X or Y
161 * value--from beginning of CaretValue
164 DEFINE_SIZE_STATIC (6);
169 inline int get_caret_value (hb_ot_layout_context_t *c, hb_codepoint_t glyph_id) const
172 case 1: return u.format1.get_caret_value (c, glyph_id);
173 case 2: return u.format2.get_caret_value (c, glyph_id);
174 case 3: return u.format3.get_caret_value (c, glyph_id);
179 inline bool sanitize (hb_sanitize_context_t *c) {
181 if (!u.format.sanitize (c)) return false;
183 case 1: return u.format1.sanitize (c);
184 case 2: return u.format2.sanitize (c);
185 case 3: return u.format3.sanitize (c);
192 USHORT format; /* Format identifier */
193 CaretValueFormat1 format1;
194 CaretValueFormat2 format2;
195 CaretValueFormat3 format3;
198 DEFINE_SIZE_UNION (2, format);
203 inline unsigned int get_lig_carets (hb_ot_layout_context_t *c,
204 hb_codepoint_t glyph_id,
205 unsigned int start_offset,
206 unsigned int *caret_count /* IN/OUT */,
207 int *caret_array /* OUT */) const
210 const OffsetTo<CaretValue> *array = carets.sub_array (start_offset, caret_count);
211 unsigned int count = *caret_count;
212 for (unsigned int i = 0; i < count; i++)
213 caret_array[i] = (this+array[i]).get_caret_value (c, glyph_id);
219 inline bool sanitize (hb_sanitize_context_t *c) {
221 return carets.sanitize (c, this);
225 OffsetArrayOf<CaretValue>
226 carets; /* Offset array of CaretValue tables
227 * --from beginning of LigGlyph table
228 * --in increasing coordinate order */
230 DEFINE_SIZE_ARRAY (2, carets);
235 inline unsigned int get_lig_carets (hb_ot_layout_context_t *c,
236 hb_codepoint_t glyph_id,
237 unsigned int start_offset,
238 unsigned int *caret_count /* IN/OUT */,
239 int *caret_array /* OUT */) const
241 unsigned int index = (this+coverage) (glyph_id);
242 if (index == NOT_COVERED)
248 const LigGlyph &lig_glyph = this+ligGlyph[index];
249 return lig_glyph.get_lig_carets (c, glyph_id, start_offset, caret_count, caret_array);
252 inline bool sanitize (hb_sanitize_context_t *c) {
254 return coverage.sanitize (c, this)
255 && ligGlyph.sanitize (c, this);
260 coverage; /* Offset to Coverage table--from
261 * beginning of LigCaretList table */
262 OffsetArrayOf<LigGlyph>
263 ligGlyph; /* Array of LigGlyph tables
264 * in Coverage Index order */
266 DEFINE_SIZE_ARRAY (4, ligGlyph);
270 struct MarkGlyphSetsFormat1
272 inline bool covers (unsigned int set_index, hb_codepoint_t glyph_id) const
273 { return (this+coverage[set_index]).get_coverage (glyph_id) != NOT_COVERED; }
275 inline bool sanitize (hb_sanitize_context_t *c) {
277 return coverage.sanitize (c, this);
281 USHORT format; /* Format identifier--format = 1 */
282 LongOffsetArrayOf<Coverage>
283 coverage; /* Array of long offsets to mark set
286 DEFINE_SIZE_ARRAY (4, coverage);
291 inline bool covers (unsigned int set_index, hb_codepoint_t glyph_id) const
294 case 1: return u.format1.covers (set_index, glyph_id);
295 default:return false;
299 inline bool sanitize (hb_sanitize_context_t *c) {
301 if (!u.format.sanitize (c)) return false;
303 case 1: return u.format1.sanitize (c);
310 USHORT format; /* Format identifier */
311 MarkGlyphSetsFormat1 format1;
314 DEFINE_SIZE_UNION (2, format);
324 static const hb_tag_t Tag = HB_OT_TAG_GDEF;
327 UnclassifiedGlyph = 0,
334 inline bool has_glyph_classes () const { return glyphClassDef != 0; }
335 inline hb_ot_layout_class_t get_glyph_class (hb_codepoint_t glyph) const
336 { return (this+glyphClassDef).get_class (glyph); }
338 inline bool has_mark_attachment_types () const { return markAttachClassDef != 0; }
339 inline hb_ot_layout_class_t get_mark_attachment_type (hb_codepoint_t glyph) const
340 { return (this+markAttachClassDef).get_class (glyph); }
342 inline bool has_attach_points () const { return attachList != 0; }
343 inline unsigned int get_attach_points (hb_codepoint_t glyph_id,
344 unsigned int start_offset,
345 unsigned int *point_count /* IN/OUT */,
346 unsigned int *point_array /* OUT */) const
347 { return (this+attachList).get_attach_points (glyph_id, start_offset, point_count, point_array); }
349 inline bool has_lig_carets () const { return ligCaretList != 0; }
350 inline unsigned int get_lig_carets (hb_ot_layout_context_t *c,
351 hb_codepoint_t glyph_id,
352 unsigned int start_offset,
353 unsigned int *caret_count /* IN/OUT */,
354 int *caret_array /* OUT */) const
355 { return (this+ligCaretList).get_lig_carets (c, glyph_id, start_offset, caret_count, caret_array); }
357 inline bool has_mark_sets () const { return version >= 0x00010002 && markGlyphSetsDef[0] != 0; }
358 inline bool mark_set_covers (unsigned int set_index, hb_codepoint_t glyph_id) const
359 { return version >= 0x00010002 && (this+markGlyphSetsDef[0]).covers (set_index, glyph_id); }
361 inline bool sanitize (hb_sanitize_context_t *c) {
363 return version.sanitize (c) && likely (version.major == 1)
364 && glyphClassDef.sanitize (c, this)
365 && attachList.sanitize (c, this)
366 && ligCaretList.sanitize (c, this)
367 && markAttachClassDef.sanitize (c, this)
368 && (version < 0x00010002 || markGlyphSetsDef[0].sanitize (c, this));
372 FixedVersion version; /* Version of the GDEF table--currently
375 glyphClassDef; /* Offset to class definition table
376 * for glyph type--from beginning of
377 * GDEF header (may be Null) */
379 attachList; /* Offset to list of glyphs with
380 * attachment points--from beginning
381 * of GDEF header (may be Null) */
382 OffsetTo<LigCaretList>
383 ligCaretList; /* Offset to list of positioning points
384 * for ligature carets--from beginning
385 * of GDEF header (may be Null) */
387 markAttachClassDef; /* Offset to class definition table for
388 * mark attachment type--from beginning
389 * of GDEF header (may be Null) */
390 OffsetTo<MarkGlyphSets>
391 markGlyphSetsDef[VAR]; /* Offset to the table of mark set
392 * definitions--from beginning of GDEF
393 * header (may be NULL). Introduced
394 * in version 00010002. */
396 DEFINE_SIZE_ARRAY (12, markGlyphSetsDef);
400 #endif /* HB_OT_LAYOUT_GDEF_PRIVATE_HH */