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]
42 enum hb_ot_shape_zero_width_marks_type_t {
43 HB_OT_SHAPE_ZERO_WIDTH_MARKS_NONE,
44 // HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_UNICODE_EARLY,
45 HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_UNICODE_LATE,
46 HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_GDEF_EARLY,
47 HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_GDEF_LATE,
49 HB_OT_SHAPE_ZERO_WIDTH_MARKS_DEFAULT = HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_UNICODE_LATE
53 /* Master OT shaper list */
54 #define HB_COMPLEX_SHAPERS_IMPLEMENT_SHAPERS \
55 HB_COMPLEX_SHAPER_IMPLEMENT (default) /* should be first */ \
56 HB_COMPLEX_SHAPER_IMPLEMENT (arabic) \
57 HB_COMPLEX_SHAPER_IMPLEMENT (hangul) \
58 HB_COMPLEX_SHAPER_IMPLEMENT (hebrew) \
59 HB_COMPLEX_SHAPER_IMPLEMENT (indic) \
60 HB_COMPLEX_SHAPER_IMPLEMENT (myanmar) \
61 HB_COMPLEX_SHAPER_IMPLEMENT (sea) \
62 HB_COMPLEX_SHAPER_IMPLEMENT (thai) \
63 HB_COMPLEX_SHAPER_IMPLEMENT (tibetan) \
64 /* ^--- Add new shapers here */
67 struct hb_ot_complex_shaper_t
72 * Called during shape_plan().
73 * Shapers should use plan->map to add their features and callbacks.
76 void (*collect_features) (hb_ot_shape_planner_t *plan);
78 /* override_features()
79 * Called during shape_plan().
80 * Shapers should use plan->map to override features and add callbacks after
81 * common features are added.
84 void (*override_features) (hb_ot_shape_planner_t *plan);
88 * Called at the end of shape_plan().
89 * Whatever shapers return will be accessible through plan->data later.
90 * If NULL is returned, means a plan failure.
92 void *(*data_create) (const hb_ot_shape_plan_t *plan);
95 * Called when the shape_plan is being destroyed.
96 * plan->data is passed here for destruction.
97 * If NULL is returned, means a plan failure.
100 void (*data_destroy) (void *data);
104 * Called during shape().
105 * Shapers can use to modify text before shaping starts.
108 void (*preprocess_text) (const hb_ot_shape_plan_t *plan,
113 hb_ot_shape_normalization_mode_t normalization_preference;
116 * Called during shape()'s normalization.
119 bool (*decompose) (const hb_ot_shape_normalize_context_t *c,
125 * Called during shape()'s normalization.
128 bool (*compose) (const hb_ot_shape_normalize_context_t *c,
134 * Called during shape().
135 * Shapers should use map to get feature masks and set on buffer.
136 * Shapers may NOT modify characters.
139 void (*setup_masks) (const hb_ot_shape_plan_t *plan,
143 hb_ot_shape_zero_width_marks_type_t zero_width_marks;
145 bool fallback_position;
148 #define HB_COMPLEX_SHAPER_IMPLEMENT(name) extern HB_INTERNAL const hb_ot_complex_shaper_t _hb_ot_complex_shaper_##name;
149 HB_COMPLEX_SHAPERS_IMPLEMENT_SHAPERS
150 #undef HB_COMPLEX_SHAPER_IMPLEMENT
153 static inline const hb_ot_complex_shaper_t *
154 hb_ot_shape_complex_categorize (const hb_ot_shape_planner_t *planner)
156 switch ((hb_tag_t) planner->props.script)
159 return &_hb_ot_complex_shaper_default;
162 /* Unicode-1.1 additions */
163 case HB_SCRIPT_ARABIC:
165 /* Unicode-3.0 additions */
166 case HB_SCRIPT_MONGOLIAN:
167 case HB_SCRIPT_SYRIAC:
169 /* Unicode-5.0 additions */
171 case HB_SCRIPT_PHAGS_PA:
173 /* Unicode-6.0 additions */
174 case HB_SCRIPT_MANDAIC:
176 /* For Arabic script, use the Arabic shaper even if no OT script tag was found.
177 * This is because we do fallback shaping for Arabic script (and not others). */
178 if (planner->map.chosen_script[0] != HB_OT_TAG_DEFAULT_SCRIPT ||
179 planner->props.script == HB_SCRIPT_ARABIC)
180 return &_hb_ot_complex_shaper_arabic;
182 return &_hb_ot_complex_shaper_default;
185 /* Unicode-1.1 additions */
189 return &_hb_ot_complex_shaper_thai;
192 /* Unicode-1.1 additions */
193 case HB_SCRIPT_HANGUL:
195 return &_hb_ot_complex_shaper_hangul;
198 /* Unicode-2.0 additions */
199 case HB_SCRIPT_TIBETAN:
201 return &_hb_ot_complex_shaper_tibetan;
204 /* Unicode-1.1 additions */
205 case HB_SCRIPT_HEBREW:
207 return &_hb_ot_complex_shaper_hebrew;
210 /* ^--- Add new shapers here */
216 * These disabled scripts are listed in ucd/IndicSyllabicCategory.txt, but according
217 * to Martin Hosken and Jonathan Kew do not require complex shaping.
219 * TODO We should automate figuring out which scripts do not need complex shaping
221 * TODO We currently keep data for these scripts in our indic table. Need to fix the
222 * generator to not do that.
228 /* Unicode-3.2 additions */
229 case HB_SCRIPT_BUHID:
230 case HB_SCRIPT_HANUNOO:
232 /* Unicode-5.1 additions */
233 case HB_SCRIPT_SAURASHTRA:
235 /* Unicode-6.0 additions */
236 case HB_SCRIPT_BATAK:
237 case HB_SCRIPT_BRAHMI:
242 /* Unicode-1.1 additions */
243 /* These have their own shaper now. */
247 /* Unicode-3.2 additions */
248 case HB_SCRIPT_TAGALOG:
249 case HB_SCRIPT_TAGBANWA:
251 /* Unicode-4.0 additions */
252 case HB_SCRIPT_LIMBU:
253 case HB_SCRIPT_TAI_LE:
255 /* Unicode-4.1 additions */
256 case HB_SCRIPT_KHAROSHTHI:
257 case HB_SCRIPT_SYLOTI_NAGRI:
259 /* Unicode-5.1 additions */
260 case HB_SCRIPT_KAYAH_LI:
262 /* Unicode-5.2 additions */
263 case HB_SCRIPT_TAI_VIET:
268 /* Unicode-1.1 additions */
269 case HB_SCRIPT_BENGALI:
270 case HB_SCRIPT_DEVANAGARI:
271 case HB_SCRIPT_GUJARATI:
272 case HB_SCRIPT_GURMUKHI:
273 case HB_SCRIPT_KANNADA:
274 case HB_SCRIPT_MALAYALAM:
275 case HB_SCRIPT_ORIYA:
276 case HB_SCRIPT_TAMIL:
277 case HB_SCRIPT_TELUGU:
279 /* Unicode-3.0 additions */
280 case HB_SCRIPT_SINHALA:
282 /* Unicode-5.0 additions */
283 case HB_SCRIPT_BALINESE:
285 /* Unicode-5.1 additions */
286 case HB_SCRIPT_LEPCHA:
287 case HB_SCRIPT_REJANG:
288 case HB_SCRIPT_SUNDANESE:
290 /* Unicode-5.2 additions */
291 case HB_SCRIPT_JAVANESE:
292 case HB_SCRIPT_KAITHI:
293 case HB_SCRIPT_MEETEI_MAYEK:
295 /* Unicode-6.0 additions */
297 /* Unicode-6.1 additions */
298 case HB_SCRIPT_CHAKMA:
299 case HB_SCRIPT_SHARADA:
300 case HB_SCRIPT_TAKRI:
302 /* If the designer designed the font for the 'DFLT' script,
303 * use the default shaper. Otherwise, use the Indic shaper.
304 * Note that for some simple scripts, there may not be *any*
305 * GSUB/GPOS needed, so there may be no scripts found! */
306 if (planner->map.chosen_script[0] == HB_TAG ('D','F','L','T'))
307 return &_hb_ot_complex_shaper_default;
309 return &_hb_ot_complex_shaper_indic;
311 case HB_SCRIPT_KHMER:
312 /* A number of Khmer fonts in the wild don't have a 'pref' feature,
313 * and as such won't shape properly via the Indic shaper;
314 * however, they typically have 'liga' / 'clig' features that implement
315 * the necessary "reordering" by means of ligature substitutions.
316 * So we send such pref-less fonts through the generic shaper instead. */
317 if (planner->map.found_script[0] &&
318 hb_ot_layout_language_find_feature (planner->face, HB_OT_TAG_GSUB,
319 planner->map.script_index[0],
320 planner->map.language_index[0],
321 HB_TAG ('p','r','e','f'),
323 return &_hb_ot_complex_shaper_indic;
325 return &_hb_ot_complex_shaper_default;
327 case HB_SCRIPT_MYANMAR:
328 /* For Myanmar, we only want to use the Myanmar shaper if the "new" script
329 * tag is found. For "old" script tag we want to use the default shaper. */
330 if (planner->map.chosen_script[0] == HB_TAG ('m','y','m','2'))
331 return &_hb_ot_complex_shaper_myanmar;
333 return &_hb_ot_complex_shaper_default;
335 /* Unicode-4.1 additions */
336 case HB_SCRIPT_BUGINESE:
337 case HB_SCRIPT_NEW_TAI_LUE:
339 /* Unicode-5.1 additions */
342 /* Unicode-5.2 additions */
343 case HB_SCRIPT_TAI_THAM:
345 /* If the designer designed the font for the 'DFLT' script,
346 * use the default shaper. Otherwise, use the Indic shaper.
347 * Note that for some simple scripts, there may not be *any*
348 * GSUB/GPOS needed, so there may be no scripts found! */
349 if (planner->map.chosen_script[0] == HB_TAG ('D','F','L','T'))
350 return &_hb_ot_complex_shaper_default;
352 return &_hb_ot_complex_shaper_sea;
357 #endif /* HB_OT_SHAPE_COMPLEX_PRIVATE_HH */