2 * Copyright © 2010,2011,2012 Google, Inc.
4 * This is part of HarfBuzz, a text shaping library.
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.
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
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.
24 * Google Author(s): Behdad Esfahbod
27 #ifndef HB_OT_SHAPE_COMPLEX_PRIVATE_HH
28 #define HB_OT_SHAPE_COMPLEX_PRIVATE_HH
30 #include "hb-private.hh"
32 #include "hb-ot-shape-private.hh"
33 #include "hb-ot-shape-normalize-private.hh"
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]
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 */
52 struct hb_ot_complex_shaper_t
57 * Called during shape_plan().
58 * Shapers should use plan->map to add their features and callbacks.
61 void (*collect_features) (hb_ot_shape_planner_t *plan);
63 /* override_features()
64 * Called during shape_plan().
65 * Shapers should use plan->map to override features and add callbacks after
66 * common features are added.
69 void (*override_features) (hb_ot_shape_planner_t *plan);
73 * Called at the end of shape_plan().
74 * Whatever shapers return will be accessible through plan->data later.
75 * If NULL is returned, means a plan failure.
77 void *(*data_create) (const hb_ot_shape_plan_t *plan);
80 * Called when the shape_plan is being destroyed.
81 * plan->data is passed here for destruction.
82 * If NULL is returned, means a plan failure.
85 void (*data_destroy) (void *data);
89 * Called during shape().
90 * Shapers can use to modify text before shaping starts.
93 void (*preprocess_text) (const hb_ot_shape_plan_t *plan,
98 /* normalization_preference()
99 * Called during shape().
102 hb_ot_shape_normalization_mode_t
103 (*normalization_preference) (const hb_segment_properties_t *props);
106 * Called during shape()'s normalization.
109 bool (*decompose) (const hb_ot_shape_normalize_context_t *c,
115 * Called during shape()'s normalization.
118 bool (*compose) (const hb_ot_shape_normalize_context_t *c,
124 * Called during shape().
125 * Shapers should use map to get feature masks and set on buffer.
126 * Shapers may NOT modify characters.
129 void (*setup_masks) (const hb_ot_shape_plan_t *plan,
133 bool zero_width_attached_marks;
134 bool fallback_position;
137 #define HB_COMPLEX_SHAPER_IMPLEMENT(name) extern HB_INTERNAL const hb_ot_complex_shaper_t _hb_ot_complex_shaper_##name;
138 HB_COMPLEX_SHAPERS_IMPLEMENT_SHAPERS
139 #undef HB_COMPLEX_SHAPER_IMPLEMENT
142 static inline const hb_ot_complex_shaper_t *
143 hb_ot_shape_complex_categorize (const hb_ot_shape_planner_t *planner)
145 switch ((hb_tag_t) planner->props.script)
148 return &_hb_ot_complex_shaper_default;
151 /* Unicode-1.1 additions */
152 case HB_SCRIPT_ARABIC:
153 case HB_SCRIPT_MONGOLIAN:
154 case HB_SCRIPT_SYRIAC:
156 /* Unicode-5.0 additions */
158 case HB_SCRIPT_PHAGS_PA:
160 /* Unicode-6.0 additions */
161 case HB_SCRIPT_MANDAIC:
163 /* For Arabic script, use the Arabic shaper even if no OT script tag was found.
164 * This is because we do fallback shaping for Arabic script (and not others). */
165 if (planner->map.chosen_script[0] != HB_OT_TAG_DEFAULT_SCRIPT ||
166 planner->props.script == HB_SCRIPT_ARABIC)
167 return &_hb_ot_complex_shaper_arabic;
169 return &_hb_ot_complex_shaper_default;
172 /* Unicode-1.1 additions */
176 return &_hb_ot_complex_shaper_thai;
180 /* ^--- Add new shapers here */
186 * These disabled scripts are listed in ucd/IndicSyllabicCategory.txt, but according
187 * to Martin Hosken and Jonathan Kew do not require complex shaping.
189 * TODO We should automate figuring out which scripts do not need complex shaping
191 * TODO We currently keep data for these scripts in our indic table. Need to fix the
192 * generator to not do that.
198 /* Unicode-3.2 additions */
199 case HB_SCRIPT_BUHID:
200 case HB_SCRIPT_HANUNOO:
202 /* Unicode-5.1 additions */
203 case HB_SCRIPT_SAURASHTRA:
205 /* Unicode-6.0 additions */
206 case HB_SCRIPT_BATAK:
207 case HB_SCRIPT_BRAHMI:
212 /* Unicode-1.1 additions */
213 /* These have their own shaper now. */
217 /* Unicode-2.0 additions */
218 case HB_SCRIPT_TIBETAN:
220 /* Unicode-3.2 additions */
221 case HB_SCRIPT_TAGALOG:
222 case HB_SCRIPT_TAGBANWA:
224 /* Unicode-4.0 additions */
225 case HB_SCRIPT_LIMBU:
226 case HB_SCRIPT_TAI_LE:
228 /* Unicode-4.1 additions */
229 case HB_SCRIPT_KHAROSHTHI:
230 case HB_SCRIPT_SYLOTI_NAGRI:
232 /* Unicode-5.1 additions */
233 case HB_SCRIPT_KAYAH_LI:
235 /* Unicode-5.2 additions */
236 case HB_SCRIPT_TAI_VIET:
241 /* Unicode-1.1 additions */
242 case HB_SCRIPT_BENGALI:
243 case HB_SCRIPT_DEVANAGARI:
244 case HB_SCRIPT_GUJARATI:
245 case HB_SCRIPT_GURMUKHI:
246 case HB_SCRIPT_KANNADA:
247 case HB_SCRIPT_MALAYALAM:
248 case HB_SCRIPT_ORIYA:
249 case HB_SCRIPT_TAMIL:
250 case HB_SCRIPT_TELUGU:
252 /* Unicode-3.0 additions */
253 case HB_SCRIPT_SINHALA:
255 /* Unicode-4.1 additions */
256 case HB_SCRIPT_BUGINESE:
257 case HB_SCRIPT_NEW_TAI_LUE:
259 /* Unicode-5.0 additions */
260 case HB_SCRIPT_BALINESE:
262 /* Unicode-5.1 additions */
264 case HB_SCRIPT_LEPCHA:
265 case HB_SCRIPT_REJANG:
266 case HB_SCRIPT_SUNDANESE:
268 /* Unicode-5.2 additions */
269 case HB_SCRIPT_JAVANESE:
270 case HB_SCRIPT_KAITHI:
271 case HB_SCRIPT_MEETEI_MAYEK:
272 case HB_SCRIPT_TAI_THAM:
275 /* Unicode-6.1 additions */
276 case HB_SCRIPT_CHAKMA:
277 case HB_SCRIPT_SHARADA:
278 case HB_SCRIPT_TAKRI:
280 /* Only use Indic shaper if the font has Indic tables. */
281 if (planner->map.found_script[0])
282 return &_hb_ot_complex_shaper_indic;
284 return &_hb_ot_complex_shaper_default;
286 case HB_SCRIPT_KHMER:
287 /* A number of Khmer fonts in the wild don't have a 'pref' feature,
288 * and as such won't shape properly via the Indic shaper;
289 * however, they typically have 'liga' / 'clig' features that implement
290 * the necessary "reordering" by means of ligature substitutions.
291 * So we send such pref-less fonts through the generic shaper instead. */
292 if (planner->map.found_script[0] &&
293 hb_ot_layout_language_find_feature (planner->face, HB_OT_TAG_GSUB,
294 planner->map.script_index[0],
295 planner->map.language_index[0],
296 HB_TAG ('p','r','e','f'),
298 return &_hb_ot_complex_shaper_indic;
300 return &_hb_ot_complex_shaper_default;
302 case HB_SCRIPT_MYANMAR:
303 /* For Myanmar, we only want to use the Indic shaper if the "new" script
304 * tag is found. For "old" script tag we want to use the default shaper. */
305 if (planner->map.chosen_script[0] == HB_TAG ('m','y','m','2'))
306 return &_hb_ot_complex_shaper_indic;
308 return &_hb_ot_complex_shaper_default;
313 #endif /* HB_OT_SHAPE_COMPLEX_PRIVATE_HH */