Imported Upstream version 0.9.3
[platform/upstream/harfbuzz.git] / src / hb-ot-shape-complex-private.hh
1 /*
2  * Copyright © 2010,2011,2012  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-shape-private.hh"
33 #include "hb-ot-shape-normalize-private.hh"
34
35
36
37 /* buffer var allocations, used by complex shapers */
38 #define complex_var_u8_0()      var2.u8[2]
39 #define complex_var_u8_1()      var2.u8[3]
40
41
42
43 /* Master OT shaper list */
44 #define HB_COMPLEX_SHAPERS_IMPLEMENT_SHAPERS \
45   HB_COMPLEX_SHAPER_IMPLEMENT (default) /* should be first */ \
46   HB_COMPLEX_SHAPER_IMPLEMENT (arabic) \
47   HB_COMPLEX_SHAPER_IMPLEMENT (indic) \
48   HB_COMPLEX_SHAPER_IMPLEMENT (thai) \
49   /* ^--- Add new shapers here */
50
51
52 struct hb_ot_complex_shaper_t
53 {
54   char name[8];
55
56   /* collect_features()
57    * Called during shape_plan().
58    * Shapers should use plan->map to add their features and callbacks.
59    */
60   void (*collect_features) (hb_ot_shape_planner_t *plan);
61
62   /* override_features()
63    * Called during shape_plan().
64    * Shapers should use plan->map to override features and add callbacks after
65    * common features are added.
66    */
67   void (*override_features) (hb_ot_shape_planner_t *plan);
68
69
70   /* data_create()
71    * Called at the end of shape_plan().
72    * Whatever shapers return will be accessible through plan->data later.
73    * If NULL is returned, means a plan failure.
74    */
75   void *(*data_create) (const hb_ot_shape_plan_t *plan);
76
77   /* data_destroy()
78    * Called when the shape_plan is being destroyed.
79    * plan->data is passed here for destruction.
80    * If NULL is returned, means a plan failure.
81    * May be NULL. */
82   void (*data_destroy) (void *data);
83
84
85   /* preprocess_text()
86    * Called during shape().
87    * Shapers can use to modify text before shaping starts.
88    */
89   void (*preprocess_text) (const hb_ot_shape_plan_t *plan,
90                            hb_buffer_t              *buffer,
91                            hb_font_t                *font);
92
93
94   /* normalization_preference()
95    * Called during shape().
96    */
97   hb_ot_shape_normalization_mode_t
98   (*normalization_preference) (const hb_ot_shape_plan_t *plan);
99
100   /* setup_masks()
101    * Called during shape().
102    * Shapers should use map to get feature masks and set on buffer.
103    * Shapers may NOT modify characters.
104    */
105   void (*setup_masks) (const hb_ot_shape_plan_t *plan,
106                        hb_buffer_t              *buffer,
107                        hb_font_t                *font);
108
109   bool zero_width_attached_marks;
110 };
111
112 #define HB_COMPLEX_SHAPER_IMPLEMENT(name) extern HB_INTERNAL const hb_ot_complex_shaper_t _hb_ot_complex_shaper_##name;
113 HB_COMPLEX_SHAPERS_IMPLEMENT_SHAPERS
114 #undef HB_COMPLEX_SHAPER_IMPLEMENT
115
116
117 static inline const hb_ot_complex_shaper_t *
118 hb_ot_shape_complex_categorize (const hb_segment_properties_t *props)
119 {
120   switch ((hb_tag_t) props->script)
121   {
122     default:
123       return &_hb_ot_complex_shaper_default;
124
125
126     /* Unicode-1.1 additions */
127     case HB_SCRIPT_ARABIC:
128     case HB_SCRIPT_MONGOLIAN:
129     case HB_SCRIPT_SYRIAC:
130
131     /* Unicode-5.0 additions */
132     case HB_SCRIPT_NKO:
133
134     /* Unicode-6.0 additions */
135     case HB_SCRIPT_MANDAIC:
136
137       return &_hb_ot_complex_shaper_arabic;
138
139
140     /* Unicode-1.1 additions */
141     case HB_SCRIPT_THAI:
142     case HB_SCRIPT_LAO:
143
144       return &_hb_ot_complex_shaper_thai;
145
146
147
148     /* ^--- Add new shapers here */
149
150
151 #if 0
152     /* Note:
153      *
154      * These disabled scripts are listed in ucd/IndicSyllabicCategory.txt, but according
155      * to Martin Hosken and Jonathan Kew do not require complex shaping.
156      *
157      * TODO We should automate figuring out which scripts do not need complex shaping
158      *
159      * TODO We currently keep data for these scripts in our indic table.  Need to fix the
160      * generator to not do that.
161      */
162
163
164     /* Simple? */
165
166     /* Unicode-3.2 additions */
167     case HB_SCRIPT_BUHID:
168     case HB_SCRIPT_HANUNOO:
169
170     /* Unicode-5.1 additions */
171     case HB_SCRIPT_SAURASHTRA:
172
173     /* Unicode-5.2 additions */
174     case HB_SCRIPT_MEETEI_MAYEK:
175
176     /* Unicode-6.0 additions */
177     case HB_SCRIPT_BATAK:
178     case HB_SCRIPT_BRAHMI:
179
180
181     /* Simple */
182
183     /* Unicode-1.1 additions */
184     /* These have their own shaper now. */
185     case HB_SCRIPT_LAO:
186     case HB_SCRIPT_THAI:
187
188     /* Unicode-2.0 additions */
189     case HB_SCRIPT_TIBETAN:
190
191     /* Unicode-3.2 additions */
192     case HB_SCRIPT_TAGALOG:
193     case HB_SCRIPT_TAGBANWA:
194
195     /* Unicode-4.0 additions */
196     case HB_SCRIPT_LIMBU:
197     case HB_SCRIPT_TAI_LE:
198
199     /* Unicode-4.1 additions */
200     case HB_SCRIPT_SYLOTI_NAGRI:
201
202     /* Unicode-5.0 additions */
203     case HB_SCRIPT_PHAGS_PA:
204
205     /* Unicode-5.1 additions */
206     case HB_SCRIPT_KAYAH_LI:
207
208     /* Unicode-5.2 additions */
209     case HB_SCRIPT_TAI_VIET:
210
211
212     /* May need Indic treatment in the future? */
213
214     /* Unicode-3.0 additions */
215     case HB_SCRIPT_MYANMAR:
216
217
218 #endif
219
220     /* Unicode-1.1 additions */
221     case HB_SCRIPT_BENGALI:
222     case HB_SCRIPT_DEVANAGARI:
223     case HB_SCRIPT_GUJARATI:
224     case HB_SCRIPT_GURMUKHI:
225     case HB_SCRIPT_KANNADA:
226     case HB_SCRIPT_MALAYALAM:
227     case HB_SCRIPT_ORIYA:
228     case HB_SCRIPT_TAMIL:
229     case HB_SCRIPT_TELUGU:
230
231     /* Unicode-3.0 additions */
232     case HB_SCRIPT_KHMER:
233     case HB_SCRIPT_SINHALA:
234
235     /* Unicode-4.1 additions */
236     case HB_SCRIPT_BUGINESE:
237     case HB_SCRIPT_KHAROSHTHI:
238     case HB_SCRIPT_NEW_TAI_LUE:
239
240     /* Unicode-5.0 additions */
241     case HB_SCRIPT_BALINESE:
242
243     /* Unicode-5.1 additions */
244     case HB_SCRIPT_CHAM:
245     case HB_SCRIPT_LEPCHA:
246     case HB_SCRIPT_REJANG:
247     case HB_SCRIPT_SUNDANESE:
248
249     /* Unicode-5.2 additions */
250     case HB_SCRIPT_JAVANESE:
251     case HB_SCRIPT_KAITHI:
252     case HB_SCRIPT_TAI_THAM:
253
254     /* Unicode-6.1 additions */
255     case HB_SCRIPT_CHAKMA:
256     case HB_SCRIPT_SHARADA:
257     case HB_SCRIPT_TAKRI:
258
259       return &_hb_ot_complex_shaper_indic;
260   }
261 }
262
263
264 #endif /* HB_OT_SHAPE_COMPLEX_PRIVATE_HH */