cc: Added inline to Tile::IsReadyToDraw
[chromium-blink-merge.git] / third_party / harfbuzz-ng / src / hb-ot-shape-complex-private.hh
blob62151baa512a7f0eaa68c615fc746bfa1ff6fd66
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
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 (indic) \
56 HB_COMPLEX_SHAPER_IMPLEMENT (myanmar) \
57 HB_COMPLEX_SHAPER_IMPLEMENT (sea) \
58 HB_COMPLEX_SHAPER_IMPLEMENT (thai) \
59 /* ^--- Add new shapers here */
62 struct hb_ot_complex_shaper_t
64 char name[8];
66 /* collect_features()
67 * Called during shape_plan().
68 * Shapers should use plan->map to add their features and callbacks.
69 * May be NULL.
71 void (*collect_features) (hb_ot_shape_planner_t *plan);
73 /* override_features()
74 * Called during shape_plan().
75 * Shapers should use plan->map to override features and add callbacks after
76 * common features are added.
77 * May be NULL.
79 void (*override_features) (hb_ot_shape_planner_t *plan);
82 /* data_create()
83 * Called at the end of shape_plan().
84 * Whatever shapers return will be accessible through plan->data later.
85 * If NULL is returned, means a plan failure.
87 void *(*data_create) (const hb_ot_shape_plan_t *plan);
89 /* data_destroy()
90 * Called when the shape_plan is being destroyed.
91 * plan->data is passed here for destruction.
92 * If NULL is returned, means a plan failure.
93 * May be NULL.
95 void (*data_destroy) (void *data);
98 /* preprocess_text()
99 * Called during shape().
100 * Shapers can use to modify text before shaping starts.
101 * May be NULL.
103 void (*preprocess_text) (const hb_ot_shape_plan_t *plan,
104 hb_buffer_t *buffer,
105 hb_font_t *font);
108 /* normalization_preference()
109 * Called during shape().
110 * May be NULL.
112 hb_ot_shape_normalization_mode_t
113 (*normalization_preference) (const hb_segment_properties_t *props);
115 /* decompose()
116 * Called during shape()'s normalization.
117 * May be NULL.
119 bool (*decompose) (const hb_ot_shape_normalize_context_t *c,
120 hb_codepoint_t ab,
121 hb_codepoint_t *a,
122 hb_codepoint_t *b);
124 /* compose()
125 * Called during shape()'s normalization.
126 * May be NULL.
128 bool (*compose) (const hb_ot_shape_normalize_context_t *c,
129 hb_codepoint_t a,
130 hb_codepoint_t b,
131 hb_codepoint_t *ab);
133 /* setup_masks()
134 * Called during shape().
135 * Shapers should use map to get feature masks and set on buffer.
136 * Shapers may NOT modify characters.
137 * May be NULL.
139 void (*setup_masks) (const hb_ot_shape_plan_t *plan,
140 hb_buffer_t *buffer,
141 hb_font_t *font);
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)
158 default:
159 return &_hb_ot_complex_shaper_default;
162 /* Unicode-1.1 additions */
163 case HB_SCRIPT_ARABIC:
164 case HB_SCRIPT_MONGOLIAN:
165 case HB_SCRIPT_SYRIAC:
167 /* Unicode-5.0 additions */
168 case HB_SCRIPT_NKO:
169 case HB_SCRIPT_PHAGS_PA:
171 /* Unicode-6.0 additions */
172 case HB_SCRIPT_MANDAIC:
174 /* For Arabic script, use the Arabic shaper even if no OT script tag was found.
175 * This is because we do fallback shaping for Arabic script (and not others). */
176 if (planner->map.chosen_script[0] != HB_OT_TAG_DEFAULT_SCRIPT ||
177 planner->props.script == HB_SCRIPT_ARABIC)
178 return &_hb_ot_complex_shaper_arabic;
179 else
180 return &_hb_ot_complex_shaper_default;
183 /* Unicode-1.1 additions */
184 case HB_SCRIPT_THAI:
185 case HB_SCRIPT_LAO:
187 return &_hb_ot_complex_shaper_thai;
190 #if 0
191 /* Note:
192 * Currently we don't have a separate Hangul shaper. The default shaper handles
193 * Hangul by enabling jamo features. We may want to implement a separate shaper
194 * in the future. See this thread for details of what such a shaper would do:
196 * http://lists.freedesktop.org/archives/harfbuzz/2013-April/003070.html
198 /* Unicode-1.1 additions */
199 case HB_SCRIPT_HANGUL:
201 return &_hb_ot_complex_shaper_hangul;
202 #endif
205 /* ^--- Add new shapers here */
208 #if 0
209 /* Note:
211 * These disabled scripts are listed in ucd/IndicSyllabicCategory.txt, but according
212 * to Martin Hosken and Jonathan Kew do not require complex shaping.
214 * TODO We should automate figuring out which scripts do not need complex shaping
216 * TODO We currently keep data for these scripts in our indic table. Need to fix the
217 * generator to not do that.
221 /* Simple? */
223 /* Unicode-3.2 additions */
224 case HB_SCRIPT_BUHID:
225 case HB_SCRIPT_HANUNOO:
227 /* Unicode-5.1 additions */
228 case HB_SCRIPT_SAURASHTRA:
230 /* Unicode-6.0 additions */
231 case HB_SCRIPT_BATAK:
232 case HB_SCRIPT_BRAHMI:
235 /* Simple */
237 /* Unicode-1.1 additions */
238 /* These have their own shaper now. */
239 case HB_SCRIPT_LAO:
240 case HB_SCRIPT_THAI:
242 /* Unicode-2.0 additions */
243 case HB_SCRIPT_TIBETAN:
245 /* Unicode-3.2 additions */
246 case HB_SCRIPT_TAGALOG:
247 case HB_SCRIPT_TAGBANWA:
249 /* Unicode-4.0 additions */
250 case HB_SCRIPT_LIMBU:
251 case HB_SCRIPT_TAI_LE:
253 /* Unicode-4.1 additions */
254 case HB_SCRIPT_KHAROSHTHI:
255 case HB_SCRIPT_SYLOTI_NAGRI:
257 /* Unicode-5.1 additions */
258 case HB_SCRIPT_KAYAH_LI:
260 /* Unicode-5.2 additions */
261 case HB_SCRIPT_TAI_VIET:
264 #endif
266 /* Unicode-1.1 additions */
267 case HB_SCRIPT_BENGALI:
268 case HB_SCRIPT_DEVANAGARI:
269 case HB_SCRIPT_GUJARATI:
270 case HB_SCRIPT_GURMUKHI:
271 case HB_SCRIPT_KANNADA:
272 case HB_SCRIPT_MALAYALAM:
273 case HB_SCRIPT_ORIYA:
274 case HB_SCRIPT_TAMIL:
275 case HB_SCRIPT_TELUGU:
277 /* Unicode-3.0 additions */
278 case HB_SCRIPT_SINHALA:
280 /* Unicode-4.1 additions */
281 case HB_SCRIPT_BUGINESE:
283 /* Unicode-5.0 additions */
284 case HB_SCRIPT_BALINESE:
286 /* Unicode-5.1 additions */
287 case HB_SCRIPT_LEPCHA:
288 case HB_SCRIPT_REJANG:
289 case HB_SCRIPT_SUNDANESE:
291 /* Unicode-5.2 additions */
292 case HB_SCRIPT_JAVANESE:
293 case HB_SCRIPT_KAITHI:
294 case HB_SCRIPT_MEETEI_MAYEK:
296 /* Unicode-6.0 additions */
298 /* Unicode-6.1 additions */
299 case HB_SCRIPT_CHAKMA:
300 case HB_SCRIPT_SHARADA:
301 case HB_SCRIPT_TAKRI:
303 /* If the designer designed the font for the 'DFLT' script,
304 * use the default shaper. Otherwise, use the Indic shaper.
305 * Note that for some simple scripts, there may not be *any*
306 * GSUB/GPOS needed, so there may be no scripts found! */
307 if (planner->map.chosen_script[0] == HB_TAG ('D','F','L','T'))
308 return &_hb_ot_complex_shaper_default;
309 else
310 return &_hb_ot_complex_shaper_indic;
312 case HB_SCRIPT_KHMER:
313 /* A number of Khmer fonts in the wild don't have a 'pref' feature,
314 * and as such won't shape properly via the Indic shaper;
315 * however, they typically have 'liga' / 'clig' features that implement
316 * the necessary "reordering" by means of ligature substitutions.
317 * So we send such pref-less fonts through the generic shaper instead. */
318 if (planner->map.found_script[0] &&
319 hb_ot_layout_language_find_feature (planner->face, HB_OT_TAG_GSUB,
320 planner->map.script_index[0],
321 planner->map.language_index[0],
322 HB_TAG ('p','r','e','f'),
323 NULL))
324 return &_hb_ot_complex_shaper_indic;
325 else
326 return &_hb_ot_complex_shaper_default;
328 case HB_SCRIPT_MYANMAR:
329 /* For Myanmar, we only want to use the Myanmar shaper if the "new" script
330 * tag is found. For "old" script tag we want to use the default shaper. */
331 if (planner->map.chosen_script[0] == HB_TAG ('m','y','m','2'))
332 return &_hb_ot_complex_shaper_myanmar;
333 else
334 return &_hb_ot_complex_shaper_default;
336 /* Unicode-4.1 additions */
337 case HB_SCRIPT_NEW_TAI_LUE:
339 /* Unicode-5.1 additions */
340 case HB_SCRIPT_CHAM:
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;
351 else
352 return &_hb_ot_complex_shaper_sea;
357 #endif /* HB_OT_SHAPE_COMPLEX_PRIVATE_HH */