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 */
41 ASSERT_SIZE (AttachPoint, 2);
45 inline unsigned int get_attach_points (hb_codepoint_t glyph_id,
46 unsigned int start_offset,
47 unsigned int *point_count /* IN/OUT */,
48 unsigned int *point_array /* OUT */) const
50 unsigned int index = (this+coverage) (glyph_id);
51 if (index == NOT_COVERED)
58 const AttachPoint &points = this+attachPoint[index];
61 const USHORT *array = points.sub_array (start_offset, point_count);
62 unsigned int count = *point_count;
63 for (unsigned int i = 0; i < count; i++)
64 point_array[i] = array[i];
70 inline bool sanitize (SANITIZE_ARG_DEF) {
72 return SANITIZE_THIS2 (coverage, attachPoint);
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 ASSERT_SIZE (AttachList, 4);
86 * Ligature Caret Table
89 struct CaretValueFormat1
91 friend struct CaretValue;
94 inline int get_caret_value (hb_ot_layout_context_t *context, hb_codepoint_t glyph_id HB_GNUC_UNUSED) const
97 return _hb_16dot16_mul_round (context->font->x_scale, coordinate);
100 inline bool sanitize (SANITIZE_ARG_DEF) {
102 return SANITIZE_SELF ();
106 USHORT caretValueFormat; /* Format identifier--format = 1 */
107 SHORT coordinate; /* X or Y value, in design units */
109 ASSERT_SIZE (CaretValueFormat1, 4);
111 struct CaretValueFormat2
113 friend struct CaretValue;
116 inline int get_caret_value (hb_ot_layout_context_t *context, hb_codepoint_t glyph_id) const
119 hb_position_t x = 0, y = 0;
120 hb_font_get_contour_point (context->font, context->face, caretValuePoint, glyph_id, &x, &y);
124 inline bool sanitize (SANITIZE_ARG_DEF) {
126 return SANITIZE_SELF ();
130 USHORT caretValueFormat; /* Format identifier--format = 2 */
131 USHORT caretValuePoint; /* Contour point index on glyph */
133 ASSERT_SIZE (CaretValueFormat2, 4);
135 struct CaretValueFormat3
137 friend struct CaretValue;
139 inline int get_caret_value (hb_ot_layout_context_t *context, hb_codepoint_t glyph_id HB_GNUC_UNUSED) const
142 return _hb_16dot16_mul_round (context->font->x_scale, coordinate) +
143 ((this+deviceTable).get_delta (context->font->x_ppem) << 6);
146 inline bool sanitize (SANITIZE_ARG_DEF) {
148 return SANITIZE_SELF () && SANITIZE_THIS (deviceTable);
152 USHORT caretValueFormat; /* Format identifier--format = 3 */
153 SHORT coordinate; /* X or Y value, in design units */
155 deviceTable; /* Offset to Device table for X or Y
156 * value--from beginning of CaretValue
159 ASSERT_SIZE (CaretValueFormat3, 6);
163 inline int get_caret_value (hb_ot_layout_context_t *context, hb_codepoint_t glyph_id) const
166 case 1: return u.format1->get_caret_value (context, glyph_id);
167 case 2: return u.format2->get_caret_value (context, glyph_id);
168 case 3: return u.format3->get_caret_value (context, glyph_id);
173 inline bool sanitize (SANITIZE_ARG_DEF) {
175 if (!SANITIZE (u.format)) return false;
177 case 1: return u.format1->sanitize (SANITIZE_ARG);
178 case 2: return u.format2->sanitize (SANITIZE_ARG);
179 case 3: return u.format3->sanitize (SANITIZE_ARG);
186 USHORT format; /* Format identifier */
187 CaretValueFormat1 format1[VAR];
188 CaretValueFormat2 format2[VAR];
189 CaretValueFormat3 format3[VAR];
195 inline unsigned int get_lig_carets (hb_ot_layout_context_t *context,
196 hb_codepoint_t glyph_id,
197 unsigned int start_offset,
198 unsigned int *caret_count /* IN/OUT */,
199 int *caret_array /* OUT */) const
202 const OffsetTo<CaretValue> *array = carets.sub_array (start_offset, caret_count);
203 unsigned int count = *caret_count;
204 for (unsigned int i = 0; i < count; i++)
205 caret_array[i] = (this+array[i]).get_caret_value (context, glyph_id);
211 inline bool sanitize (SANITIZE_ARG_DEF) {
213 return SANITIZE_THIS (carets);
217 OffsetArrayOf<CaretValue>
218 carets; /* Offset array of CaretValue tables
219 * --from beginning of LigGlyph table
220 * --in increasing coordinate order */
222 ASSERT_SIZE (LigGlyph, 2);
226 inline unsigned int get_lig_carets (hb_ot_layout_context_t *context,
227 hb_codepoint_t glyph_id,
228 unsigned int start_offset,
229 unsigned int *caret_count /* IN/OUT */,
230 int *caret_array /* OUT */) const
232 unsigned int index = (this+coverage) (glyph_id);
233 if (index == NOT_COVERED)
239 const LigGlyph &lig_glyph = this+ligGlyph[index];
240 return lig_glyph.get_lig_carets (context, glyph_id, start_offset, caret_count, caret_array);
243 inline bool sanitize (SANITIZE_ARG_DEF) {
245 return SANITIZE_THIS2 (coverage, ligGlyph);
250 coverage; /* Offset to Coverage table--from
251 * beginning of LigCaretList table */
252 OffsetArrayOf<LigGlyph>
253 ligGlyph; /* Array of LigGlyph tables
254 * in Coverage Index order */
256 ASSERT_SIZE (LigCaretList, 4);
259 struct MarkGlyphSetsFormat1
261 inline bool covers (unsigned int set_index, hb_codepoint_t glyph_id) const
262 { return (this+coverage[set_index]).get_coverage (glyph_id) != NOT_COVERED; }
264 inline bool sanitize (SANITIZE_ARG_DEF) {
266 return SANITIZE_THIS (coverage);
270 USHORT format; /* Format identifier--format = 1 */
271 LongOffsetArrayOf<Coverage>
272 coverage; /* Array of long offsets to mark set
275 ASSERT_SIZE (MarkGlyphSetsFormat1, 4);
279 inline bool covers (unsigned int set_index, hb_codepoint_t glyph_id) const
282 case 1: return u.format1->covers (set_index, glyph_id);
283 default:return false;
287 inline bool sanitize (SANITIZE_ARG_DEF) {
289 if (!SANITIZE (u.format)) return false;
291 case 1: return u.format1->sanitize (SANITIZE_ARG);
298 USHORT format; /* Format identifier */
299 MarkGlyphSetsFormat1 format1[VAR];
310 static const hb_tag_t Tag = HB_OT_TAG_GDEF;
313 UnclassifiedGlyph = 0,
320 inline bool has_glyph_classes () const { return glyphClassDef != 0; }
321 inline hb_ot_layout_class_t get_glyph_class (hb_codepoint_t glyph) const
322 { return (this+glyphClassDef).get_class (glyph); }
324 inline bool has_mark_attachment_types () const { return markAttachClassDef != 0; }
325 inline hb_ot_layout_class_t get_mark_attachment_type (hb_codepoint_t glyph) const
326 { return (this+markAttachClassDef).get_class (glyph); }
328 inline bool has_attach_points () const { return attachList != 0; }
329 inline unsigned int get_attach_points (hb_codepoint_t glyph_id,
330 unsigned int start_offset,
331 unsigned int *point_count /* IN/OUT */,
332 unsigned int *point_array /* OUT */) const
333 { return (this+attachList).get_attach_points (glyph_id, start_offset, point_count, point_array); }
335 inline bool has_lig_carets () const { return ligCaretList != 0; }
336 inline unsigned int get_lig_carets (hb_ot_layout_context_t *context,
337 hb_codepoint_t glyph_id,
338 unsigned int start_offset,
339 unsigned int *caret_count /* IN/OUT */,
340 int *caret_array /* OUT */) const
341 { return (this+ligCaretList).get_lig_carets (context, glyph_id, start_offset, caret_count, caret_array); }
343 inline bool has_mark_sets () const { return version >= 0x00010002 && markGlyphSetsDef[0] != 0; }
344 inline bool mark_set_covers (unsigned int set_index, hb_codepoint_t glyph_id) const
345 { return version >= 0x00010002 && (this+markGlyphSetsDef[0]).covers (set_index, glyph_id); }
347 inline bool sanitize (SANITIZE_ARG_DEF) {
349 if (!SANITIZE (version)) return false;
350 if (HB_UNLIKELY (version.major != 1)) return false;
351 return SANITIZE_THIS2 (glyphClassDef, attachList) &&
352 SANITIZE_THIS2 (ligCaretList, markAttachClassDef) &&
353 (version < 0x00010002 || SANITIZE_THIS (markGlyphSetsDef[0]));
357 FixedVersion version; /* Version of the GDEF table--currently
360 glyphClassDef; /* Offset to class definition table
361 * for glyph type--from beginning of
362 * GDEF header (may be Null) */
364 attachList; /* Offset to list of glyphs with
365 * attachment points--from beginning
366 * of GDEF header (may be Null) */
367 OffsetTo<LigCaretList>
368 ligCaretList; /* Offset to list of positioning points
369 * for ligature carets--from beginning
370 * of GDEF header (may be Null) */
372 markAttachClassDef; /* Offset to class definition table for
373 * mark attachment type--from beginning
374 * of GDEF header (may be Null) */
375 OffsetTo<MarkGlyphSets>
376 markGlyphSetsDef[VAR]; /* Offset to the table of mark set
377 * definitions--from beginning of GDEF
378 * header (may be NULL). Introduced
379 * in version 00010002. */
381 ASSERT_SIZE_VAR (GDEF, 12, OffsetTo<MarkGlyphSets>);
384 #endif /* HB_OT_LAYOUT_GDEF_PRIVATE_HH */