[HB] Fix mix warnings
[framework/uifw/harfbuzz.git] / src / hb-ot-layout-gdef-private.hh
1 /*
2  * Copyright (C) 2007,2008,2009  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_HH
28 #define HB_OT_LAYOUT_GDEF_PRIVATE_HH
29
30 #include "hb-ot-layout-common-private.hh"
31
32 #include "hb-font-private.h"
33
34
35 struct GlyphClassDef : ClassDef
36 {
37   enum {
38     BaseGlyph           = 0x0001u,
39     LigatureGlyph       = 0x0002u,
40     MarkGlyph           = 0x0003u,
41     ComponentGlyph      = 0x0004u,
42   };
43 };
44
45 /*
46  * Attachment List Table
47  */
48
49 typedef ArrayOf<USHORT> AttachPoint;    /* Array of contour point indices--in
50                                          * increasing numerical order */
51 ASSERT_SIZE (AttachPoint, 2);
52
53 struct AttachList
54 {
55   inline bool get_attach_points (hb_codepoint_t glyph_id,
56                                  unsigned int *point_count /* IN/OUT */,
57                                  unsigned int *point_array /* OUT */) const
58   {
59     unsigned int index = (this+coverage) (glyph_id);
60     if (index == NOT_COVERED)
61     {
62       *point_count = 0;
63       return false;
64     }
65     const AttachPoint &points = this+attachPoint[index];
66
67     unsigned int count = MIN (points.len, *point_count);
68     for (unsigned int i = 0; i < count; i++)
69       point_array[i] = points[i];
70
71     *point_count = points.len;
72
73     return true;
74   }
75
76   private:
77   OffsetTo<Coverage>
78                 coverage;               /* Offset to Coverage table -- from
79                                          * beginning of AttachList table */
80   OffsetArrayOf<AttachPoint>
81                 attachPoint;            /* Array of AttachPoint tables
82                                          * in Coverage Index order */
83 };
84 ASSERT_SIZE (AttachList, 4);
85
86 /*
87  * Ligature Caret Table
88  */
89
90 struct CaretValueFormat1
91 {
92   friend struct CaretValue;
93
94   private:
95   inline int get_caret_value (hb_ot_layout_context_t *context, hb_codepoint_t glyph_id) const
96   {
97     /* XXX vertical */
98     return context->font->x_scale * coordinate / 0x10000;
99   }
100
101   private:
102   USHORT        caretValueFormat;       /* Format identifier--format = 1 */
103   SHORT         coordinate;             /* X or Y value, in design units */
104 };
105 ASSERT_SIZE (CaretValueFormat1, 4);
106
107 struct CaretValueFormat2
108 {
109   friend struct CaretValue;
110
111   private:
112   inline int get_caret_value (hb_ot_layout_context_t *context, hb_codepoint_t glyph_id) const
113   {
114     return /* TODO contour point */ 0;
115   }
116
117   private:
118   USHORT        caretValueFormat;       /* Format identifier--format = 2 */
119   USHORT        caretValuePoint;        /* Contour point index on glyph */
120 };
121 ASSERT_SIZE (CaretValueFormat2, 4);
122
123 struct CaretValueFormat3
124 {
125   friend struct CaretValue;
126
127   inline int get_caret_value (hb_ot_layout_context_t *context, hb_codepoint_t glyph_id) const
128   {
129     /* XXX vertical */
130     return context->font->x_scale * coordinate / 0x10000 +
131            ((this+deviceTable).get_delta (context->font->x_ppem) << 6);
132   }
133
134   private:
135   USHORT        caretValueFormat;       /* Format identifier--format = 3 */
136   SHORT         coordinate;             /* X or Y value, in design units */
137   OffsetTo<Device>
138                 deviceTable;            /* Offset to Device table for X or Y
139                                          * value--from beginning of CaretValue
140                                          * table */
141 };
142 ASSERT_SIZE (CaretValueFormat3, 6);
143
144 struct CaretValue
145 {
146   /* XXX  we need access to a load-contour-point vfunc here */
147   int get_caret_value (hb_ot_layout_context_t *context, hb_codepoint_t glyph_id) const
148   {
149     switch (u.format) {
150     case 1: return u.format1->get_caret_value (context, glyph_id);
151     case 2: return u.format2->get_caret_value (context, glyph_id);
152     case 3: return u.format3->get_caret_value (context, glyph_id);
153     default:return 0;
154     }
155   }
156
157   private:
158   union {
159   USHORT                format;         /* Format identifier */
160   CaretValueFormat1     format1[];
161   CaretValueFormat2     format2[];
162   CaretValueFormat3     format3[];
163   } u;
164 };
165 ASSERT_SIZE (CaretValue, 2);
166
167 struct LigGlyph
168 {
169   inline void get_lig_carets (hb_ot_layout_context_t *context,
170                               hb_codepoint_t glyph_id,
171                               unsigned int *caret_count /* IN/OUT */,
172                               int *caret_array /* OUT */) const
173   {
174
175     unsigned int count = MIN (carets.len, *caret_count);
176     for (unsigned int i = 0; i < count; i++)
177       caret_array[i] = (this+carets[i]).get_caret_value (context, glyph_id);
178
179     *caret_count = carets.len;
180   }
181
182   private:
183   OffsetArrayOf<CaretValue>
184                 carets;                 /* Offset rrray of CaretValue tables
185                                          * --from beginning of LigGlyph table
186                                          * --in increasing coordinate order */
187 };
188 ASSERT_SIZE (LigGlyph, 2);
189
190 struct LigCaretList
191 {
192   inline bool get_lig_carets (hb_ot_layout_context_t *context,
193                               hb_codepoint_t glyph_id,
194                               unsigned int *caret_count /* IN/OUT */,
195                               int *caret_array /* OUT */) const
196   {
197     unsigned int index = (this+coverage) (glyph_id);
198     if (index == NOT_COVERED)
199     {
200       *caret_count = 0;
201       return false;
202     }
203     const LigGlyph &lig_glyph = this+ligGlyph[index];
204     lig_glyph.get_lig_carets (context, glyph_id, caret_count, caret_array);
205     return true;
206   }
207
208   private:
209   OffsetTo<Coverage>
210                 coverage;               /* Offset to Coverage table--from
211                                          * beginning of LigCaretList table */
212   OffsetArrayOf<LigGlyph>
213                 ligGlyph;               /* Array of LigGlyph tables
214                                          * in Coverage Index order */
215 };
216 ASSERT_SIZE (LigCaretList, 4);
217
218
219 struct MarkGlyphSetsFormat1
220 {
221   inline bool covers (unsigned int set_index, hb_codepoint_t glyph_id) const
222   { return (this+coverage[set_index]).get_coverage (glyph_id) != NOT_COVERED; }
223
224   private:
225   USHORT        format;                 /* Format identifier--format = 1 */
226   LongOffsetArrayOf<Coverage>
227                 coverage;               /* Array of long offsets to mark set
228                                          * coverage tables */
229 };
230 ASSERT_SIZE (MarkGlyphSetsFormat1, 4);
231
232 struct MarkGlyphSets
233 {
234   inline bool covers (unsigned int set_index, hb_codepoint_t glyph_id) const
235   {
236     switch (u.format) {
237     case 1: return u.format1->covers (set_index, glyph_id);
238     default:return false;
239     }
240   }
241
242   private:
243   union {
244   USHORT                format;         /* Format identifier */
245   MarkGlyphSetsFormat1  format1[];
246   } u;
247 };
248 ASSERT_SIZE (MarkGlyphSets, 2);
249
250
251 /*
252  * GDEF
253  */
254
255 struct GDEF
256 {
257   static const hb_tag_t Tag             = HB_TAG ('G','D','E','F');
258
259   enum {
260     UnclassifiedGlyph   = 0,
261     BaseGlyph           = 1,
262     LigatureGlyph       = 2,
263     MarkGlyph           = 3,
264     ComponentGlyph      = 4,
265   };
266
267   STATIC_DEFINE_GET_FOR_DATA_CHECK_MAJOR_VERSION (GDEF, 1, 1);
268
269   inline bool has_glyph_classes () const { return glyphClassDef != 0; }
270   inline hb_ot_layout_class_t get_glyph_class (hb_codepoint_t glyph) const
271   { return (this+glyphClassDef).get_class (glyph); }
272
273   inline bool has_mark_attachment_types () const { return markAttachClassDef != 0; }
274   inline hb_ot_layout_class_t get_mark_attachment_type (hb_codepoint_t glyph) const
275   { return (this+markAttachClassDef).get_class (glyph); }
276
277   inline bool has_attach_points () const { return attachList != 0; }
278   inline bool get_attach_points (hb_codepoint_t glyph_id,
279                                  unsigned int *point_count /* IN/OUT */,
280                                  unsigned int *point_array /* OUT */) const
281   { return (this+attachList).get_attach_points (glyph_id, point_count, point_array); }
282
283   inline bool has_lig_carets () const { return ligCaretList != 0; }
284   inline bool get_lig_carets (hb_ot_layout_context_t *context,
285                               hb_codepoint_t glyph_id,
286                               unsigned int *caret_count /* IN/OUT */,
287                               int *caret_array /* OUT */) const
288   { return (this+ligCaretList).get_lig_carets (context, glyph_id, caret_count, caret_array); }
289
290   inline bool has_mark_sets () const { return version >= 0x00010002 && markGlyphSetsDef[0] != 0; }
291   inline bool mark_set_covers (unsigned int set_index, hb_codepoint_t glyph_id) const
292   { return version >= 0x00010002 && (this+markGlyphSetsDef[0]).covers (set_index, glyph_id); }
293
294   private:
295   FixedVersion  version;                /* Version of the GDEF table--currently
296                                          * 0x00010002 */
297   OffsetTo<ClassDef>
298                 glyphClassDef;          /* Offset to class definition table
299                                          * for glyph type--from beginning of
300                                          * GDEF header (may be Null) */
301   OffsetTo<AttachList>
302                 attachList;             /* Offset to list of glyphs with
303                                          * attachment points--from beginning
304                                          * of GDEF header (may be Null) */
305   OffsetTo<LigCaretList>
306                 ligCaretList;           /* Offset to list of positioning points
307                                          * for ligature carets--from beginning
308                                          * of GDEF header (may be Null) */
309   OffsetTo<ClassDef>
310                 markAttachClassDef;     /* Offset to class definition table for
311                                          * mark attachment type--from beginning
312                                          * of GDEF header (may be Null) */
313   OffsetTo<MarkGlyphSets>
314                 markGlyphSetsDef[0];    /* Offset to the table of mark set
315                                          * definitions--from beginning of GDEF
316                                          * header (may be NULL).  Introduced
317                                          * in version 00010002. */
318 };
319 ASSERT_SIZE (GDEF, 12);
320
321
322 #endif /* HB_OT_LAYOUT_GDEF_PRIVATE_HH */