Register buffer vars in Indic shaper
[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 during the entire shaping process */
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 /* buffer var allocations, used by complex shapers */
42 #define complex_var_persistent_u8_0()   var2.u8[0]
43 #define complex_var_persistent_u8_1()   var2.u8[1]
44 #define complex_var_persistent_u16()    var2.u16[0]
45 #define complex_var_temporary_u8_0()    var2.u8[2]
46 #define complex_var_temporary_u8_1()    var2.u8[3]
47 #define complex_var_temporary_u16()     var2.u16[1]
48
49
50 #define HB_COMPLEX_SHAPERS_IMPLEMENT_SHAPERS \
51   HB_COMPLEX_SHAPER_IMPLEMENT (default) /* should be first */ \
52   HB_COMPLEX_SHAPER_IMPLEMENT (arabic) \
53   HB_COMPLEX_SHAPER_IMPLEMENT (indic) \
54   /* ^--- Add new shapers here */
55
56 enum hb_ot_complex_shaper_t {
57 #define HB_COMPLEX_SHAPER_IMPLEMENT(name) hb_ot_complex_shaper_##name,
58   HB_COMPLEX_SHAPERS_IMPLEMENT_SHAPERS
59 #undef HB_COMPLEX_SHAPER_IMPLEMENT
60 };
61
62 static inline hb_ot_complex_shaper_t
63 hb_ot_shape_complex_categorize (const hb_segment_properties_t *props)
64 {
65   switch ((int) props->script)
66   {
67     default:
68       return hb_ot_complex_shaper_default;
69
70     case HB_SCRIPT_ARABIC:
71     case HB_SCRIPT_MANDAIC:
72     case HB_SCRIPT_MONGOLIAN:
73     case HB_SCRIPT_NKO:
74     case HB_SCRIPT_SYRIAC:
75       return hb_ot_complex_shaper_arabic;
76
77     /* TODO: These are all the scripts that the ucd/IndicSyllabicCategory.txt covers.
78      * Quite possibly many of these need no shaping, and some other are encoded visually.
79      * Needs to be refined.
80      */
81     case HB_SCRIPT_BALINESE:
82     case HB_SCRIPT_BATAK:
83     case HB_SCRIPT_BENGALI:
84     case HB_SCRIPT_BRAHMI:
85     case HB_SCRIPT_BUGINESE:
86     case HB_SCRIPT_BUHID:
87     case HB_SCRIPT_CHAM:
88     case HB_SCRIPT_DEVANAGARI:
89     case HB_SCRIPT_GUJARATI:
90     case HB_SCRIPT_GURMUKHI:
91     case HB_SCRIPT_HANUNOO:
92     case HB_SCRIPT_JAVANESE:
93     case HB_SCRIPT_KAITHI:
94     case HB_SCRIPT_KANNADA:
95     case HB_SCRIPT_KAYAH_LI:
96     case HB_SCRIPT_KHAROSHTHI:
97     case HB_SCRIPT_KHMER:
98     case HB_SCRIPT_LAO:
99     case HB_SCRIPT_LEPCHA:
100     case HB_SCRIPT_LIMBU:
101     case HB_SCRIPT_MALAYALAM:
102     case HB_SCRIPT_MEETEI_MAYEK:
103     case HB_SCRIPT_MYANMAR:
104     case HB_SCRIPT_NEW_TAI_LUE:
105     case HB_SCRIPT_ORIYA:
106     case HB_SCRIPT_PHAGS_PA:
107     case HB_SCRIPT_REJANG:
108     case HB_SCRIPT_SAURASHTRA:
109     case HB_SCRIPT_SINHALA:
110     case HB_SCRIPT_SUNDANESE:
111     case HB_SCRIPT_SYLOTI_NAGRI:
112     case HB_SCRIPT_TAGALOG:
113     case HB_SCRIPT_TAGBANWA:
114     case HB_SCRIPT_TAI_LE:
115     case HB_SCRIPT_TAI_THAM:
116     case HB_SCRIPT_TAI_VIET:
117     case HB_SCRIPT_TAMIL:
118     case HB_SCRIPT_TELUGU:
119     case HB_SCRIPT_THAI:
120     case HB_SCRIPT_TIBETAN:
121       return hb_ot_complex_shaper_indic;
122
123     /* ^--- Add new shapers here */
124   }
125 }
126
127
128
129 /*
130  * collect_features()
131  *
132  * Called during shape_plan().
133  *
134  * Shapers should use map to add their features and callbacks.
135  */
136
137 typedef void hb_ot_shape_complex_collect_features_func_t (hb_ot_map_builder_t *map, const hb_segment_properties_t  *props);
138 #define HB_COMPLEX_SHAPER_IMPLEMENT(name) \
139   HB_INTERNAL hb_ot_shape_complex_collect_features_func_t _hb_ot_shape_complex_collect_features_##name;
140   HB_COMPLEX_SHAPERS_IMPLEMENT_SHAPERS
141 #undef HB_COMPLEX_SHAPER_IMPLEMENT
142
143 static inline void
144 hb_ot_shape_complex_collect_features (hb_ot_complex_shaper_t shaper,
145                                       hb_ot_map_builder_t *map,
146                                       const hb_segment_properties_t  *props)
147 {
148   switch (shaper) {
149     default:
150 #define HB_COMPLEX_SHAPER_IMPLEMENT(name) \
151     case hb_ot_complex_shaper_##name:   _hb_ot_shape_complex_collect_features_##name (map, props); return;
152     HB_COMPLEX_SHAPERS_IMPLEMENT_SHAPERS
153 #undef HB_COMPLEX_SHAPER_IMPLEMENT
154   }
155 }
156
157
158 /*
159  * prefer_decomposed()
160  *
161  * Called during shape_execute().
162  *
163  * Shapers should return TRUE if it prefers decomposed (NFD) input rather than precomposed (NFC).
164  */
165
166 typedef bool hb_ot_shape_complex_prefer_decomposed_func_t (void);
167 #define HB_COMPLEX_SHAPER_IMPLEMENT(name) \
168   HB_INTERNAL hb_ot_shape_complex_prefer_decomposed_func_t _hb_ot_shape_complex_prefer_decomposed_##name;
169   HB_COMPLEX_SHAPERS_IMPLEMENT_SHAPERS
170 #undef HB_COMPLEX_SHAPER_IMPLEMENT
171
172 static inline bool
173 hb_ot_shape_complex_prefer_decomposed (hb_ot_complex_shaper_t shaper)
174 {
175   switch (shaper) {
176     default:
177 #define HB_COMPLEX_SHAPER_IMPLEMENT(name) \
178     case hb_ot_complex_shaper_##name:   return _hb_ot_shape_complex_prefer_decomposed_##name ();
179     HB_COMPLEX_SHAPERS_IMPLEMENT_SHAPERS
180 #undef HB_COMPLEX_SHAPER_IMPLEMENT
181   }
182 }
183
184
185 /* setup_masks()
186  *
187  * Called during shape_execute().
188  *
189  * Shapers should use map to get feature masks and set on buffer.
190  */
191
192 typedef void hb_ot_shape_complex_setup_masks_func_t (hb_ot_map_t *map, hb_buffer_t *buffer);
193 #define HB_COMPLEX_SHAPER_IMPLEMENT(name) \
194   HB_INTERNAL hb_ot_shape_complex_setup_masks_func_t _hb_ot_shape_complex_setup_masks_##name;
195   HB_COMPLEX_SHAPERS_IMPLEMENT_SHAPERS
196 #undef HB_COMPLEX_SHAPER_IMPLEMENT
197
198 static inline void
199 hb_ot_shape_complex_setup_masks (hb_ot_complex_shaper_t shaper,
200                                  hb_ot_map_t *map,
201                                  hb_buffer_t *buffer)
202 {
203   switch (shaper) {
204     default:
205 #define HB_COMPLEX_SHAPER_IMPLEMENT(name) \
206     case hb_ot_complex_shaper_##name:   _hb_ot_shape_complex_setup_masks_##name (map, buffer); return;
207     HB_COMPLEX_SHAPERS_IMPLEMENT_SHAPERS
208 #undef HB_COMPLEX_SHAPER_IMPLEMENT
209   }
210 }
211
212
213 HB_END_DECLS
214
215 #endif /* HB_OT_SHAPE_COMPLEX_PRIVATE_HH */