2 * Copyright (C) 2007,2008,2009 Red Hat, Inc.
4 * This is part of HarfBuzz, an OpenType Layout engine 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 bool get_attach_points (hb_codepoint_t glyph_id,
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)
55 const AttachPoint &points = this+attachPoint[index];
57 unsigned int count = MIN (points.len, *point_count);
58 for (unsigned int i = 0; i < count; i++)
59 point_array[i] = points[i];
61 *point_count = points.len;
66 inline bool sanitize (SANITIZE_ARG_DEF) {
68 return SANITIZE_THIS2 (coverage, attachPoint);
73 coverage; /* Offset to Coverage table -- from
74 * beginning of AttachList table */
75 OffsetArrayOf<AttachPoint>
76 attachPoint; /* Array of AttachPoint tables
77 * in Coverage Index order */
79 ASSERT_SIZE (AttachList, 4);
82 * Ligature Caret Table
85 struct CaretValueFormat1
87 friend struct CaretValue;
90 inline int get_caret_value (hb_ot_layout_context_t *context, hb_codepoint_t glyph_id) const
93 return context->font->x_scale * coordinate / 0x10000;
96 inline bool sanitize (SANITIZE_ARG_DEF) {
98 return SANITIZE_SELF ();
102 USHORT caretValueFormat; /* Format identifier--format = 1 */
103 SHORT coordinate; /* X or Y value, in design units */
105 ASSERT_SIZE (CaretValueFormat1, 4);
107 struct CaretValueFormat2
109 friend struct CaretValue;
112 inline int get_caret_value (hb_ot_layout_context_t *context, hb_codepoint_t glyph_id) const
114 return /* TODO contour point */ 0;
117 inline bool sanitize (SANITIZE_ARG_DEF) {
119 return SANITIZE_SELF ();
123 USHORT caretValueFormat; /* Format identifier--format = 2 */
124 USHORT caretValuePoint; /* Contour point index on glyph */
126 ASSERT_SIZE (CaretValueFormat2, 4);
128 struct CaretValueFormat3
130 friend struct CaretValue;
132 inline int get_caret_value (hb_ot_layout_context_t *context, hb_codepoint_t glyph_id) const
135 return context->font->x_scale * coordinate / 0x10000 +
136 ((this+deviceTable).get_delta (context->font->x_ppem) << 6);
139 inline bool sanitize (SANITIZE_ARG_DEF) {
141 return SANITIZE_SELF () && SANITIZE_THIS (deviceTable);
145 USHORT caretValueFormat; /* Format identifier--format = 3 */
146 SHORT coordinate; /* X or Y value, in design units */
148 deviceTable; /* Offset to Device table for X or Y
149 * value--from beginning of CaretValue
152 ASSERT_SIZE (CaretValueFormat3, 6);
156 inline int get_caret_value (hb_ot_layout_context_t *context, hb_codepoint_t glyph_id) const
159 case 1: return u.format1->get_caret_value (context, glyph_id);
160 case 2: return u.format2->get_caret_value (context, glyph_id);
161 case 3: return u.format3->get_caret_value (context, glyph_id);
166 inline bool sanitize (SANITIZE_ARG_DEF) {
168 if (!SANITIZE (u.format)) return false;
170 case 1: return u.format1->sanitize (SANITIZE_ARG);
171 case 2: return u.format2->sanitize (SANITIZE_ARG);
172 case 3: return u.format3->sanitize (SANITIZE_ARG);
179 USHORT format; /* Format identifier */
180 CaretValueFormat1 format1[];
181 CaretValueFormat2 format2[];
182 CaretValueFormat3 format3[];
185 ASSERT_SIZE (CaretValue, 2);
189 inline void get_lig_carets (hb_ot_layout_context_t *context,
190 hb_codepoint_t glyph_id,
191 unsigned int *caret_count /* IN/OUT */,
192 int *caret_array /* OUT */) const
195 unsigned int count = MIN (carets.len, *caret_count);
196 for (unsigned int i = 0; i < count; i++)
197 caret_array[i] = (this+carets[i]).get_caret_value (context, glyph_id);
199 *caret_count = carets.len;
202 inline bool sanitize (SANITIZE_ARG_DEF) {
204 return SANITIZE_THIS (carets);
208 OffsetArrayOf<CaretValue>
209 carets; /* Offset array of CaretValue tables
210 * --from beginning of LigGlyph table
211 * --in increasing coordinate order */
213 ASSERT_SIZE (LigGlyph, 2);
217 inline bool get_lig_carets (hb_ot_layout_context_t *context,
218 hb_codepoint_t glyph_id,
219 unsigned int *caret_count /* IN/OUT */,
220 int *caret_array /* OUT */) const
222 unsigned int index = (this+coverage) (glyph_id);
223 if (index == NOT_COVERED)
228 const LigGlyph &lig_glyph = this+ligGlyph[index];
229 lig_glyph.get_lig_carets (context, glyph_id, caret_count, caret_array);
233 inline bool sanitize (SANITIZE_ARG_DEF) {
235 return SANITIZE_THIS2 (coverage, ligGlyph);
240 coverage; /* Offset to Coverage table--from
241 * beginning of LigCaretList table */
242 OffsetArrayOf<LigGlyph>
243 ligGlyph; /* Array of LigGlyph tables
244 * in Coverage Index order */
246 ASSERT_SIZE (LigCaretList, 4);
249 struct MarkGlyphSetsFormat1
251 inline bool covers (unsigned int set_index, hb_codepoint_t glyph_id) const
252 { return (this+coverage[set_index]).get_coverage (glyph_id) != NOT_COVERED; }
254 inline bool sanitize (SANITIZE_ARG_DEF) {
256 return SANITIZE_THIS (coverage);
260 USHORT format; /* Format identifier--format = 1 */
261 LongOffsetArrayOf<Coverage>
262 coverage; /* Array of long offsets to mark set
265 ASSERT_SIZE (MarkGlyphSetsFormat1, 4);
269 inline bool covers (unsigned int set_index, hb_codepoint_t glyph_id) const
272 case 1: return u.format1->covers (set_index, glyph_id);
273 default:return false;
277 inline bool sanitize (SANITIZE_ARG_DEF) {
279 if (!SANITIZE (u.format)) return false;
281 case 1: return u.format1->sanitize (SANITIZE_ARG);
288 USHORT format; /* Format identifier */
289 MarkGlyphSetsFormat1 format1[];
292 ASSERT_SIZE (MarkGlyphSets, 2);
301 static const hb_tag_t Tag = HB_OT_TAG_GDEF;
304 UnclassifiedGlyph = 0,
311 STATIC_DEFINE_GET_FOR_DATA_CHECK_MAJOR_VERSION (GDEF, 1, 1);
313 inline bool has_glyph_classes () const { return glyphClassDef != 0; }
314 inline hb_ot_layout_class_t get_glyph_class (hb_codepoint_t glyph) const
315 { return (this+glyphClassDef).get_class (glyph); }
317 inline bool has_mark_attachment_types () const { return markAttachClassDef != 0; }
318 inline hb_ot_layout_class_t get_mark_attachment_type (hb_codepoint_t glyph) const
319 { return (this+markAttachClassDef).get_class (glyph); }
321 inline bool has_attach_points () const { return attachList != 0; }
322 inline bool get_attach_points (hb_codepoint_t glyph_id,
323 unsigned int *point_count /* IN/OUT */,
324 unsigned int *point_array /* OUT */) const
325 { return (this+attachList).get_attach_points (glyph_id, point_count, point_array); }
327 inline bool has_lig_carets () const { return ligCaretList != 0; }
328 inline bool get_lig_carets (hb_ot_layout_context_t *context,
329 hb_codepoint_t glyph_id,
330 unsigned int *caret_count /* IN/OUT */,
331 int *caret_array /* OUT */) const
332 { return (this+ligCaretList).get_lig_carets (context, glyph_id, caret_count, caret_array); }
334 inline bool has_mark_sets () const { return version >= 0x00010002 && markGlyphSetsDef[0] != 0; }
335 inline bool mark_set_covers (unsigned int set_index, hb_codepoint_t glyph_id) const
336 { return version >= 0x00010002 && (this+markGlyphSetsDef[0]).covers (set_index, glyph_id); }
338 inline bool sanitize (SANITIZE_ARG_DEF) {
340 if (!SANITIZE (version)) return false;
341 if (version.major != 1) return true;
342 return SANITIZE_THIS2 (glyphClassDef, attachList) &&
343 SANITIZE_THIS2 (ligCaretList, markAttachClassDef) &&
344 (version < 0x00010002 || SANITIZE_THIS (markGlyphSetsDef[0]));
348 FixedVersion version; /* Version of the GDEF table--currently
351 glyphClassDef; /* Offset to class definition table
352 * for glyph type--from beginning of
353 * GDEF header (may be Null) */
355 attachList; /* Offset to list of glyphs with
356 * attachment points--from beginning
357 * of GDEF header (may be Null) */
358 OffsetTo<LigCaretList>
359 ligCaretList; /* Offset to list of positioning points
360 * for ligature carets--from beginning
361 * of GDEF header (may be Null) */
363 markAttachClassDef; /* Offset to class definition table for
364 * mark attachment type--from beginning
365 * of GDEF header (may be Null) */
366 OffsetTo<MarkGlyphSets>
367 markGlyphSetsDef[0]; /* Offset to the table of mark set
368 * definitions--from beginning of GDEF
369 * header (may be NULL). Introduced
370 * in version 00010002. */
372 ASSERT_SIZE (GDEF, 12);
375 #endif /* HB_OT_LAYOUT_GDEF_PRIVATE_HH */