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_HH
28 #define HB_OT_SHAPE_COMPLEX_HH
32 #include "hb-ot-layout.hh"
33 #include "hb-ot-shape.hh"
34 #include "hb-ot-shape-normalize.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 #define HB_OT_SHAPE_COMPLEX_MAX_COMBINING_MARKS 32
44 enum hb_ot_shape_zero_width_marks_type_t {
45 HB_OT_SHAPE_ZERO_WIDTH_MARKS_NONE,
46 HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_GDEF_EARLY,
47 HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_GDEF_LATE
51 /* Master OT shaper list */
52 #define HB_COMPLEX_SHAPERS_IMPLEMENT_SHAPERS \
53 HB_COMPLEX_SHAPER_IMPLEMENT (default) /* should be first */ \
54 HB_COMPLEX_SHAPER_IMPLEMENT (arabic) \
55 HB_COMPLEX_SHAPER_IMPLEMENT (hangul) \
56 HB_COMPLEX_SHAPER_IMPLEMENT (hebrew) \
57 HB_COMPLEX_SHAPER_IMPLEMENT (indic) \
58 HB_COMPLEX_SHAPER_IMPLEMENT (khmer) \
59 HB_COMPLEX_SHAPER_IMPLEMENT (myanmar) \
60 HB_COMPLEX_SHAPER_IMPLEMENT (myanmar_zawgyi) \
61 HB_COMPLEX_SHAPER_IMPLEMENT (thai) \
62 HB_COMPLEX_SHAPER_IMPLEMENT (use) \
63 /* ^--- Add new shapers here */
66 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 nullptr 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 nullptr 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,
150 * If not HB_TAG_NONE, then must match found GPOS script tag for
151 * GPOS to be applied. Otherwise, fallback positioning will be used.
156 * Called during shape().
157 * Shapers can use to modify ordering of combining marks.
160 void (*reorder_marks) (const hb_ot_shape_plan_t *plan,
165 hb_ot_shape_zero_width_marks_type_t zero_width_marks;
167 bool fallback_position;
170 #define HB_COMPLEX_SHAPER_IMPLEMENT(name) extern HB_INTERNAL const hb_ot_complex_shaper_t _hb_ot_complex_shaper_##name;
171 HB_COMPLEX_SHAPERS_IMPLEMENT_SHAPERS
172 #undef HB_COMPLEX_SHAPER_IMPLEMENT
175 static inline const hb_ot_complex_shaper_t *
176 hb_ot_shape_complex_categorize (const hb_ot_shape_planner_t *planner)
178 switch ((hb_tag_t) planner->props.script)
181 return &_hb_ot_complex_shaper_default;
184 /* Unicode-1.1 additions */
185 case HB_SCRIPT_ARABIC:
187 /* Unicode-3.0 additions */
188 case HB_SCRIPT_MONGOLIAN:
189 case HB_SCRIPT_SYRIAC:
191 /* Unicode-5.0 additions */
193 case HB_SCRIPT_PHAGS_PA:
195 /* Unicode-6.0 additions */
196 case HB_SCRIPT_MANDAIC:
198 /* Unicode-7.0 additions */
199 case HB_SCRIPT_MANICHAEAN:
200 case HB_SCRIPT_PSALTER_PAHLAVI:
202 /* Unicode-9.0 additions */
203 case HB_SCRIPT_ADLAM:
205 /* Unicode-11.0 additions */
206 case HB_SCRIPT_HANIFI_ROHINGYA:
207 case HB_SCRIPT_SOGDIAN:
209 /* For Arabic script, use the Arabic shaper even if no OT script tag was found.
210 * This is because we do fallback shaping for Arabic script (and not others).
211 * But note that Arabic shaping is applicable only to horizontal layout; for
212 * vertical text, just use the generic shaper instead. */
213 if ((planner->map.chosen_script[0] != HB_OT_TAG_DEFAULT_SCRIPT ||
214 planner->props.script == HB_SCRIPT_ARABIC) &&
215 HB_DIRECTION_IS_HORIZONTAL(planner->props.direction))
216 return &_hb_ot_complex_shaper_arabic;
218 return &_hb_ot_complex_shaper_default;
221 /* Unicode-1.1 additions */
225 return &_hb_ot_complex_shaper_thai;
228 /* Unicode-1.1 additions */
229 case HB_SCRIPT_HANGUL:
231 return &_hb_ot_complex_shaper_hangul;
234 /* Unicode-1.1 additions */
235 case HB_SCRIPT_HEBREW:
237 return &_hb_ot_complex_shaper_hebrew;
240 /* Unicode-1.1 additions */
241 case HB_SCRIPT_BENGALI:
242 case HB_SCRIPT_DEVANAGARI:
243 case HB_SCRIPT_GUJARATI:
244 case HB_SCRIPT_GURMUKHI:
245 case HB_SCRIPT_KANNADA:
246 case HB_SCRIPT_MALAYALAM:
247 case HB_SCRIPT_ORIYA:
248 case HB_SCRIPT_TAMIL:
249 case HB_SCRIPT_TELUGU:
251 /* Unicode-3.0 additions */
252 case HB_SCRIPT_SINHALA:
254 /* If the designer designed the font for the 'DFLT' script,
255 * (or we ended up arbitrarily pick 'latn'), use the default shaper.
256 * Otherwise, use the specific shaper.
258 * If it's indy3 tag, send to USE. */
259 if (planner->map.chosen_script[0] == HB_TAG ('D','F','L','T') ||
260 planner->map.chosen_script[0] == HB_TAG ('l','a','t','n'))
261 return &_hb_ot_complex_shaper_default;
262 else if ((planner->map.chosen_script[0] & 0x000000FF) == '3')
263 return &_hb_ot_complex_shaper_use;
265 return &_hb_ot_complex_shaper_indic;
267 case HB_SCRIPT_KHMER:
268 return &_hb_ot_complex_shaper_khmer;
270 case HB_SCRIPT_MYANMAR:
271 /* If the designer designed the font for the 'DFLT' script,
272 * (or we ended up arbitrarily pick 'latn'), use the default shaper.
273 * Otherwise, use the specific shaper.
275 * If designer designed for 'mymr' tag, also send to default
276 * shaper. That's tag used from before Myanmar shaping spec
277 * was developed. The shaping spec uses 'mym2' tag. */
278 if (planner->map.chosen_script[0] == HB_TAG ('D','F','L','T') ||
279 planner->map.chosen_script[0] == HB_TAG ('l','a','t','n') ||
280 planner->map.chosen_script[0] == HB_TAG ('m','y','m','r'))
281 return &_hb_ot_complex_shaper_default;
283 return &_hb_ot_complex_shaper_myanmar;
286 /* https://github.com/harfbuzz/harfbuzz/issues/1162 */
287 case HB_SCRIPT_MYANMAR_ZAWGYI:
289 return &_hb_ot_complex_shaper_myanmar_zawgyi;
292 /* Unicode-2.0 additions */
293 case HB_SCRIPT_TIBETAN:
295 /* Unicode-3.0 additions */
296 //case HB_SCRIPT_MONGOLIAN:
297 //case HB_SCRIPT_SINHALA:
299 /* Unicode-3.2 additions */
300 case HB_SCRIPT_BUHID:
301 case HB_SCRIPT_HANUNOO:
302 case HB_SCRIPT_TAGALOG:
303 case HB_SCRIPT_TAGBANWA:
305 /* Unicode-4.0 additions */
306 case HB_SCRIPT_LIMBU:
307 case HB_SCRIPT_TAI_LE:
309 /* Unicode-4.1 additions */
310 case HB_SCRIPT_BUGINESE:
311 case HB_SCRIPT_KHAROSHTHI:
312 case HB_SCRIPT_SYLOTI_NAGRI:
313 case HB_SCRIPT_TIFINAGH:
315 /* Unicode-5.0 additions */
316 case HB_SCRIPT_BALINESE:
317 //case HB_SCRIPT_NKO:
318 //case HB_SCRIPT_PHAGS_PA:
320 /* Unicode-5.1 additions */
322 case HB_SCRIPT_KAYAH_LI:
323 case HB_SCRIPT_LEPCHA:
324 case HB_SCRIPT_REJANG:
325 case HB_SCRIPT_SAURASHTRA:
326 case HB_SCRIPT_SUNDANESE:
328 /* Unicode-5.2 additions */
329 case HB_SCRIPT_EGYPTIAN_HIEROGLYPHS:
330 case HB_SCRIPT_JAVANESE:
331 case HB_SCRIPT_KAITHI:
332 case HB_SCRIPT_MEETEI_MAYEK:
333 case HB_SCRIPT_TAI_THAM:
334 case HB_SCRIPT_TAI_VIET:
336 /* Unicode-6.0 additions */
337 case HB_SCRIPT_BATAK:
338 case HB_SCRIPT_BRAHMI:
339 //case HB_SCRIPT_MANDAIC:
341 /* Unicode-6.1 additions */
342 case HB_SCRIPT_CHAKMA:
343 case HB_SCRIPT_SHARADA:
344 case HB_SCRIPT_TAKRI:
346 /* Unicode-7.0 additions */
347 case HB_SCRIPT_DUPLOYAN:
348 case HB_SCRIPT_GRANTHA:
349 case HB_SCRIPT_KHOJKI:
350 case HB_SCRIPT_KHUDAWADI:
351 case HB_SCRIPT_MAHAJANI:
352 //case HB_SCRIPT_MANICHAEAN:
354 case HB_SCRIPT_PAHAWH_HMONG:
355 //case HB_SCRIPT_PSALTER_PAHLAVI:
356 case HB_SCRIPT_SIDDHAM:
357 case HB_SCRIPT_TIRHUTA:
359 /* Unicode-8.0 additions */
362 /* Unicode-9.0 additions */
363 //case HB_SCRIPT_ADLAM:
364 case HB_SCRIPT_BHAIKSUKI:
365 case HB_SCRIPT_MARCHEN:
368 /* Unicode-10.0 additions */
369 case HB_SCRIPT_MASARAM_GONDI:
370 case HB_SCRIPT_SOYOMBO:
371 case HB_SCRIPT_ZANABAZAR_SQUARE:
373 /* Unicode-11.0 additions */
374 case HB_SCRIPT_DOGRA:
375 case HB_SCRIPT_GUNJALA_GONDI:
376 //case HB_SCRIPT_HANIFI_ROHINGYA:
377 case HB_SCRIPT_MAKASAR:
378 //case HB_SCRIPT_SOGDIAN:
380 /* If the designer designed the font for the 'DFLT' script,
381 * (or we ended up arbitrarily pick 'latn'), use the default shaper.
382 * Otherwise, use the specific shaper.
383 * Note that for some simple scripts, there may not be *any*
384 * GSUB/GPOS needed, so there may be no scripts found! */
385 if (planner->map.chosen_script[0] == HB_TAG ('D','F','L','T') ||
386 planner->map.chosen_script[0] == HB_TAG ('l','a','t','n'))
387 return &_hb_ot_complex_shaper_default;
389 return &_hb_ot_complex_shaper_use;
394 #endif /* HB_OT_SHAPE_COMPLEX_HH */