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_VAR (4, OffsetTo<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[VAR];
195 CaretValueFormat2 format2[VAR];
196 CaretValueFormat3 format3[VAR];
202 inline unsigned int get_lig_carets (hb_ot_layout_context_t *context,
203 hb_codepoint_t glyph_id,
204 unsigned int start_offset,
205 unsigned int *caret_count /* IN/OUT */,
206 int *caret_array /* OUT */) const
209 const OffsetTo<CaretValue> *array = carets.sub_array (start_offset, caret_count);
210 unsigned int count = *caret_count;
211 for (unsigned int i = 0; i < count; i++)
212 caret_array[i] = (this+array[i]).get_caret_value (context, glyph_id);
218 inline bool sanitize (hb_sanitize_context_t *context) {
220 return carets.sanitize (context, this);
224 OffsetArrayOf<CaretValue>
225 carets; /* Offset array of CaretValue tables
226 * --from beginning of LigGlyph table
227 * --in increasing coordinate order */
229 DEFINE_SIZE_VAR (2, OffsetTo<CaretValue>);
234 inline unsigned int get_lig_carets (hb_ot_layout_context_t *context,
235 hb_codepoint_t glyph_id,
236 unsigned int start_offset,
237 unsigned int *caret_count /* IN/OUT */,
238 int *caret_array /* OUT */) const
240 unsigned int index = (this+coverage) (glyph_id);
241 if (index == NOT_COVERED)
247 const LigGlyph &lig_glyph = this+ligGlyph[index];
248 return lig_glyph.get_lig_carets (context, glyph_id, start_offset, caret_count, caret_array);
251 inline bool sanitize (hb_sanitize_context_t *context) {
253 return coverage.sanitize (context, this)
254 && ligGlyph.sanitize (context, this);
259 coverage; /* Offset to Coverage table--from
260 * beginning of LigCaretList table */
261 OffsetArrayOf<LigGlyph>
262 ligGlyph; /* Array of LigGlyph tables
263 * in Coverage Index order */
265 DEFINE_SIZE_VAR (4, OffsetTo<LigGlyph>);
269 struct MarkGlyphSetsFormat1
271 inline bool covers (unsigned int set_index, hb_codepoint_t glyph_id) const
272 { return (this+coverage[set_index]).get_coverage (glyph_id) != NOT_COVERED; }
274 inline bool sanitize (hb_sanitize_context_t *context) {
276 return coverage.sanitize (context, this);
280 USHORT format; /* Format identifier--format = 1 */
281 LongOffsetArrayOf<Coverage>
282 coverage; /* Array of long offsets to mark set
285 DEFINE_SIZE_VAR (4, LongOffsetTo<Coverage>);
290 inline bool covers (unsigned int set_index, hb_codepoint_t glyph_id) const
293 case 1: return u.format1->covers (set_index, glyph_id);
294 default:return false;
298 inline bool sanitize (hb_sanitize_context_t *context) {
300 if (!u.format.sanitize (context)) return false;
302 case 1: return u.format1->sanitize (context);
309 USHORT format; /* Format identifier */
310 MarkGlyphSetsFormat1 format1[VAR];
321 static const hb_tag_t Tag = HB_OT_TAG_GDEF;
324 UnclassifiedGlyph = 0,
331 inline bool has_glyph_classes () const { return glyphClassDef != 0; }
332 inline hb_ot_layout_class_t get_glyph_class (hb_codepoint_t glyph) const
333 { return (this+glyphClassDef).get_class (glyph); }
335 inline bool has_mark_attachment_types () const { return markAttachClassDef != 0; }
336 inline hb_ot_layout_class_t get_mark_attachment_type (hb_codepoint_t glyph) const
337 { return (this+markAttachClassDef).get_class (glyph); }
339 inline bool has_attach_points () const { return attachList != 0; }
340 inline unsigned int get_attach_points (hb_codepoint_t glyph_id,
341 unsigned int start_offset,
342 unsigned int *point_count /* IN/OUT */,
343 unsigned int *point_array /* OUT */) const
344 { return (this+attachList).get_attach_points (glyph_id, start_offset, point_count, point_array); }
346 inline bool has_lig_carets () const { return ligCaretList != 0; }
347 inline unsigned int get_lig_carets (hb_ot_layout_context_t *context,
348 hb_codepoint_t glyph_id,
349 unsigned int start_offset,
350 unsigned int *caret_count /* IN/OUT */,
351 int *caret_array /* OUT */) const
352 { return (this+ligCaretList).get_lig_carets (context, glyph_id, start_offset, caret_count, caret_array); }
354 inline bool has_mark_sets () const { return version >= 0x00010002 && markGlyphSetsDef[0] != 0; }
355 inline bool mark_set_covers (unsigned int set_index, hb_codepoint_t glyph_id) const
356 { return version >= 0x00010002 && (this+markGlyphSetsDef[0]).covers (set_index, glyph_id); }
358 inline bool sanitize (hb_sanitize_context_t *context) {
360 return version.sanitize (context) && likely (version.major == 1)
361 && glyphClassDef.sanitize (context, this)
362 && attachList.sanitize (context, this)
363 && ligCaretList.sanitize (context, this)
364 && markAttachClassDef.sanitize (context, this)
365 && (version < 0x00010002 || markGlyphSetsDef[0].sanitize (context, this));
369 FixedVersion version; /* Version of the GDEF table--currently
372 glyphClassDef; /* Offset to class definition table
373 * for glyph type--from beginning of
374 * GDEF header (may be Null) */
376 attachList; /* Offset to list of glyphs with
377 * attachment points--from beginning
378 * of GDEF header (may be Null) */
379 OffsetTo<LigCaretList>
380 ligCaretList; /* Offset to list of positioning points
381 * for ligature carets--from beginning
382 * of GDEF header (may be Null) */
384 markAttachClassDef; /* Offset to class definition table for
385 * mark attachment type--from beginning
386 * of GDEF header (may be Null) */
387 OffsetTo<MarkGlyphSets>
388 markGlyphSetsDef[VAR]; /* Offset to the table of mark set
389 * definitions--from beginning of GDEF
390 * header (may be NULL). Introduced
391 * in version 00010002. */
393 DEFINE_SIZE_VAR (12, OffsetTo<MarkGlyphSets>);
397 #endif /* HB_OT_LAYOUT_GDEF_PRIVATE_HH */