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"
35 struct GlyphClassDef : ClassDef
39 LigatureGlyph = 0x0002u,
41 ComponentGlyph = 0x0004u,
46 * Attachment List Table
49 typedef ArrayOf<USHORT> AttachPoint; /* Array of contour point indices--in
50 * increasing numerical order */
51 ASSERT_SIZE (AttachPoint, 2);
55 inline bool get_attach_points (hb_codepoint_t glyph_id,
56 unsigned int *point_count /* IN/OUT */,
57 unsigned int *point_array /* OUT */) const
59 unsigned int index = (this+coverage) (glyph_id);
60 if (index == NOT_COVERED)
65 const AttachPoint &points = this+attachPoint[index];
67 unsigned int count = MIN (points.len, *point_count);
68 for (unsigned int i = 0; i < count; i++)
69 point_array[i] = points[i];
71 *point_count = points.len;
76 inline bool sanitize (SANITIZE_ARG_DEF) {
78 return SANITIZE_THIS2 (coverage, attachPoint);
83 coverage; /* Offset to Coverage table -- from
84 * beginning of AttachList table */
85 OffsetArrayOf<AttachPoint>
86 attachPoint; /* Array of AttachPoint tables
87 * in Coverage Index order */
89 ASSERT_SIZE (AttachList, 4);
92 * Ligature Caret Table
95 struct CaretValueFormat1
97 friend struct CaretValue;
100 inline int get_caret_value (hb_ot_layout_context_t *context, hb_codepoint_t glyph_id) const
103 return context->font->x_scale * coordinate / 0x10000;
106 inline bool sanitize (SANITIZE_ARG_DEF) {
108 return SANITIZE_SELF ();
112 USHORT caretValueFormat; /* Format identifier--format = 1 */
113 SHORT coordinate; /* X or Y value, in design units */
115 ASSERT_SIZE (CaretValueFormat1, 4);
117 struct CaretValueFormat2
119 friend struct CaretValue;
122 inline int get_caret_value (hb_ot_layout_context_t *context, hb_codepoint_t glyph_id) const
124 return /* TODO contour point */ 0;
127 inline bool sanitize (SANITIZE_ARG_DEF) {
129 return SANITIZE_SELF ();
133 USHORT caretValueFormat; /* Format identifier--format = 2 */
134 USHORT caretValuePoint; /* Contour point index on glyph */
136 ASSERT_SIZE (CaretValueFormat2, 4);
138 struct CaretValueFormat3
140 friend struct CaretValue;
142 inline int get_caret_value (hb_ot_layout_context_t *context, hb_codepoint_t glyph_id) const
145 return context->font->x_scale * coordinate / 0x10000 +
146 ((this+deviceTable).get_delta (context->font->x_ppem) << 6);
149 inline bool sanitize (SANITIZE_ARG_DEF) {
151 return SANITIZE_SELF () && SANITIZE_THIS (deviceTable);
155 USHORT caretValueFormat; /* Format identifier--format = 3 */
156 SHORT coordinate; /* X or Y value, in design units */
158 deviceTable; /* Offset to Device table for X or Y
159 * value--from beginning of CaretValue
162 ASSERT_SIZE (CaretValueFormat3, 6);
166 /* XXX we need access to a load-contour-point vfunc here */
167 int get_caret_value (hb_ot_layout_context_t *context, hb_codepoint_t glyph_id) const
170 case 1: return u.format1->get_caret_value (context, glyph_id);
171 case 2: return u.format2->get_caret_value (context, glyph_id);
172 case 3: return u.format3->get_caret_value (context, glyph_id);
177 inline bool sanitize (SANITIZE_ARG_DEF) {
179 if (!SANITIZE (u.format)) return false;
181 case 1: return u.format1->sanitize (SANITIZE_ARG);
182 case 2: return u.format2->sanitize (SANITIZE_ARG);
183 case 3: return u.format3->sanitize (SANITIZE_ARG);
190 USHORT format; /* Format identifier */
191 CaretValueFormat1 format1[];
192 CaretValueFormat2 format2[];
193 CaretValueFormat3 format3[];
196 ASSERT_SIZE (CaretValue, 2);
200 inline void get_lig_carets (hb_ot_layout_context_t *context,
201 hb_codepoint_t glyph_id,
202 unsigned int *caret_count /* IN/OUT */,
203 int *caret_array /* OUT */) const
206 unsigned int count = MIN (carets.len, *caret_count);
207 for (unsigned int i = 0; i < count; i++)
208 caret_array[i] = (this+carets[i]).get_caret_value (context, glyph_id);
210 *caret_count = carets.len;
213 inline bool sanitize (SANITIZE_ARG_DEF) {
215 return SANITIZE (carets);
219 OffsetArrayOf<CaretValue>
220 carets; /* Offset rrray of CaretValue tables
221 * --from beginning of LigGlyph table
222 * --in increasing coordinate order */
224 ASSERT_SIZE (LigGlyph, 2);
228 inline bool get_lig_carets (hb_ot_layout_context_t *context,
229 hb_codepoint_t glyph_id,
230 unsigned int *caret_count /* IN/OUT */,
231 int *caret_array /* OUT */) const
233 unsigned int index = (this+coverage) (glyph_id);
234 if (index == NOT_COVERED)
239 const LigGlyph &lig_glyph = this+ligGlyph[index];
240 lig_glyph.get_lig_carets (context, glyph_id, caret_count, caret_array);
244 inline bool sanitize (SANITIZE_ARG_DEF) {
246 return SANITIZE_THIS2 (coverage, ligGlyph);
251 coverage; /* Offset to Coverage table--from
252 * beginning of LigCaretList table */
253 OffsetArrayOf<LigGlyph>
254 ligGlyph; /* Array of LigGlyph tables
255 * in Coverage Index order */
257 ASSERT_SIZE (LigCaretList, 4);
260 struct MarkGlyphSetsFormat1
262 inline bool covers (unsigned int set_index, hb_codepoint_t glyph_id) const
263 { return (this+coverage[set_index]).get_coverage (glyph_id) != NOT_COVERED; }
265 inline bool sanitize (SANITIZE_ARG_DEF) {
267 return SANITIZE_THIS (coverage);
271 USHORT format; /* Format identifier--format = 1 */
272 LongOffsetArrayOf<Coverage>
273 coverage; /* Array of long offsets to mark set
276 ASSERT_SIZE (MarkGlyphSetsFormat1, 4);
280 inline bool covers (unsigned int set_index, hb_codepoint_t glyph_id) const
283 case 1: return u.format1->covers (set_index, glyph_id);
284 default:return false;
288 inline bool sanitize (SANITIZE_ARG_DEF) {
290 if (!SANITIZE (u.format)) return false;
292 case 1: return u.format1->sanitize (SANITIZE_ARG);
299 USHORT format; /* Format identifier */
300 MarkGlyphSetsFormat1 format1[];
303 ASSERT_SIZE (MarkGlyphSets, 2);
312 static const hb_tag_t Tag = HB_OT_TAG_GDEF;
315 UnclassifiedGlyph = 0,
322 STATIC_DEFINE_GET_FOR_DATA_CHECK_MAJOR_VERSION (GDEF, 1, 1);
324 inline bool has_glyph_classes () const { return glyphClassDef != 0; }
325 inline hb_ot_layout_class_t get_glyph_class (hb_codepoint_t glyph) const
326 { return (this+glyphClassDef).get_class (glyph); }
328 inline bool has_mark_attachment_types () const { return markAttachClassDef != 0; }
329 inline hb_ot_layout_class_t get_mark_attachment_type (hb_codepoint_t glyph) const
330 { return (this+markAttachClassDef).get_class (glyph); }
332 inline bool has_attach_points () const { return attachList != 0; }
333 inline bool get_attach_points (hb_codepoint_t glyph_id,
334 unsigned int *point_count /* IN/OUT */,
335 unsigned int *point_array /* OUT */) const
336 { return (this+attachList).get_attach_points (glyph_id, point_count, point_array); }
338 inline bool has_lig_carets () const { return ligCaretList != 0; }
339 inline bool get_lig_carets (hb_ot_layout_context_t *context,
340 hb_codepoint_t glyph_id,
341 unsigned int *caret_count /* IN/OUT */,
342 int *caret_array /* OUT */) const
343 { return (this+ligCaretList).get_lig_carets (context, glyph_id, caret_count, caret_array); }
345 inline bool has_mark_sets () const { return version >= 0x00010002 && markGlyphSetsDef[0] != 0; }
346 inline bool mark_set_covers (unsigned int set_index, hb_codepoint_t glyph_id) const
347 { return version >= 0x00010002 && (this+markGlyphSetsDef[0]).covers (set_index, glyph_id); }
349 bool sanitize (SANITIZE_ARG_DEF) {
351 if (!SANITIZE (version)) return false;
352 if (version.major != 1) return true;
353 return SANITIZE_THIS2 (glyphClassDef, attachList) &&
354 SANITIZE_THIS2 (ligCaretList, markAttachClassDef) &&
355 (version < 0x00010002 || SANITIZE_THIS (markGlyphSetsDef[0]));
359 FixedVersion version; /* Version of the GDEF table--currently
362 glyphClassDef; /* Offset to class definition table
363 * for glyph type--from beginning of
364 * GDEF header (may be Null) */
366 attachList; /* Offset to list of glyphs with
367 * attachment points--from beginning
368 * of GDEF header (may be Null) */
369 OffsetTo<LigCaretList>
370 ligCaretList; /* Offset to list of positioning points
371 * for ligature carets--from beginning
372 * of GDEF header (may be Null) */
374 markAttachClassDef; /* Offset to class definition table for
375 * mark attachment type--from beginning
376 * of GDEF header (may be Null) */
377 OffsetTo<MarkGlyphSets>
378 markGlyphSetsDef[0]; /* Offset to the table of mark set
379 * definitions--from beginning of GDEF
380 * header (may be NULL). Introduced
381 * in version 00010002. */
383 ASSERT_SIZE (GDEF, 12);
386 #endif /* HB_OT_LAYOUT_GDEF_PRIVATE_HH */