Towards normalization
[framework/uifw/harfbuzz.git] / src / hb-ot-shape-complex-private.hh
1 /*
2  * Copyright © 2010,2011  Google, Inc.
3  *
4  *  This is part of HarfBuzz, a text shaping 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  * Google Author(s): Behdad Esfahbod
25  */
26
27 #ifndef HB_OT_SHAPE_COMPLEX_PRIVATE_HH
28 #define HB_OT_SHAPE_COMPLEX_PRIVATE_HH
29
30 #include "hb-private.hh"
31
32 #include "hb-ot-map-private.hh"
33
34 HB_BEGIN_DECLS
35
36
37 /* buffer var allocations, used by all shapers */
38 #define general_category() var1.u8[0] /* unicode general_category (hb_unicode_general_category_t) */
39 #define combining_class() var1.u8[1] /* unicode combining_class (uint8_t) */
40
41
42 #define HB_COMPLEX_SHAPERS_IMPLEMENT_SHAPERS \
43   HB_COMPLEX_SHAPER_IMPLEMENT (default) /* should be first */ \
44   HB_COMPLEX_SHAPER_IMPLEMENT (arabic) \
45   HB_COMPLEX_SHAPER_IMPLEMENT (indic) \
46   /* ^--- Add new shapers here */
47
48 enum hb_ot_complex_shaper_t {
49 #define HB_COMPLEX_SHAPER_IMPLEMENT(name) hb_ot_complex_shaper_##name,
50   HB_COMPLEX_SHAPERS_IMPLEMENT_SHAPERS
51 #undef HB_COMPLEX_SHAPER_IMPLEMENT
52 };
53
54 static inline hb_ot_complex_shaper_t
55 hb_ot_shape_complex_categorize (const hb_segment_properties_t *props)
56 {
57   switch ((int) props->script)
58   {
59     default:
60       return hb_ot_complex_shaper_default;
61
62     case HB_SCRIPT_ARABIC:
63     case HB_SCRIPT_MANDAIC:
64     case HB_SCRIPT_MONGOLIAN:
65     case HB_SCRIPT_NKO:
66     case HB_SCRIPT_SYRIAC:
67       return hb_ot_complex_shaper_arabic;
68
69     /* TODO: These are all the scripts that the ucd/IndicSyllabicCategory.txt covers.
70      * Quite possibly many of these need no shaping, and some other are encoded visually.
71      * Needs to be refined.
72      */
73     case HB_SCRIPT_BALINESE:
74     case HB_SCRIPT_BATAK:
75     case HB_SCRIPT_BENGALI:
76     case HB_SCRIPT_BRAHMI:
77     case HB_SCRIPT_BUGINESE:
78     case HB_SCRIPT_BUHID:
79     case HB_SCRIPT_CHAM:
80     case HB_SCRIPT_DEVANAGARI:
81     case HB_SCRIPT_GUJARATI:
82     case HB_SCRIPT_GURMUKHI:
83     case HB_SCRIPT_HANUNOO:
84     case HB_SCRIPT_JAVANESE:
85     case HB_SCRIPT_KAITHI:
86     case HB_SCRIPT_KANNADA:
87     case HB_SCRIPT_KAYAH_LI:
88     case HB_SCRIPT_KHAROSHTHI:
89     case HB_SCRIPT_KHMER:
90     case HB_SCRIPT_LAO:
91     case HB_SCRIPT_LEPCHA:
92     case HB_SCRIPT_LIMBU:
93     case HB_SCRIPT_MALAYALAM:
94     case HB_SCRIPT_MEETEI_MAYEK:
95     case HB_SCRIPT_MYANMAR:
96     case HB_SCRIPT_NEW_TAI_LUE:
97     case HB_SCRIPT_ORIYA:
98     case HB_SCRIPT_PHAGS_PA:
99     case HB_SCRIPT_REJANG:
100     case HB_SCRIPT_SAURASHTRA:
101     case HB_SCRIPT_SINHALA:
102     case HB_SCRIPT_SUNDANESE:
103     case HB_SCRIPT_SYLOTI_NAGRI:
104     case HB_SCRIPT_TAGALOG:
105     case HB_SCRIPT_TAGBANWA:
106     case HB_SCRIPT_TAI_LE:
107     case HB_SCRIPT_TAI_THAM:
108     case HB_SCRIPT_TAI_VIET:
109     case HB_SCRIPT_TAMIL:
110     case HB_SCRIPT_TELUGU:
111     case HB_SCRIPT_THAI:
112     case HB_SCRIPT_TIBETAN:
113       return hb_ot_complex_shaper_indic;
114
115     /* ^--- Add new shapers here */
116   }
117 }
118
119
120
121 /*
122  * collect_features()
123  *
124  * Called during shape_plan().
125  *
126  * Shapers should use map to add their features and callbacks.
127  */
128
129 typedef void hb_ot_shape_complex_collect_features_func_t (hb_ot_map_builder_t *map, const hb_segment_properties_t  *props);
130 #define HB_COMPLEX_SHAPER_IMPLEMENT(name) \
131   HB_INTERNAL hb_ot_shape_complex_collect_features_func_t _hb_ot_shape_complex_collect_features_##name;
132   HB_COMPLEX_SHAPERS_IMPLEMENT_SHAPERS
133 #undef HB_COMPLEX_SHAPER_IMPLEMENT
134
135 static inline void
136 hb_ot_shape_complex_collect_features (hb_ot_complex_shaper_t shaper,
137                                       hb_ot_map_builder_t *map,
138                                       const hb_segment_properties_t  *props)
139 {
140   switch (shaper) {
141     default:
142 #define HB_COMPLEX_SHAPER_IMPLEMENT(name) \
143     case hb_ot_complex_shaper_##name:   _hb_ot_shape_complex_collect_features_##name    (map, props);   return;
144     HB_COMPLEX_SHAPERS_IMPLEMENT_SHAPERS
145 #undef HB_COMPLEX_SHAPER_IMPLEMENT
146   }
147 }
148
149
150 /* setup_masks()
151  *
152  * Called during shape_execute().
153  *
154  * Shapers should use map to get feature masks and set on buffer.
155  */
156
157 typedef void hb_ot_shape_complex_setup_masks_func_t (hb_ot_map_t *map, hb_buffer_t *buffer);
158 #define HB_COMPLEX_SHAPER_IMPLEMENT(name) \
159   HB_INTERNAL hb_ot_shape_complex_setup_masks_func_t _hb_ot_shape_complex_setup_masks_##name;
160   HB_COMPLEX_SHAPERS_IMPLEMENT_SHAPERS
161 #undef HB_COMPLEX_SHAPER_IMPLEMENT
162
163 static inline void
164 hb_ot_shape_complex_setup_masks (hb_ot_complex_shaper_t shaper,
165                                  hb_ot_map_t *map,
166                                  hb_buffer_t *buffer)
167 {
168   switch (shaper) {
169     default:
170 #define HB_COMPLEX_SHAPER_IMPLEMENT(name) \
171     case hb_ot_complex_shaper_##name:   _hb_ot_shape_complex_setup_masks_##name (map, buffer);  return;
172     HB_COMPLEX_SHAPERS_IMPLEMENT_SHAPERS
173 #undef HB_COMPLEX_SHAPER_IMPLEMENT
174   }
175 }
176
177
178 HB_END_DECLS
179
180 #endif /* HB_OT_SHAPE_COMPLEX_PRIVATE_HH */