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