2 * Copyright (C) 2007,2008 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_H
28 #define HB_OT_LAYOUT_GDEF_PRIVATE_H
30 #include "hb-private.h"
31 #include "hb-ot-layout.h"
33 #include "hb-ot-layout-open-private.h"
36 #define DEFINE_INDIRECT_GLYPH_ARRAY_LOOKUP(Type, name) \
37 inline const Type& name (uint16_t glyph_id) { \
38 const Coverage &c = get_coverage (); \
39 int c_index = c.get_coverage (glyph_id); \
40 return (*this)[c_index]; \
44 struct GlyphClassDef : ClassDef {
45 static const uint16_t BaseGlyph = 0x0001u;
46 static const uint16_t LigatureGlyph = 0x0002u;
47 static const uint16_t MarkGlyph = 0x0003u;
48 static const uint16_t ComponentGlyph = 0x0004u;
52 * Attachment List Table
56 /* countour point indices, in increasing numerical order */
57 DEFINE_ARRAY_TYPE (USHORT, pointIndex, pointCount);
60 USHORT pointCount; /* Number of attachment points on
62 USHORT pointIndex[]; /* Array of contour point indices--in
63 * increasing numerical order */
65 DEFINE_NULL_ASSERT_SIZE (AttachPoint, 2);
68 /* const AttachPoint& get_attach_points (uint16_t glyph_id); */
69 DEFINE_INDIRECT_GLYPH_ARRAY_LOOKUP (AttachPoint, get_attach_points);
72 /* AttachPoint tables, in Coverage Index order */
73 DEFINE_OFFSET_ARRAY_TYPE (AttachPoint, attachPoint, glyphCount);
74 DEFINE_ACCESSOR (Coverage, get_coverage, coverage);
77 Offset coverage; /* Offset to Coverage table -- from
78 * beginning of AttachList table */
79 USHORT glyphCount; /* Number of glyphs with attachment
81 Offset attachPoint[]; /* Array of offsets to AttachPoint
82 * tables--from beginning of AttachList
83 * table--in Coverage Index order */
85 DEFINE_NULL_ASSERT_SIZE (AttachList, 4);
88 * Ligature Caret Table
91 struct CaretValueFormat1 {
93 inline int get_caret_value (int ppem) const {
94 return /* TODO garbage */ coordinate / ppem;
98 USHORT caretValueFormat; /* Format identifier--format = 1 */
99 SHORT coordinate; /* X or Y value, in design units */
101 ASSERT_SIZE (CaretValueFormat1, 4);
103 struct CaretValueFormat2 {
105 inline int get_caret_value (int ppem) const {
106 return /* TODO garbage */ 0 / ppem;
110 USHORT caretValueFormat; /* Format identifier--format = 2 */
111 USHORT caretValuePoint; /* Contour point index on glyph */
113 ASSERT_SIZE (CaretValueFormat2, 4);
115 struct CaretValueFormat3 {
117 inline const Device& get_device (void) const {
118 if (HB_UNLIKELY (!deviceTable)) return NullDevice;
119 return *(const Device*)((const char*)this + deviceTable);
122 inline int get_caret_value (int ppem) const {
123 return /* TODO garbage */ (coordinate + get_device().get_delta (ppem)) / ppem;
127 USHORT caretValueFormat; /* Format identifier--format = 3 */
128 SHORT coordinate; /* X or Y value, in design units */
129 Offset deviceTable; /* Offset to Device table for X or Y
130 * value--from beginning of CaretValue
133 ASSERT_SIZE (CaretValueFormat3, 6);
136 DEFINE_NON_INSTANTIABLE(CaretValue);
138 inline unsigned int get_size (void) const {
139 switch (u.caretValueFormat) {
140 case 1: return sizeof (u.format1);
141 case 2: return sizeof (u.format2);
142 case 3: return sizeof (u.format3);
143 default:return sizeof (u.caretValueFormat);
147 /* XXX we need access to a load-contour-point vfunc here */
148 inline int get_caret_value (int ppem) const {
149 switch (u.caretValueFormat) {
150 case 1: return u.format1.get_caret_value(ppem);
151 case 2: return u.format2.get_caret_value(ppem);
152 case 3: return u.format3.get_caret_value(ppem);
159 USHORT caretValueFormat; /* Format identifier */
160 CaretValueFormat1 format1;
161 CaretValueFormat2 format2;
162 CaretValueFormat3 format3;
163 /* FIXME old HarfBuzz code has a format 4 here! */
166 DEFINE_NULL (CaretValue, 2);
169 /* Caret value tables, in increasing coordinate order */
170 DEFINE_OFFSET_ARRAY_TYPE (CaretValue, caretValue, caretCount);
174 USHORT caretCount; /* Number of CaretValues for this
175 * ligature (components - 1) */
176 Offset caretValue[]; /* Array of offsets to CaretValue
177 * tables--from beginning of LigGlyph
178 * table--in increasing coordinate
181 DEFINE_NULL_ASSERT_SIZE (LigGlyph, 2);
183 struct LigCaretList {
184 /* const LigGlyph& get_lig_glyph (uint16_t glyph_id); */
185 DEFINE_INDIRECT_GLYPH_ARRAY_LOOKUP (LigGlyph, get_lig_glyph);
188 /* AttachPoint tables, in Coverage Index order */
189 DEFINE_OFFSET_ARRAY_TYPE (LigGlyph, ligGlyph, ligGlyphCount);
190 DEFINE_ACCESSOR (Coverage, get_coverage, coverage);
193 Offset coverage; /* Offset to Coverage table--from
194 * beginning of LigCaretList table */
195 USHORT ligGlyphCount; /* Number of ligature glyphs */
196 Offset ligGlyph[]; /* Array of offsets to LigGlyph
197 * tables--from beginning of
198 * LigCaretList table--in Coverage
201 DEFINE_NULL_ASSERT_SIZE (LigCaretList, 4);
208 static const hb_tag_t GDEFTag = HB_TAG ('G','D','E','F');
210 STATIC_DEFINE_GET_FOR_DATA (GDEF);
211 /* XXX check version here? */
213 DEFINE_ACCESSOR (ClassDef, get_glyph_class_def, glyphClassDef);
214 DEFINE_ACCESSOR (AttachList, get_attach_list, attachList);
215 DEFINE_ACCESSOR (LigCaretList, get_lig_caret_list, ligCaretList);
216 DEFINE_ACCESSOR (ClassDef, get_mark_attach_class_def, markAttachClassDef);
218 /* Returns 0 if not found. */
219 inline int get_glyph_class (uint16_t glyph_id) const {
220 const ClassDef &class_def = get_glyph_class_def ();
221 return class_def.get_class (glyph_id);
224 /* Returns 0 if not found. */
225 inline int get_mark_attachment_type (uint16_t glyph_id) const {
226 const ClassDef &class_def = get_mark_attach_class_def ();
227 return class_def.get_class (glyph_id);
230 /* TODO get_glyph_property */
232 /* TODO get_attach and get_lig_caret */
235 Fixed version; /* Version of the GDEF table--initially
237 Offset glyphClassDef; /* Offset to class definition table
238 * for glyph type--from beginning of
239 * GDEF header (may be Null) */
240 Offset attachList; /* Offset to list of glyphs with
241 * attachment points--from beginning
242 * of GDEF header (may be Null) */
243 Offset ligCaretList; /* Offset to list of positioning points
244 * for ligature carets--from beginning
245 * of GDEF header (may be Null) */
246 Offset markAttachClassDef; /* Offset to class definition table for
247 * mark attachment type--from beginning
248 * of GDEF header (may be Null) */
250 DEFINE_NULL_ASSERT_SIZE (GDEF, 12);
252 #endif /* HB_OT_LAYOUT_GDEF_PRIVATE_H */