hb-ot-shape-complex-private.hh revision 7cfee3827636f0dff7df5c8975a4fadd1b4bfbd5
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_PRIVATE_HH 28#define HB_OT_SHAPE_COMPLEX_PRIVATE_HH 29 30#include "hb-private.hh" 31 32#include "hb-ot-shape-private.hh" 33#include "hb-ot-shape-normalize-private.hh" 34 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 42enum 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, 48 49 HB_OT_SHAPE_ZERO_WIDTH_MARKS_DEFAULT = HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_UNICODE_LATE 50}; 51 52 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 (indic) \ 60 HB_COMPLEX_SHAPER_IMPLEMENT (myanmar) \ 61 HB_COMPLEX_SHAPER_IMPLEMENT (sea) \ 62 HB_COMPLEX_SHAPER_IMPLEMENT (thai) \ 63 HB_COMPLEX_SHAPER_IMPLEMENT (tibetan) \ 64 /* ^--- Add new shapers here */ 65 66 67struct hb_ot_complex_shaper_t 68{ 69 char name[8]; 70 71 /* collect_features() 72 * Called during shape_plan(). 73 * Shapers should use plan->map to add their features and callbacks. 74 * May be NULL. 75 */ 76 void (*collect_features) (hb_ot_shape_planner_t *plan); 77 78 /* override_features() 79 * Called during shape_plan(). 80 * Shapers should use plan->map to override features and add callbacks after 81 * common features are added. 82 * May be NULL. 83 */ 84 void (*override_features) (hb_ot_shape_planner_t *plan); 85 86 87 /* data_create() 88 * Called at the end of shape_plan(). 89 * Whatever shapers return will be accessible through plan->data later. 90 * If NULL is returned, means a plan failure. 91 */ 92 void *(*data_create) (const hb_ot_shape_plan_t *plan); 93 94 /* data_destroy() 95 * Called when the shape_plan is being destroyed. 96 * plan->data is passed here for destruction. 97 * If NULL is returned, means a plan failure. 98 * May be NULL. 99 */ 100 void (*data_destroy) (void *data); 101 102 103 /* preprocess_text() 104 * Called during shape(). 105 * Shapers can use to modify text before shaping starts. 106 * May be NULL. 107 */ 108 void (*preprocess_text) (const hb_ot_shape_plan_t *plan, 109 hb_buffer_t *buffer, 110 hb_font_t *font); 111 112 113 hb_ot_shape_normalization_mode_t normalization_preference; 114 115 /* decompose() 116 * Called during shape()'s normalization. 117 * May be NULL. 118 */ 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); 123 124 /* compose() 125 * Called during shape()'s normalization. 126 * May be NULL. 127 */ 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); 132 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. 138 */ 139 void (*setup_masks) (const hb_ot_shape_plan_t *plan, 140 hb_buffer_t *buffer, 141 hb_font_t *font); 142 143 hb_ot_shape_zero_width_marks_type_t zero_width_marks; 144 145 bool fallback_position; 146}; 147 148#define HB_COMPLEX_SHAPER_IMPLEMENT(name) extern HB_INTERNAL const hb_ot_complex_shaper_t _hb_ot_complex_shaper_##name; 149HB_COMPLEX_SHAPERS_IMPLEMENT_SHAPERS 150#undef HB_COMPLEX_SHAPER_IMPLEMENT 151 152 153static inline const hb_ot_complex_shaper_t * 154hb_ot_shape_complex_categorize (const hb_ot_shape_planner_t *planner) 155{ 156 switch ((hb_tag_t) planner->props.script) 157 { 158 default: 159 return &_hb_ot_complex_shaper_default; 160 161 162 /* Unicode-1.1 additions */ 163 case HB_SCRIPT_ARABIC: 164 165 /* Unicode-3.0 additions */ 166 case HB_SCRIPT_MONGOLIAN: 167 case HB_SCRIPT_SYRIAC: 168 169 /* Unicode-5.0 additions */ 170 case HB_SCRIPT_NKO: 171 case HB_SCRIPT_PHAGS_PA: 172 173 /* Unicode-6.0 additions */ 174 case HB_SCRIPT_MANDAIC: 175 176 /* Unicode-7.0 additions */ 177 case HB_SCRIPT_MANICHAEAN: 178 case HB_SCRIPT_PSALTER_PAHLAVI: 179 180 /* For Arabic script, use the Arabic shaper even if no OT script tag was found. 181 * This is because we do fallback shaping for Arabic script (and not others). */ 182 if (planner->map.chosen_script[0] != HB_OT_TAG_DEFAULT_SCRIPT || 183 planner->props.script == HB_SCRIPT_ARABIC) 184 return &_hb_ot_complex_shaper_arabic; 185 else 186 return &_hb_ot_complex_shaper_default; 187 188 189 /* Unicode-1.1 additions */ 190 case HB_SCRIPT_THAI: 191 case HB_SCRIPT_LAO: 192 193 return &_hb_ot_complex_shaper_thai; 194 195 196 /* Unicode-1.1 additions */ 197 case HB_SCRIPT_HANGUL: 198 199 return &_hb_ot_complex_shaper_hangul; 200 201 202 /* Unicode-2.0 additions */ 203 case HB_SCRIPT_TIBETAN: 204 205 return &_hb_ot_complex_shaper_tibetan; 206 207 208 /* Unicode-1.1 additions */ 209 case HB_SCRIPT_HEBREW: 210 211 return &_hb_ot_complex_shaper_hebrew; 212 213 214 /* ^--- Add new shapers here */ 215 216 217#if 0 218 /* Note: 219 * 220 * These disabled scripts are listed in ucd/IndicSyllabicCategory.txt, but according 221 * to Martin Hosken and Jonathan Kew do not require complex shaping. 222 * 223 * TODO We should automate figuring out which scripts do not need complex shaping 224 * 225 * TODO We currently keep data for these scripts in our indic table. Need to fix the 226 * generator to not do that. 227 */ 228 229 230 /* Simple? */ 231 232 /* Unicode-3.2 additions */ 233 case HB_SCRIPT_BUHID: 234 case HB_SCRIPT_HANUNOO: 235 236 /* Unicode-5.1 additions */ 237 case HB_SCRIPT_SAURASHTRA: 238 239 /* Unicode-6.0 additions */ 240 case HB_SCRIPT_BATAK: 241 case HB_SCRIPT_BRAHMI: 242 243 244 /* Simple */ 245 246 /* Unicode-1.1 additions */ 247 /* These have their own shaper now. */ 248 case HB_SCRIPT_LAO: 249 case HB_SCRIPT_THAI: 250 251 /* Unicode-3.2 additions */ 252 case HB_SCRIPT_TAGALOG: 253 case HB_SCRIPT_TAGBANWA: 254 255 /* Unicode-4.0 additions */ 256 case HB_SCRIPT_LIMBU: 257 case HB_SCRIPT_TAI_LE: 258 259 /* Unicode-4.1 additions */ 260 case HB_SCRIPT_KHAROSHTHI: 261 case HB_SCRIPT_SYLOTI_NAGRI: 262 263 /* Unicode-5.1 additions */ 264 case HB_SCRIPT_KAYAH_LI: 265 266 /* Unicode-5.2 additions */ 267 case HB_SCRIPT_TAI_VIET: 268 269 270#endif 271 272 /* Unicode-1.1 additions */ 273 case HB_SCRIPT_BENGALI: 274 case HB_SCRIPT_DEVANAGARI: 275 case HB_SCRIPT_GUJARATI: 276 case HB_SCRIPT_GURMUKHI: 277 case HB_SCRIPT_KANNADA: 278 case HB_SCRIPT_MALAYALAM: 279 case HB_SCRIPT_ORIYA: 280 case HB_SCRIPT_TAMIL: 281 case HB_SCRIPT_TELUGU: 282 283 /* Unicode-3.0 additions */ 284 case HB_SCRIPT_SINHALA: 285 286 /* Unicode-5.0 additions */ 287 case HB_SCRIPT_BALINESE: 288 289 /* Unicode-5.1 additions */ 290 case HB_SCRIPT_LEPCHA: 291 case HB_SCRIPT_REJANG: 292 case HB_SCRIPT_SUNDANESE: 293 294 /* Unicode-5.2 additions */ 295 case HB_SCRIPT_JAVANESE: 296 case HB_SCRIPT_KAITHI: 297 case HB_SCRIPT_MEETEI_MAYEK: 298 299 /* Unicode-6.0 additions */ 300 301 /* Unicode-6.1 additions */ 302 case HB_SCRIPT_CHAKMA: 303 case HB_SCRIPT_SHARADA: 304 case HB_SCRIPT_TAKRI: 305 306 /* If the designer designed the font for the 'DFLT' script, 307 * use the default shaper. Otherwise, use the Indic shaper. 308 * Note that for some simple scripts, there may not be *any* 309 * GSUB/GPOS needed, so there may be no scripts found! */ 310 if (planner->map.chosen_script[0] == HB_TAG ('D','F','L','T')) 311 return &_hb_ot_complex_shaper_default; 312 else 313 return &_hb_ot_complex_shaper_indic; 314 315 case HB_SCRIPT_KHMER: 316 /* A number of Khmer fonts in the wild don't have a 'pref' feature, 317 * and as such won't shape properly via the Indic shaper; 318 * however, they typically have 'liga' / 'clig' features that implement 319 * the necessary "reordering" by means of ligature substitutions. 320 * So we send such pref-less fonts through the generic shaper instead. */ 321 if (planner->map.found_script[0] && 322 hb_ot_layout_language_find_feature (planner->face, HB_OT_TAG_GSUB, 323 planner->map.script_index[0], 324 planner->map.language_index[0], 325 HB_TAG ('p','r','e','f'), 326 NULL)) 327 return &_hb_ot_complex_shaper_indic; 328 else 329 return &_hb_ot_complex_shaper_default; 330 331 case HB_SCRIPT_MYANMAR: 332 /* For Myanmar, we only want to use the Myanmar shaper if the "new" script 333 * tag is found. For "old" script tag we want to use the default shaper. */ 334 if (planner->map.chosen_script[0] == HB_TAG ('m','y','m','2')) 335 return &_hb_ot_complex_shaper_myanmar; 336 else 337 return &_hb_ot_complex_shaper_default; 338 339 /* Unicode-4.1 additions */ 340 case HB_SCRIPT_BUGINESE: 341 case HB_SCRIPT_NEW_TAI_LUE: 342 343 /* Unicode-5.1 additions */ 344 case HB_SCRIPT_CHAM: 345 346 /* Unicode-5.2 additions */ 347 case HB_SCRIPT_TAI_THAM: 348 349 /* If the designer designed the font for the 'DFLT' script, 350 * use the default shaper. Otherwise, use the Indic shaper. 351 * Note that for some simple scripts, there may not be *any* 352 * GSUB/GPOS needed, so there may be no scripts found! */ 353 if (planner->map.chosen_script[0] == HB_TAG ('D','F','L','T')) 354 return &_hb_ot_complex_shaper_default; 355 else 356 return &_hb_ot_complex_shaper_sea; 357 } 358} 359 360 361#endif /* HB_OT_SHAPE_COMPLEX_PRIVATE_HH */ 362