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_codepoint_t glyph_id HB_UNUSED) const
100 return c->scale_x (coordinate);
103 inline bool sanitize (hb_sanitize_context_t *c) {
105 return c->check_struct (this);
109 USHORT caretValueFormat; /* Format identifier--format = 1 */
110 SHORT coordinate; /* X or Y value, in design units */
112 DEFINE_SIZE_STATIC (4);
115 struct CaretValueFormat2
117 friend struct CaretValue;
120 inline int get_caret_value (hb_ot_layout_context_t *c, hb_codepoint_t glyph_id) const
124 if (hb_font_get_contour_point (c->font, c->face, caretValuePoint, glyph_id, &x, &y))
130 inline bool sanitize (hb_sanitize_context_t *c) {
132 return c->check_struct (this);
136 USHORT caretValueFormat; /* Format identifier--format = 2 */
137 USHORT caretValuePoint; /* Contour point index on glyph */
139 DEFINE_SIZE_STATIC (4);
142 struct CaretValueFormat3
144 friend struct CaretValue;
146 inline int get_caret_value (hb_ot_layout_context_t *c, hb_codepoint_t glyph_id HB_UNUSED) const
149 return c->scale_x (coordinate) + ((this+deviceTable).get_x_delta (c));
152 inline bool sanitize (hb_sanitize_context_t *c) {
154 return c->check_struct (this)
155 && deviceTable.sanitize (c, this);
159 USHORT caretValueFormat; /* Format identifier--format = 3 */
160 SHORT coordinate; /* X or Y value, in design units */
162 deviceTable; /* Offset to Device table for X or Y
163 * value--from beginning of CaretValue
166 DEFINE_SIZE_STATIC (6);
171 inline int get_caret_value (hb_ot_layout_context_t *c, hb_codepoint_t glyph_id) const
174 case 1: return u.format1.get_caret_value (c, glyph_id);
175 case 2: return u.format2.get_caret_value (c, glyph_id);
176 case 3: return u.format3.get_caret_value (c, glyph_id);
181 inline bool sanitize (hb_sanitize_context_t *c) {
183 if (!u.format.sanitize (c)) return false;
185 case 1: return u.format1.sanitize (c);
186 case 2: return u.format2.sanitize (c);
187 case 3: return u.format3.sanitize (c);
194 USHORT format; /* Format identifier */
195 CaretValueFormat1 format1;
196 CaretValueFormat2 format2;
197 CaretValueFormat3 format3;
200 DEFINE_SIZE_UNION (2, format);
205 inline unsigned int get_lig_carets (hb_ot_layout_context_t *c,
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, 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_codepoint_t glyph_id,
239 unsigned int start_offset,
240 unsigned int *caret_count /* IN/OUT */,
241 int *caret_array /* OUT */) const
243 unsigned int index = (this+coverage) (glyph_id);
244 if (index == NOT_COVERED)
250 const LigGlyph &lig_glyph = this+ligGlyph[index];
251 return lig_glyph.get_lig_carets (c, glyph_id, start_offset, caret_count, caret_array);
254 inline bool sanitize (hb_sanitize_context_t *c) {
256 return coverage.sanitize (c, this)
257 && ligGlyph.sanitize (c, this);
262 coverage; /* Offset to Coverage table--from
263 * beginning of LigCaretList table */
264 OffsetArrayOf<LigGlyph>
265 ligGlyph; /* Array of LigGlyph tables
266 * in Coverage Index order */
268 DEFINE_SIZE_ARRAY (4, ligGlyph);
272 struct MarkGlyphSetsFormat1
274 inline bool covers (unsigned int set_index, hb_codepoint_t glyph_id) const
275 { return (this+coverage[set_index]).get_coverage (glyph_id) != NOT_COVERED; }
277 inline bool sanitize (hb_sanitize_context_t *c) {
279 return coverage.sanitize (c, this);
283 USHORT format; /* Format identifier--format = 1 */
284 LongOffsetArrayOf<Coverage>
285 coverage; /* Array of long offsets to mark set
288 DEFINE_SIZE_ARRAY (4, coverage);
293 inline bool covers (unsigned int set_index, hb_codepoint_t glyph_id) const
296 case 1: return u.format1.covers (set_index, glyph_id);
297 default:return false;
301 inline bool sanitize (hb_sanitize_context_t *c) {
303 if (!u.format.sanitize (c)) return false;
305 case 1: return u.format1.sanitize (c);
312 USHORT format; /* Format identifier */
313 MarkGlyphSetsFormat1 format1;
316 DEFINE_SIZE_UNION (2, format);
326 static const hb_tag_t Tag = HB_OT_TAG_GDEF;
329 UnclassifiedGlyph = 0,
336 inline bool has_glyph_classes () const { return glyphClassDef != 0; }
337 inline hb_ot_layout_class_t get_glyph_class (hb_codepoint_t glyph) const
338 { return (this+glyphClassDef).get_class (glyph); }
340 inline bool has_mark_attachment_types () const { return markAttachClassDef != 0; }
341 inline hb_ot_layout_class_t get_mark_attachment_type (hb_codepoint_t glyph) const
342 { return (this+markAttachClassDef).get_class (glyph); }
344 inline bool has_attach_points () const { return attachList != 0; }
345 inline unsigned int get_attach_points (hb_codepoint_t glyph_id,
346 unsigned int start_offset,
347 unsigned int *point_count /* IN/OUT */,
348 unsigned int *point_array /* OUT */) const
349 { return (this+attachList).get_attach_points (glyph_id, start_offset, point_count, point_array); }
351 inline bool has_lig_carets () const { return ligCaretList != 0; }
352 inline unsigned int get_lig_carets (hb_ot_layout_context_t *c,
353 hb_codepoint_t glyph_id,
354 unsigned int start_offset,
355 unsigned int *caret_count /* IN/OUT */,
356 int *caret_array /* OUT */) const
357 { return (this+ligCaretList).get_lig_carets (c, glyph_id, start_offset, caret_count, caret_array); }
359 inline bool has_mark_sets () const { return version >= 0x00010002 && markGlyphSetsDef[0] != 0; }
360 inline bool mark_set_covers (unsigned int set_index, hb_codepoint_t glyph_id) const
361 { return version >= 0x00010002 && (this+markGlyphSetsDef[0]).covers (set_index, glyph_id); }
363 inline bool sanitize (hb_sanitize_context_t *c) {
365 return version.sanitize (c) && likely (version.major == 1)
366 && glyphClassDef.sanitize (c, this)
367 && attachList.sanitize (c, this)
368 && ligCaretList.sanitize (c, this)
369 && markAttachClassDef.sanitize (c, this)
370 && (version < 0x00010002 || markGlyphSetsDef[0].sanitize (c, this));
374 FixedVersion version; /* Version of the GDEF table--currently
377 glyphClassDef; /* Offset to class definition table
378 * for glyph type--from beginning of
379 * GDEF header (may be Null) */
381 attachList; /* Offset to list of glyphs with
382 * attachment points--from beginning
383 * of GDEF header (may be Null) */
384 OffsetTo<LigCaretList>
385 ligCaretList; /* Offset to list of positioning points
386 * for ligature carets--from beginning
387 * of GDEF header (may be Null) */
389 markAttachClassDef; /* Offset to class definition table for
390 * mark attachment type--from beginning
391 * of GDEF header (may be Null) */
392 OffsetTo<MarkGlyphSets>
393 markGlyphSetsDef[VAR]; /* Offset to the table of mark set
394 * definitions--from beginning of GDEF
395 * header (may be NULL). Introduced
396 * in version 00010002. */
398 DEFINE_SIZE_ARRAY (12, markGlyphSetsDef);
404 #endif /* HB_OT_LAYOUT_GDEF_PRIVATE_HH */