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_HH
28#define HB_OT_SHAPE_COMPLEX_HH
29
30#include "hb.hh"
31
32#include "hb-ot-layout.hh"
33#include "hb-ot-shape.hh"
34#include "hb-ot-shape-normalize.hh"
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#define HB_OT_SHAPE_COMPLEX_MAX_COMBINING_MARKS 32
43
44enum 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
48};
49
50
51/* Master OT shaper list */
52#define HB_COMPLEX_SHAPERS_IMPLEMENT_SHAPERS \
53 HB_COMPLEX_SHAPER_IMPLEMENT (arabic) \
54 HB_COMPLEX_SHAPER_IMPLEMENT (default) \
55 HB_COMPLEX_SHAPER_IMPLEMENT (dumber) \
56 HB_COMPLEX_SHAPER_IMPLEMENT (hangul) \
57 HB_COMPLEX_SHAPER_IMPLEMENT (hebrew) \
58 HB_COMPLEX_SHAPER_IMPLEMENT (indic) \
59 HB_COMPLEX_SHAPER_IMPLEMENT (khmer) \
60 HB_COMPLEX_SHAPER_IMPLEMENT (myanmar) \
61 HB_COMPLEX_SHAPER_IMPLEMENT (myanmar_zawgyi) \
62 HB_COMPLEX_SHAPER_IMPLEMENT (thai) \
63 HB_COMPLEX_SHAPER_IMPLEMENT (use) \
64 /* ^--- Add new shapers here; keep sorted. */
65
66
67struct hb_ot_complex_shaper_t
68{
69 /* collect_features()
70 * Called during shape_plan().
71 * Shapers should use plan->map to add their features and callbacks.
72 * May be NULL.
73 */
74 void (*collect_features) (hb_ot_shape_planner_t *plan);
75
76 /* override_features()
77 * Called during shape_plan().
78 * Shapers should use plan->map to override features and add callbacks after
79 * common features are added.
80 * May be NULL.
81 */
82 void (*override_features) (hb_ot_shape_planner_t *plan);
83
84
85 /* data_create()
86 * Called at the end of shape_plan().
87 * Whatever shapers return will be accessible through plan->data later.
88 * If nullptr is returned, means a plan failure.
89 */
90 void *(*data_create) (const hb_ot_shape_plan_t *plan);
91
92 /* data_destroy()
93 * Called when the shape_plan is being destroyed.
94 * plan->data is passed here for destruction.
95 * If nullptr is returned, means a plan failure.
96 * May be NULL.
97 */
98 void (*data_destroy) (void *data);
99
100
101 /* preprocess_text()
102 * Called during shape().
103 * Shapers can use to modify text before shaping starts.
104 * May be NULL.
105 */
106 void (*preprocess_text) (const hb_ot_shape_plan_t *plan,
107 hb_buffer_t *buffer,
108 hb_font_t *font);
109
110 /* postprocess_glyphs()
111 * Called during shape().
112 * Shapers can use to modify glyphs after shaping ends.
113 * May be NULL.
114 */
115 void (*postprocess_glyphs) (const hb_ot_shape_plan_t *plan,
116 hb_buffer_t *buffer,
117 hb_font_t *font);
118
119
120 hb_ot_shape_normalization_mode_t normalization_preference;
121
122 /* decompose()
123 * Called during shape()'s normalization.
124 * May be NULL.
125 */
126 bool (*decompose) (const hb_ot_shape_normalize_context_t *c,
127 hb_codepoint_t ab,
128 hb_codepoint_t *a,
129 hb_codepoint_t *b);
130
131 /* compose()
132 * Called during shape()'s normalization.
133 * May be NULL.
134 */
135 bool (*compose) (const hb_ot_shape_normalize_context_t *c,
136 hb_codepoint_t a,
137 hb_codepoint_t b,
138 hb_codepoint_t *ab);
139
140 /* setup_masks()
141 * Called during shape().
142 * Shapers should use map to get feature masks and set on buffer.
143 * Shapers may NOT modify characters.
144 * May be NULL.
145 */
146 void (*setup_masks) (const hb_ot_shape_plan_t *plan,
147 hb_buffer_t *buffer,
148 hb_font_t *font);
149
150 /* gpos_tag()
151 * If not HB_TAG_NONE, then must match found GPOS script tag for
152 * GPOS to be applied. Otherwise, fallback positioning will be used.
153 */
154 hb_tag_t gpos_tag;
155
156 /* reorder_marks()
157 * Called during shape().
158 * Shapers can use to modify ordering of combining marks.
159 * May be NULL.
160 */
161 void (*reorder_marks) (const hb_ot_shape_plan_t *plan,
162 hb_buffer_t *buffer,
163 unsigned int start,
164 unsigned int end);
165
166 hb_ot_shape_zero_width_marks_type_t zero_width_marks;
167
168 bool fallback_position;
169};
170
171#define HB_COMPLEX_SHAPER_IMPLEMENT(name) extern HB_INTERNAL const hb_ot_complex_shaper_t _hb_ot_complex_shaper_##name;
172HB_COMPLEX_SHAPERS_IMPLEMENT_SHAPERS
173#undef HB_COMPLEX_SHAPER_IMPLEMENT
174
175
176static inline const hb_ot_complex_shaper_t *
177hb_ot_shape_complex_categorize (const hb_ot_shape_planner_t *planner)
178{
179 switch ((hb_tag_t) planner->props.script)
180 {
181 default:
182 return &_hb_ot_complex_shaper_default;
183
184
185 /* Unicode-1.1 additions */
186 case HB_SCRIPT_ARABIC:
187
188 /* Unicode-3.0 additions */
189 case HB_SCRIPT_MONGOLIAN:
190 case HB_SCRIPT_SYRIAC:
191
192 /* Unicode-5.0 additions */
193 case HB_SCRIPT_NKO:
194 case HB_SCRIPT_PHAGS_PA:
195
196 /* Unicode-6.0 additions */
197 case HB_SCRIPT_MANDAIC:
198
199 /* Unicode-7.0 additions */
200 case HB_SCRIPT_MANICHAEAN:
201 case HB_SCRIPT_PSALTER_PAHLAVI:
202
203 /* Unicode-9.0 additions */
204 case HB_SCRIPT_ADLAM:
205
206 /* Unicode-11.0 additions */
207 case HB_SCRIPT_HANIFI_ROHINGYA:
208 case HB_SCRIPT_SOGDIAN:
209
210 /* For Arabic script, use the Arabic shaper even if no OT script tag was found.
211 * This is because we do fallback shaping for Arabic script (and not others).
212 * But note that Arabic shaping is applicable only to horizontal layout; for
213 * vertical text, just use the generic shaper instead. */
214 if ((planner->map.chosen_script[0] != HB_OT_TAG_DEFAULT_SCRIPT ||
215 planner->props.script == HB_SCRIPT_ARABIC) &&
216 HB_DIRECTION_IS_HORIZONTAL(planner->props.direction))
217 return &_hb_ot_complex_shaper_arabic;
218 else
219 return &_hb_ot_complex_shaper_default;
220
221
222 /* Unicode-1.1 additions */
223 case HB_SCRIPT_THAI:
224 case HB_SCRIPT_LAO:
225
226 return &_hb_ot_complex_shaper_thai;
227
228
229 /* Unicode-1.1 additions */
230 case HB_SCRIPT_HANGUL:
231
232 return &_hb_ot_complex_shaper_hangul;
233
234
235 /* Unicode-1.1 additions */
236 case HB_SCRIPT_HEBREW:
237
238 return &_hb_ot_complex_shaper_hebrew;
239
240
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:
251
252 /* Unicode-3.0 additions */
253 case HB_SCRIPT_SINHALA:
254
255 /* If the designer designed the font for the 'DFLT' script,
256 * (or we ended up arbitrarily pick 'latn'), use the default shaper.
257 * Otherwise, use the specific shaper.
258 *
259 * If it's indy3 tag, send to USE. */
260 if (planner->map.chosen_script[0] == HB_TAG ('D','F','L','T') ||
261 planner->map.chosen_script[0] == HB_TAG ('l','a','t','n'))
262 return &_hb_ot_complex_shaper_default;
263 else if ((planner->map.chosen_script[0] & 0x000000FF) == '3')
264 return &_hb_ot_complex_shaper_use;
265 else
266 return &_hb_ot_complex_shaper_indic;
267
268 case HB_SCRIPT_KHMER:
269 return &_hb_ot_complex_shaper_khmer;
270
271 case HB_SCRIPT_MYANMAR:
272 /* If the designer designed the font for the 'DFLT' script,
273 * (or we ended up arbitrarily pick 'latn'), use the default shaper.
274 * Otherwise, use the specific shaper.
275 *
276 * If designer designed for 'mymr' tag, also send to default
277 * shaper. That's tag used from before Myanmar shaping spec
278 * was developed. The shaping spec uses 'mym2' tag. */
279 if (planner->map.chosen_script[0] == HB_TAG ('D','F','L','T') ||
280 planner->map.chosen_script[0] == HB_TAG ('l','a','t','n') ||
281 planner->map.chosen_script[0] == HB_TAG ('m','y','m','r'))
282 return &_hb_ot_complex_shaper_default;
283 else
284 return &_hb_ot_complex_shaper_myanmar;
285
286
287 /* https://github.com/harfbuzz/harfbuzz/issues/1162 */
288 case HB_SCRIPT_MYANMAR_ZAWGYI:
289
290 return &_hb_ot_complex_shaper_myanmar_zawgyi;
291
292
293 /* Unicode-2.0 additions */
294 case HB_SCRIPT_TIBETAN:
295
296 /* Unicode-3.0 additions */
297 //case HB_SCRIPT_MONGOLIAN:
298 //case HB_SCRIPT_SINHALA:
299
300 /* Unicode-3.2 additions */
301 case HB_SCRIPT_BUHID:
302 case HB_SCRIPT_HANUNOO:
303 case HB_SCRIPT_TAGALOG:
304 case HB_SCRIPT_TAGBANWA:
305
306 /* Unicode-4.0 additions */
307 case HB_SCRIPT_LIMBU:
308 case HB_SCRIPT_TAI_LE:
309
310 /* Unicode-4.1 additions */
311 case HB_SCRIPT_BUGINESE:
312 case HB_SCRIPT_KHAROSHTHI:
313 case HB_SCRIPT_SYLOTI_NAGRI:
314 case HB_SCRIPT_TIFINAGH:
315
316 /* Unicode-5.0 additions */
317 case HB_SCRIPT_BALINESE:
318 //case HB_SCRIPT_NKO:
319 //case HB_SCRIPT_PHAGS_PA:
320
321 /* Unicode-5.1 additions */
322 case HB_SCRIPT_CHAM:
323 case HB_SCRIPT_KAYAH_LI:
324 case HB_SCRIPT_LEPCHA:
325 case HB_SCRIPT_REJANG:
326 case HB_SCRIPT_SAURASHTRA:
327 case HB_SCRIPT_SUNDANESE:
328
329 /* Unicode-5.2 additions */
330 case HB_SCRIPT_EGYPTIAN_HIEROGLYPHS:
331 case HB_SCRIPT_JAVANESE:
332 case HB_SCRIPT_KAITHI:
333 case HB_SCRIPT_MEETEI_MAYEK:
334 case HB_SCRIPT_TAI_THAM:
335 case HB_SCRIPT_TAI_VIET:
336
337 /* Unicode-6.0 additions */
338 case HB_SCRIPT_BATAK:
339 case HB_SCRIPT_BRAHMI:
340 //case HB_SCRIPT_MANDAIC:
341
342 /* Unicode-6.1 additions */
343 case HB_SCRIPT_CHAKMA:
344 case HB_SCRIPT_SHARADA:
345 case HB_SCRIPT_TAKRI:
346
347 /* Unicode-7.0 additions */
348 case HB_SCRIPT_DUPLOYAN:
349 case HB_SCRIPT_GRANTHA:
350 case HB_SCRIPT_KHOJKI:
351 case HB_SCRIPT_KHUDAWADI:
352 case HB_SCRIPT_MAHAJANI:
353 //case HB_SCRIPT_MANICHAEAN:
354 case HB_SCRIPT_MODI:
355 case HB_SCRIPT_PAHAWH_HMONG:
356 //case HB_SCRIPT_PSALTER_PAHLAVI:
357 case HB_SCRIPT_SIDDHAM:
358 case HB_SCRIPT_TIRHUTA:
359
360 /* Unicode-8.0 additions */
361 case HB_SCRIPT_AHOM:
362
363 /* Unicode-9.0 additions */
364 //case HB_SCRIPT_ADLAM:
365 case HB_SCRIPT_BHAIKSUKI:
366 case HB_SCRIPT_MARCHEN:
367 case HB_SCRIPT_NEWA:
368
369 /* Unicode-10.0 additions */
370 case HB_SCRIPT_MASARAM_GONDI:
371 case HB_SCRIPT_SOYOMBO:
372 case HB_SCRIPT_ZANABAZAR_SQUARE:
373
374 /* Unicode-11.0 additions */
375 case HB_SCRIPT_DOGRA:
376 case HB_SCRIPT_GUNJALA_GONDI:
377 //case HB_SCRIPT_HANIFI_ROHINGYA:
378 case HB_SCRIPT_MAKASAR:
379 //case HB_SCRIPT_SOGDIAN:
380
381 /* Unicode-12.0 additions */
382 case HB_SCRIPT_NANDINAGARI:
383
384 /* Unicode-13.0 additions */
385 case HB_SCRIPT_CHORASMIAN:
386 case HB_SCRIPT_DIVES_AKURU:
387
388 /* If the designer designed the font for the 'DFLT' script,
389 * (or we ended up arbitrarily pick 'latn'), use the default shaper.
390 * Otherwise, use the specific shaper.
391 * Note that for some simple scripts, there may not be *any*
392 * GSUB/GPOS needed, so there may be no scripts found! */
393 if (planner->map.chosen_script[0] == HB_TAG ('D','F','L','T') ||
394 planner->map.chosen_script[0] == HB_TAG ('l','a','t','n'))
395 return &_hb_ot_complex_shaper_default;
396 else
397 return &_hb_ot_complex_shaper_use;
398 }
399}
400
401
402#endif /* HB_OT_SHAPE_COMPLEX_HH */
403