Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / harfbuzz-ng / src / hb-ot-shape-complex-private.hh
blob8d03dee51f19c1ef9218c3cfa1900b8f8dc9b2a7
1 /*
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
16 * DAMAGE.
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 (myanmar_old) \
60 HB_COMPLEX_SHAPER_IMPLEMENT (indic) \
61 HB_COMPLEX_SHAPER_IMPLEMENT (myanmar) \
62 HB_COMPLEX_SHAPER_IMPLEMENT (thai) \
63 HB_COMPLEX_SHAPER_IMPLEMENT (tibetan) \
64 HB_COMPLEX_SHAPER_IMPLEMENT (use) \
65 /* ^--- Add new shapers here */
68 struct hb_ot_complex_shaper_t
70 char name[8];
72 /* collect_features()
73 * Called during shape_plan().
74 * Shapers should use plan->map to add their features and callbacks.
75 * May be NULL.
77 void (*collect_features) (hb_ot_shape_planner_t *plan);
79 /* override_features()
80 * Called during shape_plan().
81 * Shapers should use plan->map to override features and add callbacks after
82 * common features are added.
83 * May be NULL.
85 void (*override_features) (hb_ot_shape_planner_t *plan);
88 /* data_create()
89 * Called at the end of shape_plan().
90 * Whatever shapers return will be accessible through plan->data later.
91 * If NULL is returned, means a plan failure.
93 void *(*data_create) (const hb_ot_shape_plan_t *plan);
95 /* data_destroy()
96 * Called when the shape_plan is being destroyed.
97 * plan->data is passed here for destruction.
98 * If NULL is returned, means a plan failure.
99 * May be NULL.
101 void (*data_destroy) (void *data);
104 /* preprocess_text()
105 * Called during shape().
106 * Shapers can use to modify text before shaping starts.
107 * May be NULL.
109 void (*preprocess_text) (const hb_ot_shape_plan_t *plan,
110 hb_buffer_t *buffer,
111 hb_font_t *font);
114 hb_ot_shape_normalization_mode_t normalization_preference;
116 /* decompose()
117 * Called during shape()'s normalization.
118 * May be NULL.
120 bool (*decompose) (const hb_ot_shape_normalize_context_t *c,
121 hb_codepoint_t ab,
122 hb_codepoint_t *a,
123 hb_codepoint_t *b);
125 /* compose()
126 * Called during shape()'s normalization.
127 * May be NULL.
129 bool (*compose) (const hb_ot_shape_normalize_context_t *c,
130 hb_codepoint_t a,
131 hb_codepoint_t b,
132 hb_codepoint_t *ab);
134 /* setup_masks()
135 * Called during shape().
136 * Shapers should use map to get feature masks and set on buffer.
137 * Shapers may NOT modify characters.
138 * May be NULL.
140 void (*setup_masks) (const hb_ot_shape_plan_t *plan,
141 hb_buffer_t *buffer,
142 hb_font_t *font);
144 hb_ot_shape_zero_width_marks_type_t zero_width_marks;
146 bool fallback_position;
149 #define HB_COMPLEX_SHAPER_IMPLEMENT(name) extern HB_INTERNAL const hb_ot_complex_shaper_t _hb_ot_complex_shaper_##name;
150 HB_COMPLEX_SHAPERS_IMPLEMENT_SHAPERS
151 #undef HB_COMPLEX_SHAPER_IMPLEMENT
154 static inline const hb_ot_complex_shaper_t *
155 hb_ot_shape_complex_categorize (const hb_ot_shape_planner_t *planner)
157 switch ((hb_tag_t) planner->props.script)
159 default:
160 return &_hb_ot_complex_shaper_default;
163 /* Unicode-1.1 additions */
164 case HB_SCRIPT_ARABIC:
166 /* Unicode-3.0 additions */
167 case HB_SCRIPT_MONGOLIAN:
168 case HB_SCRIPT_SYRIAC:
170 /* Unicode-5.0 additions */
171 case HB_SCRIPT_NKO:
172 case HB_SCRIPT_PHAGS_PA:
174 /* Unicode-6.0 additions */
175 case HB_SCRIPT_MANDAIC:
177 /* Unicode-7.0 additions */
178 case HB_SCRIPT_MANICHAEAN:
179 case HB_SCRIPT_PSALTER_PAHLAVI:
181 /* For Arabic script, use the Arabic shaper even if no OT script tag was found.
182 * This is because we do fallback shaping for Arabic script (and not others).
183 * But note that Arabic shaping is applicable only to horizontal layout; for
184 * vertical text, just use the generic shaper instead. */
185 if ((planner->map.chosen_script[0] != HB_OT_TAG_DEFAULT_SCRIPT ||
186 planner->props.script == HB_SCRIPT_ARABIC) &&
187 HB_DIRECTION_IS_HORIZONTAL(planner->props.direction))
188 return &_hb_ot_complex_shaper_arabic;
189 else
190 return &_hb_ot_complex_shaper_default;
193 /* Unicode-1.1 additions */
194 case HB_SCRIPT_THAI:
195 case HB_SCRIPT_LAO:
197 return &_hb_ot_complex_shaper_thai;
200 /* Unicode-1.1 additions */
201 case HB_SCRIPT_HANGUL:
203 return &_hb_ot_complex_shaper_hangul;
206 /* Unicode-2.0 additions */
207 case HB_SCRIPT_TIBETAN:
209 return &_hb_ot_complex_shaper_tibetan;
212 /* Unicode-1.1 additions */
213 case HB_SCRIPT_HEBREW:
215 return &_hb_ot_complex_shaper_hebrew;
218 /* ^--- Add new shapers here */
220 #if 0
221 /* Unicode-4.1 additions */
222 case HB_SCRIPT_NEW_TAI_LUE:
223 #endif
225 /* Unicode-1.1 additions */
226 case HB_SCRIPT_BENGALI:
227 case HB_SCRIPT_DEVANAGARI:
228 case HB_SCRIPT_GUJARATI:
229 case HB_SCRIPT_GURMUKHI:
230 case HB_SCRIPT_KANNADA:
231 case HB_SCRIPT_MALAYALAM:
232 case HB_SCRIPT_ORIYA:
233 case HB_SCRIPT_TAMIL:
234 case HB_SCRIPT_TELUGU:
236 /* Unicode-3.0 additions */
237 case HB_SCRIPT_SINHALA:
239 /* Unicode-5.2 additions */
240 case HB_SCRIPT_JAVANESE:
242 /* If the designer designed the font for the 'DFLT' script,
243 * use the default shaper. Otherwise, use the specific shaper.
244 * Note that for some simple scripts, there may not be *any*
245 * GSUB/GPOS needed, so there may be no scripts found! */
246 if (planner->map.chosen_script[0] == HB_TAG ('D','F','L','T'))
247 return &_hb_ot_complex_shaper_default;
248 else
249 return &_hb_ot_complex_shaper_indic;
251 case HB_SCRIPT_KHMER:
252 /* A number of Khmer fonts in the wild don't have a 'pref' feature,
253 * and as such won't shape properly via the Indic shaper;
254 * however, they typically have 'liga' / 'clig' features that implement
255 * the necessary "reordering" by means of ligature substitutions.
256 * So we send such pref-less fonts through the generic shaper instead. */
257 if (planner->map.found_script[0] &&
258 hb_ot_layout_language_find_feature (planner->face, HB_OT_TAG_GSUB,
259 planner->map.script_index[0],
260 planner->map.language_index[0],
261 HB_TAG ('p','r','e','f'),
262 NULL))
263 return &_hb_ot_complex_shaper_indic;
264 else
265 return &_hb_ot_complex_shaper_default;
267 case HB_SCRIPT_MYANMAR:
268 if (planner->map.chosen_script[0] == HB_TAG ('m','y','m','2'))
269 return &_hb_ot_complex_shaper_myanmar;
270 else if (planner->map.chosen_script[0] == HB_TAG ('m','y','m','r'))
271 return &_hb_ot_complex_shaper_myanmar_old;
272 else
273 return &_hb_ot_complex_shaper_default;
276 /* Unicode-2.0 additions */
277 //case HB_SCRIPT_TIBETAN:
279 /* Unicode-3.0 additions */
280 //case HB_SCRIPT_MONGOLIAN:
281 //case HB_SCRIPT_SINHALA:
283 /* Unicode-3.2 additions */
284 case HB_SCRIPT_BUHID:
285 case HB_SCRIPT_HANUNOO:
286 case HB_SCRIPT_TAGALOG:
287 case HB_SCRIPT_TAGBANWA:
289 /* Unicode-4.0 additions */
290 case HB_SCRIPT_LIMBU:
291 case HB_SCRIPT_TAI_LE:
293 /* Unicode-4.1 additions */
294 case HB_SCRIPT_BUGINESE:
295 case HB_SCRIPT_KHAROSHTHI:
296 case HB_SCRIPT_SYLOTI_NAGRI:
297 case HB_SCRIPT_TIFINAGH:
299 /* Unicode-5.0 additions */
300 case HB_SCRIPT_BALINESE:
301 //case HB_SCRIPT_NKO:
302 //case HB_SCRIPT_PHAGS_PA:
304 /* Unicode-5.1 additions */
305 case HB_SCRIPT_CHAM:
306 case HB_SCRIPT_KAYAH_LI:
307 case HB_SCRIPT_LEPCHA:
308 case HB_SCRIPT_REJANG:
309 case HB_SCRIPT_SAURASHTRA:
310 case HB_SCRIPT_SUNDANESE:
312 /* Unicode-5.2 additions */
313 case HB_SCRIPT_EGYPTIAN_HIEROGLYPHS:
314 //case HB_SCRIPT_JAVANESE:
315 case HB_SCRIPT_KAITHI:
316 case HB_SCRIPT_MEETEI_MAYEK:
317 case HB_SCRIPT_TAI_THAM:
318 case HB_SCRIPT_TAI_VIET:
320 /* Unicode-6.0 additions */
321 case HB_SCRIPT_BATAK:
322 case HB_SCRIPT_BRAHMI:
323 //case HB_SCRIPT_MANDAIC:
325 /* Unicode-6.1 additions */
326 case HB_SCRIPT_CHAKMA:
327 case HB_SCRIPT_SHARADA:
328 case HB_SCRIPT_TAKRI:
330 /* Unicode-7.0 additions */
331 case HB_SCRIPT_DUPLOYAN:
332 case HB_SCRIPT_GRANTHA:
333 case HB_SCRIPT_KHOJKI:
334 case HB_SCRIPT_KHUDAWADI:
335 case HB_SCRIPT_MAHAJANI:
336 //case HB_SCRIPT_MANICHAEAN:
337 case HB_SCRIPT_MODI:
338 case HB_SCRIPT_PAHAWH_HMONG:
339 //case HB_SCRIPT_PSALTER_PAHLAVI:
340 case HB_SCRIPT_SIDDHAM:
341 case HB_SCRIPT_TIRHUTA:
343 /* If the designer designed the font for the 'DFLT' script,
344 * use the default shaper. Otherwise, use the specific shaper.
345 * Note that for some simple scripts, there may not be *any*
346 * GSUB/GPOS needed, so there may be no scripts found! */
347 if (planner->map.chosen_script[0] == HB_TAG ('D','F','L','T'))
348 return &_hb_ot_complex_shaper_default;
349 else
350 return &_hb_ot_complex_shaper_use;
355 #endif /* HB_OT_SHAPE_COMPLEX_PRIVATE_HH */