Minor renaming
[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-private.h"
31 #include "hb-ot-layout.h"
32
33 #include "hb-ot-layout-open-private.h"
34
35
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]; \
41   }
42
43
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;
49 };
50
51 /*
52  * Attachment List Table
53  */
54
55 struct AttachPoint {
56   /* countour point indices, in increasing numerical order */
57   DEFINE_ARRAY_TYPE (USHORT, pointIndex, pointCount);
58
59   private:
60   USHORT        pointCount;             /* Number of attachment points on
61                                          * this glyph */
62   USHORT        pointIndex[];           /* Array of contour point indices--in
63                                          * increasing numerical order */
64 };
65 DEFINE_NULL_ASSERT_SIZE (AttachPoint, 2);
66
67 struct AttachList {
68   /* const AttachPoint& get_attach_points (uint16_t glyph_id); */
69   DEFINE_INDIRECT_GLYPH_ARRAY_LOOKUP (AttachPoint, get_attach_points);
70
71   private:
72   /* AttachPoint tables, in Coverage Index order */
73   DEFINE_OFFSET_ARRAY_TYPE (AttachPoint, attachPoint, glyphCount);
74   DEFINE_ACCESSOR (Coverage, get_coverage, coverage);
75
76  private:
77   Offset        coverage;               /* Offset to Coverage table -- from
78                                          * beginning of AttachList table */
79   USHORT        glyphCount;             /* Number of glyphs with attachment
80                                          * points */
81   Offset        attachPoint[];          /* Array of offsets to AttachPoint
82                                          * tables--from beginning of AttachList
83                                          * table--in Coverage Index order */
84 };
85 DEFINE_NULL_ASSERT_SIZE (AttachList, 4);
86
87 /*
88  * Ligature Caret Table
89  */
90
91 struct CaretValueFormat1 {
92
93   inline int get_caret_value (int ppem) const {
94     return /* TODO garbage */ coordinate / ppem;
95   }
96
97   private:
98   USHORT        caretValueFormat;       /* Format identifier--format = 1 */
99   SHORT         coordinate;             /* X or Y value, in design units */
100 };
101 ASSERT_SIZE (CaretValueFormat1, 4);
102
103 struct CaretValueFormat2 {
104
105   inline int get_caret_value (int ppem) const {
106     return /* TODO garbage */ 0 / ppem;
107   }
108
109   private:
110   USHORT        caretValueFormat;       /* Format identifier--format = 2 */
111   USHORT        caretValuePoint;        /* Contour point index on glyph */
112 };
113 ASSERT_SIZE (CaretValueFormat2, 4);
114
115 struct CaretValueFormat3 {
116
117   inline const Device& get_device (void) const {
118     if (HB_UNLIKELY (!deviceTable)) return NullDevice;
119     return *(const Device*)((const char*)this + deviceTable);
120   }
121
122   inline int get_caret_value (int ppem) const {
123     return /* TODO garbage */ (coordinate + get_device().get_delta (ppem)) / ppem;
124   }
125
126   private:
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
131                                          * table */
132 };
133 ASSERT_SIZE (CaretValueFormat3, 6);
134
135 struct CaretValue {
136   DEFINE_NON_INSTANTIABLE(CaretValue);
137
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);
144     }
145   }
146
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);
153     default:return 0;
154     }
155   }
156
157   private:
158   union {
159   USHORT        caretValueFormat;       /* Format identifier */
160   CaretValueFormat1     format1;
161   CaretValueFormat2     format2;
162   CaretValueFormat3     format3;
163   /* FIXME old HarfBuzz code has a format 4 here! */
164   } u;
165 };
166 DEFINE_NULL (CaretValue, 2);
167
168 struct LigGlyph {
169   /* Caret value tables, in increasing coordinate order */
170   DEFINE_OFFSET_ARRAY_TYPE (CaretValue, caretValue, caretCount);
171   /* TODO */
172
173   private:
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
179                                          * order */
180 };
181 DEFINE_NULL_ASSERT_SIZE (LigGlyph, 2);
182
183 struct LigCaretList {
184   /* const LigGlyph& get_lig_glyph (uint16_t glyph_id); */
185   DEFINE_INDIRECT_GLYPH_ARRAY_LOOKUP (LigGlyph, get_lig_glyph);
186
187   private:
188   /* AttachPoint tables, in Coverage Index order */
189   DEFINE_OFFSET_ARRAY_TYPE (LigGlyph, ligGlyph, ligGlyphCount);
190   DEFINE_ACCESSOR (Coverage, get_coverage, coverage);
191
192   private:
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
199                                          * Index order */
200 };
201 DEFINE_NULL_ASSERT_SIZE (LigCaretList, 4);
202
203 /*
204  * GDEF
205  */
206
207 struct GDEF {
208   static const hb_tag_t GDEFTag         = HB_TAG ('G','D','E','F');
209
210   STATIC_DEFINE_GET_FOR_DATA (GDEF);
211   /* XXX check version here? */
212
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);
217
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);
222   }
223
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);
228   }
229
230   /* TODO get_glyph_property */
231
232   /* TODO get_attach and get_lig_caret */
233
234   private:
235   Fixed         version;                /* Version of the GDEF table--initially
236                                          * 0x00010000 */
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) */
249 };
250 DEFINE_NULL_ASSERT_SIZE (GDEF, 12);
251
252 #endif /* HB_OT_LAYOUT_GDEF_PRIVATE_H */