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_GDEF_EARLY,
45 HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_GDEF_LATE
49 /* Master OT shaper list */
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 (hangul) \
54 HB_COMPLEX_SHAPER_IMPLEMENT (hebrew) \
55 HB_COMPLEX_SHAPER_IMPLEMENT (myanmar_old) \
56 HB_COMPLEX_SHAPER_IMPLEMENT (indic) \
57 HB_COMPLEX_SHAPER_IMPLEMENT (myanmar) \
58 HB_COMPLEX_SHAPER_IMPLEMENT (thai) \
59 HB_COMPLEX_SHAPER_IMPLEMENT (tibetan) \
60 HB_COMPLEX_SHAPER_IMPLEMENT (use) \
61 /* ^--- Add new shapers here */
64 struct hb_ot_complex_shaper_t
69 * Called during shape_plan().
70 * Shapers should use plan->map to add their features and callbacks.
73 void (*collect_features) (hb_ot_shape_planner_t *plan);
75 /* override_features()
76 * Called during shape_plan().
77 * Shapers should use plan->map to override features and add callbacks after
78 * common features are added.
81 void (*override_features) (hb_ot_shape_planner_t *plan);
85 * Called at the end of shape_plan().
86 * Whatever shapers return will be accessible through plan->data later.
87 * If NULL is returned, means a plan failure.
89 void *(*data_create) (const hb_ot_shape_plan_t *plan);
92 * Called when the shape_plan is being destroyed.
93 * plan->data is passed here for destruction.
94 * If NULL is returned, means a plan failure.
97 void (*data_destroy) (void *data);
101 * Called during shape().
102 * Shapers can use to modify text before shaping starts.
105 void (*preprocess_text) (const hb_ot_shape_plan_t *plan,
109 /* postprocess_glyphs()
110 * Called during shape().
111 * Shapers can use to modify glyphs after shaping ends.
114 void (*postprocess_glyphs) (const hb_ot_shape_plan_t *plan,
119 hb_ot_shape_normalization_mode_t normalization_preference;
122 * Called during shape()'s normalization.
125 bool (*decompose) (const hb_ot_shape_normalize_context_t *c,
131 * Called during shape()'s normalization.
134 bool (*compose) (const hb_ot_shape_normalize_context_t *c,
140 * Called during shape().
141 * Shapers should use map to get feature masks and set on buffer.
142 * Shapers may NOT modify characters.
145 void (*setup_masks) (const hb_ot_shape_plan_t *plan,
149 hb_ot_shape_zero_width_marks_type_t zero_width_marks;
151 bool fallback_position;
154 #define HB_COMPLEX_SHAPER_IMPLEMENT(name) extern HB_INTERNAL const hb_ot_complex_shaper_t _hb_ot_complex_shaper_##name;
155 HB_COMPLEX_SHAPERS_IMPLEMENT_SHAPERS
156 #undef HB_COMPLEX_SHAPER_IMPLEMENT
159 static inline const hb_ot_complex_shaper_t *
160 hb_ot_shape_complex_categorize (const hb_ot_shape_planner_t *planner)
162 switch ((hb_tag_t) planner->props.script)
165 return &_hb_ot_complex_shaper_default;
168 /* Unicode-1.1 additions */
169 case HB_SCRIPT_ARABIC:
171 /* Unicode-3.0 additions */
172 case HB_SCRIPT_MONGOLIAN:
173 case HB_SCRIPT_SYRIAC:
175 /* Unicode-5.0 additions */
177 case HB_SCRIPT_PHAGS_PA:
179 /* Unicode-6.0 additions */
180 case HB_SCRIPT_MANDAIC:
182 /* Unicode-7.0 additions */
183 case HB_SCRIPT_MANICHAEAN:
184 case HB_SCRIPT_PSALTER_PAHLAVI:
186 /* For Arabic script, use the Arabic shaper even if no OT script tag was found.
187 * This is because we do fallback shaping for Arabic script (and not others).
188 * But note that Arabic shaping is applicable only to horizontal layout; for
189 * vertical text, just use the generic shaper instead. */
190 if ((planner->map.chosen_script[0] != HB_OT_TAG_DEFAULT_SCRIPT ||
191 planner->props.script == HB_SCRIPT_ARABIC) &&
192 HB_DIRECTION_IS_HORIZONTAL(planner->props.direction))
193 return &_hb_ot_complex_shaper_arabic;
195 return &_hb_ot_complex_shaper_default;
198 /* Unicode-1.1 additions */
202 return &_hb_ot_complex_shaper_thai;
205 /* Unicode-1.1 additions */
206 case HB_SCRIPT_HANGUL:
208 return &_hb_ot_complex_shaper_hangul;
211 /* Unicode-2.0 additions */
212 case HB_SCRIPT_TIBETAN:
214 return &_hb_ot_complex_shaper_tibetan;
217 /* Unicode-1.1 additions */
218 case HB_SCRIPT_HEBREW:
220 return &_hb_ot_complex_shaper_hebrew;
223 /* ^--- Add new shapers here */
226 /* Unicode-4.1 additions */
227 case HB_SCRIPT_NEW_TAI_LUE:
230 /* Unicode-1.1 additions */
231 case HB_SCRIPT_BENGALI:
232 case HB_SCRIPT_DEVANAGARI:
233 case HB_SCRIPT_GUJARATI:
234 case HB_SCRIPT_GURMUKHI:
235 case HB_SCRIPT_KANNADA:
236 case HB_SCRIPT_MALAYALAM:
237 case HB_SCRIPT_ORIYA:
238 case HB_SCRIPT_TAMIL:
239 case HB_SCRIPT_TELUGU:
241 /* Unicode-3.0 additions */
242 case HB_SCRIPT_SINHALA:
244 /* Unicode-5.2 additions */
245 case HB_SCRIPT_JAVANESE:
247 /* If the designer designed the font for the 'DFLT' script,
248 * use the default shaper. Otherwise, use the specific shaper.
249 * Note that for some simple scripts, there may not be *any*
250 * GSUB/GPOS needed, so there may be no scripts found! */
251 if (planner->map.chosen_script[0] == HB_TAG ('D','F','L','T'))
252 return &_hb_ot_complex_shaper_default;
254 return &_hb_ot_complex_shaper_indic;
256 case HB_SCRIPT_KHMER:
257 /* A number of Khmer fonts in the wild don't have a 'pref' feature,
258 * and as such won't shape properly via the Indic shaper;
259 * however, they typically have 'liga' / 'clig' features that implement
260 * the necessary "reordering" by means of ligature substitutions.
261 * So we send such pref-less fonts through the generic shaper instead. */
262 if (planner->map.found_script[0] &&
263 hb_ot_layout_language_find_feature (planner->face, HB_OT_TAG_GSUB,
264 planner->map.script_index[0],
265 planner->map.language_index[0],
266 HB_TAG ('p','r','e','f'),
268 return &_hb_ot_complex_shaper_indic;
270 return &_hb_ot_complex_shaper_default;
272 case HB_SCRIPT_MYANMAR:
273 if (planner->map.chosen_script[0] == HB_TAG ('m','y','m','2'))
274 return &_hb_ot_complex_shaper_myanmar;
275 else if (planner->map.chosen_script[0] == HB_TAG ('m','y','m','r'))
276 return &_hb_ot_complex_shaper_myanmar_old;
278 return &_hb_ot_complex_shaper_default;
281 /* Unicode-2.0 additions */
282 //case HB_SCRIPT_TIBETAN:
284 /* Unicode-3.0 additions */
285 //case HB_SCRIPT_MONGOLIAN:
286 //case HB_SCRIPT_SINHALA:
288 /* Unicode-3.2 additions */
289 case HB_SCRIPT_BUHID:
290 case HB_SCRIPT_HANUNOO:
291 case HB_SCRIPT_TAGALOG:
292 case HB_SCRIPT_TAGBANWA:
294 /* Unicode-4.0 additions */
295 case HB_SCRIPT_LIMBU:
296 case HB_SCRIPT_TAI_LE:
298 /* Unicode-4.1 additions */
299 case HB_SCRIPT_BUGINESE:
300 case HB_SCRIPT_KHAROSHTHI:
301 case HB_SCRIPT_SYLOTI_NAGRI:
302 case HB_SCRIPT_TIFINAGH:
304 /* Unicode-5.0 additions */
305 case HB_SCRIPT_BALINESE:
306 //case HB_SCRIPT_NKO:
307 //case HB_SCRIPT_PHAGS_PA:
309 /* Unicode-5.1 additions */
311 case HB_SCRIPT_KAYAH_LI:
312 case HB_SCRIPT_LEPCHA:
313 case HB_SCRIPT_REJANG:
314 case HB_SCRIPT_SAURASHTRA:
315 case HB_SCRIPT_SUNDANESE:
317 /* Unicode-5.2 additions */
318 case HB_SCRIPT_EGYPTIAN_HIEROGLYPHS:
319 //case HB_SCRIPT_JAVANESE:
320 case HB_SCRIPT_KAITHI:
321 case HB_SCRIPT_MEETEI_MAYEK:
322 case HB_SCRIPT_TAI_THAM:
323 case HB_SCRIPT_TAI_VIET:
325 /* Unicode-6.0 additions */
326 case HB_SCRIPT_BATAK:
327 case HB_SCRIPT_BRAHMI:
328 //case HB_SCRIPT_MANDAIC:
330 /* Unicode-6.1 additions */
331 case HB_SCRIPT_CHAKMA:
332 case HB_SCRIPT_SHARADA:
333 case HB_SCRIPT_TAKRI:
335 /* Unicode-7.0 additions */
336 case HB_SCRIPT_DUPLOYAN:
337 case HB_SCRIPT_GRANTHA:
338 case HB_SCRIPT_KHOJKI:
339 case HB_SCRIPT_KHUDAWADI:
340 case HB_SCRIPT_MAHAJANI:
341 //case HB_SCRIPT_MANICHAEAN:
343 case HB_SCRIPT_PAHAWH_HMONG:
344 //case HB_SCRIPT_PSALTER_PAHLAVI:
345 case HB_SCRIPT_SIDDHAM:
346 case HB_SCRIPT_TIRHUTA:
348 /* If the designer designed the font for the 'DFLT' script,
349 * use the default shaper. Otherwise, use the specific shaper.
350 * Note that for some simple scripts, there may not be *any*
351 * GSUB/GPOS needed, so there may be no scripts found! */
352 if (planner->map.chosen_script[0] == HB_TAG ('D','F','L','T'))
353 return &_hb_ot_complex_shaper_default;
355 return &_hb_ot_complex_shaper_use;
360 #endif /* HB_OT_SHAPE_COMPLEX_PRIVATE_HH */