Minor cleanup, add LIKELY and UNLIKELY annotations
[profile/ivi/org.tizen.video-player.git] / src / hb-ot-layout-gdef-private.h
1 #ifndef HB_OT_LAYOUT_GDEF_PRIVATE_H
2 #define HB_OT_LAYOUT_GDEF_PRIVATE_H
3
4 #include "hb-ot-layout-open-private.h"
5
6
7 #define DEFINE_INDIRECT_GLYPH_ARRAY_LOOKUP(Type, name) \
8   inline const Type& name (uint16_t glyph_id) { \
9     const Coverage &c = get_coverage (); \
10     int c_index = c.get_coverage (glyph_id); \
11     return (*this)[c_index]; \
12   }
13
14
15 struct GlyphClassDef : ClassDef {
16   static const uint16_t BaseGlyph               = 0x0001u;
17   static const uint16_t LigatureGlyph           = 0x0002u;
18   static const uint16_t MarkGlyph               = 0x0003u;
19   static const uint16_t ComponentGlyph          = 0x0004u;
20 };
21
22 /*
23  * Attachment List Table
24  */
25
26 struct AttachPoint {
27   /* countour point indices, in increasing numerical order */
28   DEFINE_ARRAY_TYPE (USHORT, pointIndex, pointCount);
29
30   private:
31   USHORT        pointCount;             /* Number of attachment points on
32                                          * this glyph */
33   USHORT        pointIndex[];           /* Array of contour point indices--in
34                                          * increasing numerical order */
35 };
36 DEFINE_NULL_ASSERT_SIZE (AttachPoint, 2);
37
38 struct AttachList {
39   /* const AttachPoint& get_attach_points (uint16_t glyph_id); */
40   DEFINE_INDIRECT_GLYPH_ARRAY_LOOKUP (AttachPoint, get_attach_points);
41
42   private:
43   /* AttachPoint tables, in Coverage Index order */
44   DEFINE_OFFSET_ARRAY_TYPE (AttachPoint, attachPoint, glyphCount);
45   DEFINE_ACCESSOR (Coverage, get_coverage, coverage);
46
47  private:
48   Offset        coverage;               /* Offset to Coverage table -- from
49                                          * beginning of AttachList table */
50   USHORT        glyphCount;             /* Number of glyphs with attachment
51                                          * points */
52   Offset        attachPoint[];          /* Array of offsets to AttachPoint
53                                          * tables--from beginning of AttachList
54                                          * table--in Coverage Index order */
55 };
56 DEFINE_NULL_ASSERT_SIZE (AttachList, 4);
57
58 /*
59  * Ligature Caret Table
60  */
61
62 struct CaretValueFormat1 {
63
64   inline int get_caret_value (int ppem) const {
65     return /* TODO garbage */ coordinate / ppem;
66   }
67
68   private:
69   USHORT        caretValueFormat;       /* Format identifier--format = 1 */
70   SHORT         coordinate;             /* X or Y value, in design units */
71 };
72 ASSERT_SIZE (CaretValueFormat1, 4);
73
74 struct CaretValueFormat2 {
75
76   inline int get_caret_value (int ppem) const {
77     return /* TODO garbage */ 0 / ppem;
78   }
79
80   private:
81   USHORT        caretValueFormat;       /* Format identifier--format = 2 */
82   USHORT        caretValuePoint;        /* Contour point index on glyph */
83 };
84 ASSERT_SIZE (CaretValueFormat2, 4);
85
86 struct CaretValueFormat3 {
87
88   inline const Device& get_device (void) const {
89     if (HB_UNLIKELY (!deviceTable)) return NullDevice;
90     return *(const Device*)((const char*)this + deviceTable);
91   }
92
93   inline int get_caret_value (int ppem) const {
94     return /* TODO garbage */ (coordinate + get_device().get_delta (ppem)) / ppem;
95   }
96
97   private:
98   USHORT        caretValueFormat;       /* Format identifier--format = 3 */
99   SHORT         coordinate;             /* X or Y value, in design units */
100   Offset        deviceTable;            /* Offset to Device table for X or Y
101                                          * value--from beginning of CaretValue
102                                          * table */
103 };
104 ASSERT_SIZE (CaretValueFormat3, 6);
105
106 struct CaretValue {
107   DEFINE_NON_INSTANTIABLE(CaretValue);
108
109   inline unsigned int get_size (void) const {
110     switch (u.caretValueFormat) {
111     case 1: return sizeof (u.format1);
112     case 2: return sizeof (u.format2);
113     case 3: return sizeof (u.format3);
114     default:return sizeof (u.caretValueFormat);
115     }
116   }
117
118   /* XXX  we need access to a load-contour-point vfunc here */
119   inline int get_caret_value (int ppem) const {
120     switch (u.caretValueFormat) {
121     case 1: return u.format1.get_caret_value(ppem);
122     case 2: return u.format2.get_caret_value(ppem);
123     case 3: return u.format3.get_caret_value(ppem);
124     default:return 0;
125     }
126   }
127
128   private:
129   union {
130   USHORT        caretValueFormat;       /* Format identifier */
131   CaretValueFormat1     format1;
132   CaretValueFormat2     format2;
133   CaretValueFormat3     format3;
134   /* FIXME old HarfBuzz code has a format 4 here! */
135   } u;
136 };
137 DEFINE_NULL (CaretValue, 2);
138
139 struct LigGlyph {
140   /* Caret value tables, in increasing coordinate order */
141   DEFINE_OFFSET_ARRAY_TYPE (CaretValue, caretValue, caretCount);
142   /* TODO */
143
144   private:
145   USHORT        caretCount;             /* Number of CaretValues for this
146                                          * ligature (components - 1) */
147   Offset        caretValue[];           /* Array of offsets to CaretValue
148                                          * tables--from beginning of LigGlyph
149                                          * table--in increasing coordinate
150                                          * order */
151 };
152 DEFINE_NULL_ASSERT_SIZE (LigGlyph, 2);
153
154 struct LigCaretList {
155   /* const LigGlyph& get_lig_glyph (uint16_t glyph_id); */
156   DEFINE_INDIRECT_GLYPH_ARRAY_LOOKUP (LigGlyph, get_lig_glyph);
157
158   private:
159   /* AttachPoint tables, in Coverage Index order */
160   DEFINE_OFFSET_ARRAY_TYPE (LigGlyph, ligGlyph, ligGlyphCount);
161   DEFINE_ACCESSOR (Coverage, get_coverage, coverage);
162
163   private:
164   Offset        coverage;               /* Offset to Coverage table--from
165                                          * beginning of LigCaretList table */
166   USHORT        ligGlyphCount;          /* Number of ligature glyphs */
167   Offset        ligGlyph[];             /* Array of offsets to LigGlyph
168                                          * tables--from beginning of
169                                          * LigCaretList table--in Coverage
170                                          * Index order */
171 };
172 DEFINE_NULL_ASSERT_SIZE (LigCaretList, 4);
173
174 /*
175  * GDEF Header
176  */
177
178 struct GDEFHeader {
179   static const hb_tag_t GDEFTag         = HB_TAG ('G','D','E','F');
180
181   STATIC_DEFINE_GET_FOR_DATA (GDEFHeader);
182
183   DEFINE_ACCESSOR (ClassDef, get_glyph_class_def, glyphClassDef);
184   DEFINE_ACCESSOR (AttachList, get_attach_list, attachList);
185   DEFINE_ACCESSOR (LigCaretList, get_lig_caret_list, ligCaretList);
186   DEFINE_ACCESSOR (ClassDef, get_mark_attach_class_def, markAttachClassDef);
187
188   /* Returns 0 if not found. */
189   inline int get_glyph_class (uint16_t glyph_id) const {
190     const ClassDef &class_def = get_glyph_class_def ();
191     return class_def.get_class (glyph_id);
192   }
193
194   /* Returns 0 if not found. */
195   inline int get_mark_attachment_type (uint16_t glyph_id) const {
196     const ClassDef &class_def = get_mark_attach_class_def ();
197     return class_def.get_class (glyph_id);
198   }
199
200   /* TODO get_glyph_property */
201
202   /* TODO get_attach and get_lig_caret */
203
204   private:
205   Fixed         version;                /* Version of the GDEF table--initially
206                                          * 0x00010000 */
207   Offset        glyphClassDef;          /* Offset to class definition table
208                                          * for glyph type--from beginning of
209                                          * GDEF header (may be Null) */
210   Offset        attachList;             /* Offset to list of glyphs with
211                                          * attachment points--from beginning
212                                          * of GDEF header (may be Null) */
213   Offset        ligCaretList;           /* Offset to list of positioning points
214                                          * for ligature carets--from beginning
215                                          * of GDEF header (may be Null) */
216   Offset        markAttachClassDef;     /* Offset to class definition table for
217                                          * mark attachment type--from beginning
218                                          * of GDEF header (may be Null) */
219 };
220 DEFINE_NULL_ASSERT_SIZE (GDEFHeader, 12);
221
222 #endif /* HB_OT_LAYOUT_GDEF_PRIVATE_H */