Give it a start at GSUB
[profile/ivi/org.tizen.video-player.git] / src / hb-ot-layout-gdef-private.h
1 /*
2  * Copyright (C) 2007,2008  Red Hat, Inc.
3  *
4  *  This is part of HarfBuzz, an OpenType Layout engine library.
5  *
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.
11  *
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
16  * DAMAGE.
17  *
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.
23  *
24  * Red Hat Author(s): Behdad Esfahbod
25  */
26
27 #ifndef HB_OT_LAYOUT_GDEF_PRIVATE_H
28 #define HB_OT_LAYOUT_GDEF_PRIVATE_H
29
30 #include "hb-ot-layout-private.h"
31
32 #include "hb-ot-layout-open-private.h"
33
34
35 #define DEFINE_INDIRECT_GLYPH_ARRAY_LOOKUP(Type, name) \
36   inline const Type& name (hb_codepoint_t glyph) { \
37     const Coverage &c = get_coverage (); \
38     hb_ot_layout_coverage_t c_index = c.get_coverage (glyph); \
39     return (*this)[c_index]; \
40   }
41
42
43 struct GlyphClassDef : ClassDef {
44   static const unsigned int BaseGlyph           = 0x0001u;
45   static const unsigned int LigatureGlyph       = 0x0002u;
46   static const unsigned int MarkGlyph           = 0x0003u;
47   static const unsigned int ComponentGlyph      = 0x0004u;
48 };
49
50 /*
51  * Attachment List Table
52  */
53
54 struct AttachPoint {
55
56   friend struct AttachList;
57
58   private:
59   /* countour point indices, in increasing numerical order */
60   DEFINE_ARRAY_TYPE (USHORT, pointIndex, pointCount);
61
62   private:
63   USHORT        pointCount;             /* Number of attachment points on
64                                          * this glyph */
65   USHORT        pointIndex[];           /* Array of contour point indices--in
66                                          * increasing numerical order */
67 };
68 DEFINE_NULL_ASSERT_SIZE (AttachPoint, 2);
69
70 struct AttachList {
71
72   friend struct GDEF;
73
74   private:
75   /* const AttachPoint& get_attach_points (hb_codepoint_t glyph); */
76   DEFINE_INDIRECT_GLYPH_ARRAY_LOOKUP (AttachPoint, get_attach_points);
77
78   private:
79   /* AttachPoint tables, in Coverage Index order */
80   DEFINE_OFFSET_ARRAY_TYPE (AttachPoint, attachPoint, glyphCount);
81   DEFINE_GET_ACCESSOR (Coverage, coverage, coverage);
82
83  private:
84   Offset        coverage;               /* Offset to Coverage table -- from
85                                          * beginning of AttachList table */
86   USHORT        glyphCount;             /* Number of glyphs with attachment
87                                          * points */
88   Offset        attachPoint[];          /* Array of offsets to AttachPoint
89                                          * tables--from beginning of AttachList
90                                          * table--in Coverage Index order */
91 };
92 DEFINE_NULL_ASSERT_SIZE (AttachList, 4);
93
94 /*
95  * Ligature Caret Table
96  */
97
98 struct CaretValueFormat1 {
99
100   friend struct CaretValue;
101
102   private:
103   inline int get_caret_value (int ppem) const {
104     return /* TODO garbage */ coordinate / ppem;
105   }
106
107   private:
108   USHORT        caretValueFormat;       /* Format identifier--format = 1 */
109   SHORT         coordinate;             /* X or Y value, in design units */
110 };
111 ASSERT_SIZE (CaretValueFormat1, 4);
112
113 struct CaretValueFormat2 {
114
115   friend struct CaretValue;
116
117   private:
118   inline int get_caret_value (int ppem) const {
119     return /* TODO garbage */ 0 / ppem;
120   }
121
122   private:
123   USHORT        caretValueFormat;       /* Format identifier--format = 2 */
124   USHORT        caretValuePoint;        /* Contour point index on glyph */
125 };
126 ASSERT_SIZE (CaretValueFormat2, 4);
127
128 struct CaretValueFormat3 {
129
130   friend struct CaretValue;
131
132   private:
133   inline const Device& get_device (void) const {
134     if (HB_UNLIKELY (!deviceTable)) return NullDevice;
135     return *(const Device*)((const char*)this + deviceTable);
136   }
137
138   inline int get_caret_value (int ppem) const {
139     return /* TODO garbage */ (coordinate + get_device().get_delta (ppem)) / ppem;
140   }
141
142   private:
143   USHORT        caretValueFormat;       /* Format identifier--format = 3 */
144   SHORT         coordinate;             /* X or Y value, in design units */
145   Offset        deviceTable;            /* Offset to Device table for X or Y
146                                          * value--from beginning of CaretValue
147                                          * table */
148 };
149 ASSERT_SIZE (CaretValueFormat3, 6);
150
151 struct CaretValue {
152   DEFINE_NON_INSTANTIABLE(CaretValue);
153
154   unsigned int get_size (void) const {
155     switch (u.caretValueFormat) {
156     case 1: return sizeof (u.format1);
157     case 2: return sizeof (u.format2);
158     case 3: return sizeof (u.format3);
159     default:return sizeof (u.caretValueFormat);
160     }
161   }
162
163   /* XXX  we need access to a load-contour-point vfunc here */
164   int get_caret_value (int ppem) const {
165     switch (u.caretValueFormat) {
166     case 1: return u.format1.get_caret_value(ppem);
167     case 2: return u.format2.get_caret_value(ppem);
168     case 3: return u.format3.get_caret_value(ppem);
169     default:return 0;
170     }
171   }
172
173   private:
174   union {
175   USHORT        caretValueFormat;       /* Format identifier */
176   CaretValueFormat1     format1;
177   CaretValueFormat2     format2;
178   CaretValueFormat3     format3;
179   /* FIXME old HarfBuzz code has a format 4 here! */
180   } u;
181 };
182 DEFINE_NULL (CaretValue, 2);
183
184 struct LigGlyph {
185
186   friend struct LigCaretList;
187
188   private:
189   /* Caret value tables, in increasing coordinate order */
190   DEFINE_OFFSET_ARRAY_TYPE (CaretValue, caretValue, caretCount);
191   /* TODO */
192
193   private:
194   USHORT        caretCount;             /* Number of CaretValues for this
195                                          * ligature (components - 1) */
196   Offset        caretValue[];           /* Array of offsets to CaretValue
197                                          * tables--from beginning of LigGlyph
198                                          * table--in increasing coordinate
199                                          * order */
200 };
201 DEFINE_NULL_ASSERT_SIZE (LigGlyph, 2);
202
203 struct LigCaretList {
204
205   friend struct GDEF;
206
207   private:
208   /* const LigGlyph& get_lig_glyph (hb_codepoint_t glyph); */
209   DEFINE_INDIRECT_GLYPH_ARRAY_LOOKUP (LigGlyph, get_lig_glyph);
210
211   private:
212   /* AttachPoint tables, in Coverage Index order */
213   DEFINE_OFFSET_ARRAY_TYPE (LigGlyph, ligGlyph, ligGlyphCount);
214   DEFINE_GET_ACCESSOR (Coverage, coverage, coverage);
215
216   private:
217   Offset        coverage;               /* Offset to Coverage table--from
218                                          * beginning of LigCaretList table */
219   USHORT        ligGlyphCount;          /* Number of ligature glyphs */
220   Offset        ligGlyph[];             /* Array of offsets to LigGlyph
221                                          * tables--from beginning of
222                                          * LigCaretList table--in Coverage
223                                          * Index order */
224 };
225 DEFINE_NULL_ASSERT_SIZE (LigCaretList, 4);
226
227 /*
228  * GDEF
229  */
230
231 struct GDEF {
232   static const hb_tag_t Tag             = HB_TAG ('G','D','E','F');
233
234   static const hb_ot_layout_class_t UnclassifiedGlyph   = 0;
235   static const hb_ot_layout_class_t BaseGlyph           = 1;
236   static const hb_ot_layout_class_t LigatureGlyph       = 2;
237   static const hb_ot_layout_class_t MarkGlyph           = 3;
238   static const hb_ot_layout_class_t ComponentGlyph      = 4;
239
240   STATIC_DEFINE_GET_FOR_DATA (GDEF);
241   /* XXX check version here? */
242
243   DEFINE_GET_HAS_ACCESSOR (ClassDef, glyph_classes, glyphClassDef);
244   DEFINE_GET_HAS_ACCESSOR (AttachList, attach_list, attachList);
245   DEFINE_GET_HAS_ACCESSOR (LigCaretList, lig_caret_list, ligCaretList);
246   DEFINE_GET_HAS_ACCESSOR (ClassDef, mark_attachment_types, markAttachClassDef);
247
248   inline hb_ot_layout_class_t get_glyph_class (hb_codepoint_t glyph) const {
249     return get_glyph_classes ().get_class (glyph);
250   }
251
252   inline hb_ot_layout_class_t get_mark_attachment_type (hb_codepoint_t glyph) const {
253     return get_mark_attachment_types ().get_class (glyph);
254   }
255
256   /* TODO get_attach and get_lig_caret */
257
258   private:
259   Fixed         version;                /* Version of the GDEF table--initially
260                                          * 0x00010000 */
261   Offset        glyphClassDef;          /* Offset to class definition table
262                                          * for glyph type--from beginning of
263                                          * GDEF header (may be Null) */
264   Offset        attachList;             /* Offset to list of glyphs with
265                                          * attachment points--from beginning
266                                          * of GDEF header (may be Null) */
267   Offset        ligCaretList;           /* Offset to list of positioning points
268                                          * for ligature carets--from beginning
269                                          * of GDEF header (may be Null) */
270   Offset        markAttachClassDef;     /* Offset to class definition table for
271                                          * mark attachment type--from beginning
272                                          * of GDEF header (may be Null) */
273 };
274 DEFINE_NULL_ASSERT_SIZE (GDEF, 12);
275
276 #endif /* HB_OT_LAYOUT_GDEF_PRIVATE_H */