blob: 779b2b4300be4116338d69493be97f857efa4467 [file] [log] [blame]
Behdad Esfahbod8dd1c8b2008-01-23 05:00:30 -05001#ifndef HB_OT_LAYOUT_GDEF_PRIVATE_H
2#define HB_OT_LAYOUT_GDEF_PRIVATE_H
Behdad Esfahbod5b3f7702006-12-28 06:42:37 -05003
Behdad Esfahbod8dd1c8b2008-01-23 05:00:30 -05004#include "hb-ot-layout-open-private.h"
Behdad Esfahbod5b3f7702006-12-28 06:42:37 -05005
Behdad Esfahbod4c2556c2007-07-06 11:29:21 -04006struct GlyphClassDef : ClassDef {
7 static const uint16_t BaseGlyph = 0x0001u;
8 static const uint16_t LigatureGlyph = 0x0002u;
9 static const uint16_t MarkGlyph = 0x0003u;
10 static const uint16_t ComponentGlyph = 0x0004u;
11};
12
Behdad Esfahbod1f437e62008-01-23 04:36:40 -050013/*
14 * Attachment List Table
15 */
16
17struct AttachPoint {
18 /* countour point indices, in increasing numerical order */
19 DEFINE_ARRAY_TYPE (USHORT, pointIndex, pointCount);
20
21 private:
22 USHORT pointCount; /* Number of attachment points on
23 * this glyph */
24 USHORT pointIndex[]; /* Array of contour point indices--in
25 * increasing numerical order */
26};
27DEFINE_NULL_ASSERT_SIZE (AttachPoint, 2);
Behdad Esfahbod4c2556c2007-07-06 11:29:21 -040028
29struct AttachList {
Behdad Esfahbod4c2556c2007-07-06 11:29:21 -040030
Behdad Esfahbod1f437e62008-01-23 04:36:40 -050031 inline const AttachPoint* get_attach_points (uint16_t glyph_id) {
32 const Coverage &c = get_coverage ();
33 int c_index = c.get_coverage (glyph_id);
34 return &(*this)[c_index];
Behdad Esfahbod303fe622008-01-23 00:20:48 -050035 }
36
Behdad Esfahbod1f437e62008-01-23 04:36:40 -050037 private:
38 /* AttachPoint tables, in Coverage Index order */
39 DEFINE_OFFSET_ARRAY_TYPE (AttachPoint, attachPoint, glyphCount);
40 DEFINE_ACCESSOR (Coverage, get_coverage, coverage);
Behdad Esfahbod303fe622008-01-23 00:20:48 -050041
42 private:
Behdad Esfahbod4c2556c2007-07-06 11:29:21 -040043 Offset coverage; /* Offset to Coverage table -- from
44 * beginning of AttachList table */
45 USHORT glyphCount; /* Number of glyphs with attachment
46 * points */
47 Offset attachPoint[]; /* Array of offsets to AttachPoint
48 * tables--from beginning of AttachList
49 * table--in Coverage Index order */
50};
Behdad Esfahbod1f437e62008-01-23 04:36:40 -050051DEFINE_NULL_ASSERT_SIZE (AttachList, 4);
Behdad Esfahbod4c2556c2007-07-06 11:29:21 -040052
53/*
54 * Ligature Caret Table
55 */
56
57struct CaretValue;
58
59struct LigCaretList {
Behdad Esfahbod303fe622008-01-23 00:20:48 -050060 /* TODO */
Behdad Esfahbod4c2556c2007-07-06 11:29:21 -040061
Behdad Esfahbod303fe622008-01-23 00:20:48 -050062 private:
Behdad Esfahbod4c2556c2007-07-06 11:29:21 -040063 Offset coverage; /* Offset to Coverage table--from
64 * beginning of LigCaretList table */
65 USHORT ligGlyphCount; /* Number of ligature glyphs */
66 Offset ligGlyph[]; /* Array of offsets to LigGlyph
67 * tables--from beginning of
68 * LigCaretList table--in Coverage
69 * Index order */
70};
Behdad Esfahbod1f437e62008-01-23 04:36:40 -050071DEFINE_NULL_ASSERT_SIZE (LigCaretList, 4);
Behdad Esfahbod4c2556c2007-07-06 11:29:21 -040072
73struct CaretValueFormat1 {
Behdad Esfahbod303fe622008-01-23 00:20:48 -050074
75 inline int get_caret_value (int ppem) const {
76 return /* TODO garbage */ coordinate / ppem;
77 }
78
79 private:
Behdad Esfahbod4c2556c2007-07-06 11:29:21 -040080 USHORT caretValueFormat; /* Format identifier--format = 1 */
81 SHORT coordinate; /* X or Y value, in design units */
Behdad Esfahbod4c2556c2007-07-06 11:29:21 -040082};
Behdad Esfahbod1f437e62008-01-23 04:36:40 -050083DEFINE_NULL_ASSERT_SIZE (CaretValueFormat1, 4);
Behdad Esfahbod4c2556c2007-07-06 11:29:21 -040084
85struct CaretValueFormat2 {
Behdad Esfahbod4c2556c2007-07-06 11:29:21 -040086
87 inline int get_caret_value (int ppem) const {
Behdad Esfahbod303fe622008-01-23 00:20:48 -050088 return /* TODO garbage */ 0 / ppem;
Behdad Esfahbod4c2556c2007-07-06 11:29:21 -040089 }
Behdad Esfahbod303fe622008-01-23 00:20:48 -050090
91 private:
92 USHORT caretValueFormat; /* Format identifier--format = 2 */
93 USHORT caretValuePoint; /* Contour point index on glyph */
Behdad Esfahbod4c2556c2007-07-06 11:29:21 -040094};
Behdad Esfahbod1f437e62008-01-23 04:36:40 -050095DEFINE_NULL_ASSERT_SIZE (CaretValueFormat2, 4);
Behdad Esfahbod4c2556c2007-07-06 11:29:21 -040096
97struct CaretValueFormat3 {
Behdad Esfahbod303fe622008-01-23 00:20:48 -050098
Behdad Esfahbod1f437e62008-01-23 04:36:40 -050099 inline const Device& get_device (void) const {
100 if (!deviceTable) return NullDevice;
101 return *(const Device*)((const char*)this + deviceTable);
Behdad Esfahbod4c2556c2007-07-06 11:29:21 -0400102 }
103
Behdad Esfahbod303fe622008-01-23 00:20:48 -0500104 inline int get_caret_value (int ppem) const {
Behdad Esfahbod1f437e62008-01-23 04:36:40 -0500105 return /* TODO garbage */ (coordinate + get_device().get_delta (ppem)) / ppem;
Behdad Esfahbod303fe622008-01-23 00:20:48 -0500106 }
107
108 private:
Behdad Esfahbod4c2556c2007-07-06 11:29:21 -0400109 USHORT caretValueFormat; /* Format identifier--format = 3 */
110 SHORT coordinate; /* X or Y value, in design units */
111 Offset deviceTable; /* Offset to Device table for X or Y
112 * value--from beginning of CaretValue
113 * table */
Behdad Esfahbod4c2556c2007-07-06 11:29:21 -0400114};
Behdad Esfahbod1f437e62008-01-23 04:36:40 -0500115DEFINE_NULL_ASSERT_SIZE (CaretValueFormat3, 6);
Behdad Esfahbod4c2556c2007-07-06 11:29:21 -0400116
117struct CaretValue {
118 DEFINE_NON_INSTANTIABLE(CaretValue);
119
120 inline unsigned int get_size (void) const {
121 switch (u.caretValueFormat) {
122 case 1: return sizeof (u.format1);
123 case 2: return sizeof (u.format2);
124 case 3: return sizeof (u.format3);
125 default:return sizeof (u.caretValueFormat);
126 }
127 }
128
129 /* XXX we need access to a load-contour-point vfunc here */
130 inline int get_caret_value (int ppem) const {
131 switch (u.caretValueFormat) {
132 case 1: return u.format1.get_caret_value(ppem);
133 case 2: return u.format2.get_caret_value(ppem);
134 case 3: return u.format3.get_caret_value(ppem);
135 default:return 0;
136 }
137 }
138
Behdad Esfahbod303fe622008-01-23 00:20:48 -0500139 private:
Behdad Esfahbod4c2556c2007-07-06 11:29:21 -0400140 union {
141 USHORT caretValueFormat; /* Format identifier */
142 CaretValueFormat1 format1;
143 CaretValueFormat2 format2;
144 CaretValueFormat3 format3;
Behdad Esfahbod303fe622008-01-23 00:20:48 -0500145 /* FIXME old HarfBuzz code has a format 4 here! */
Behdad Esfahbod4c2556c2007-07-06 11:29:21 -0400146 } u;
147};
Behdad Esfahbod1f437e62008-01-23 04:36:40 -0500148DEFINE_NULL (CaretValue, 2);
Behdad Esfahbod5b3f7702006-12-28 06:42:37 -0500149
Behdad Esfahbod1f437e62008-01-23 04:36:40 -0500150struct LigGlyph {
151 /* Caret value tables, in increasing coordinate order */
152 DEFINE_OFFSET_ARRAY_TYPE (CaretValue, caretValue, caretCount);
153 /* TODO */
Behdad Esfahbodb9d76882008-01-23 01:38:10 -0500154
Behdad Esfahbod1f437e62008-01-23 04:36:40 -0500155 private:
156 USHORT caretCount; /* Number of CaretValues for this
157 * ligature (components - 1) */
158 Offset caretValue[]; /* Array of offsets to CaretValue
159 * tables--from beginning of LigGlyph
160 * table--in increasing coordinate
161 * order */
162};
163DEFINE_NULL_ASSERT_SIZE (LigGlyph, 2);
164
165/*
166 * GDEF Header
167 */
Behdad Esfahbodb9d76882008-01-23 01:38:10 -0500168
169struct GDEFHeader {
Behdad Esfahbod600e5eb2008-01-23 02:01:37 -0500170 static const hb_tag_t GDEFTag = HB_TAG ('G','D','E','F');
171
172 STATIC_DEFINE_GET_FOR_DATA (GDEFHeader);
Behdad Esfahbodb9d76882008-01-23 01:38:10 -0500173
174 DEFINE_ACCESSOR (ClassDef, get_glyph_class_def, glyphClassDef);
175 DEFINE_ACCESSOR (AttachList, get_attach_list, attachList);
176 DEFINE_ACCESSOR (LigCaretList, get_lig_caret_list, ligCaretList);
177 DEFINE_ACCESSOR (ClassDef, get_mark_attach_class_def, markAttachClassDef);
178
179 /* Returns 0 if not found. */
180 inline int get_glyph_class (uint16_t glyph_id) const {
Behdad Esfahbod1f437e62008-01-23 04:36:40 -0500181 const ClassDef &class_def = get_glyph_class_def ();
182 return class_def.get_class (glyph_id);
Behdad Esfahbodb9d76882008-01-23 01:38:10 -0500183 }
184
185 /* Returns 0 if not found. */
186 inline int get_mark_attachment_type (uint16_t glyph_id) const {
Behdad Esfahbod1f437e62008-01-23 04:36:40 -0500187 const ClassDef &class_def = get_mark_attach_class_def ();
188 return class_def.get_class (glyph_id);
Behdad Esfahbodb9d76882008-01-23 01:38:10 -0500189 }
190
Behdad Esfahbod1f437e62008-01-23 04:36:40 -0500191 /* TODO get_glyph_property */
192
Behdad Esfahbodb9d76882008-01-23 01:38:10 -0500193 /* TODO get_attach and get_lig_caret */
194
195 private:
196 Fixed version; /* Version of the GDEF table--initially
197 * 0x00010000 */
198 Offset glyphClassDef; /* Offset to class definition table
199 * for glyph type--from beginning of
Behdad Esfahbod1f437e62008-01-23 04:36:40 -0500200 * GDEF header (may be Null) */
Behdad Esfahbodb9d76882008-01-23 01:38:10 -0500201 Offset attachList; /* Offset to list of glyphs with
202 * attachment points--from beginning
Behdad Esfahbod1f437e62008-01-23 04:36:40 -0500203 * of GDEF header (may be Null) */
Behdad Esfahbodb9d76882008-01-23 01:38:10 -0500204 Offset ligCaretList; /* Offset to list of positioning points
205 * for ligature carets--from beginning
Behdad Esfahbod1f437e62008-01-23 04:36:40 -0500206 * of GDEF header (may be Null) */
Behdad Esfahbodb9d76882008-01-23 01:38:10 -0500207 Offset markAttachClassDef; /* Offset to class definition table for
208 * mark attachment type--from beginning
Behdad Esfahbod1f437e62008-01-23 04:36:40 -0500209 * of GDEF header (may be Null) */
Behdad Esfahbodb9d76882008-01-23 01:38:10 -0500210};
Behdad Esfahbod1f437e62008-01-23 04:36:40 -0500211DEFINE_NULL_ASSERT_SIZE (GDEFHeader, 12);
Behdad Esfahbodb9d76882008-01-23 01:38:10 -0500212
Behdad Esfahbod8dd1c8b2008-01-23 05:00:30 -0500213#endif /* HB_OT_LAYOUT_GDEF_PRIVATE_H */