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 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_GDEF_EARLY, 45 HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_GDEF_LATE 46 }; 47 48 49 /* Master OT shaper list */ 50 #define HB_COMPLEX_SHAPERS_IMPLEMENT_SHAPERS \ 51 HB_COMPLEX_SHAPER_IMPLEMENT (default) /* should be first */ \ 52 HB_COMPLEX_SHAPER_IMPLEMENT (arabic) \ 53 HB_COMPLEX_SHAPER_IMPLEMENT (hangul) \ 54 HB_COMPLEX_SHAPER_IMPLEMENT (hebrew) \ 55 HB_COMPLEX_SHAPER_IMPLEMENT (myanmar_old) \ 56 HB_COMPLEX_SHAPER_IMPLEMENT (indic) \ 57 HB_COMPLEX_SHAPER_IMPLEMENT (myanmar) \ 58 HB_COMPLEX_SHAPER_IMPLEMENT (thai) \ 59 HB_COMPLEX_SHAPER_IMPLEMENT (tibetan) \ 60 HB_COMPLEX_SHAPER_IMPLEMENT (use) \ 61 /* ^--- Add new shapers here */ 62 63 64 struct hb_ot_complex_shaper_t 65 { 66 char name[8]; 67 68 /* collect_features() 69 * Called during shape_plan(). 70 * Shapers should use plan->map to add their features and callbacks. 71 * May be NULL. 72 */ 73 void (*collect_features) (hb_ot_shape_planner_t *plan); 74 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. 79 * May be NULL. 80 */ 81 void (*override_features) (hb_ot_shape_planner_t *plan); 82 83 84 /* data_create() 85 * Called at the end of shape_plan(). 86 * Whatever shapers return will be accessible through plan->data later. 87 * If NULL is returned, means a plan failure. 88 */ 89 void *(*data_create) (const hb_ot_shape_plan_t *plan); 90 91 /* data_destroy() 92 * Called when the shape_plan is being destroyed. 93 * plan->data is passed here for destruction. 94 * If NULL is returned, means a plan failure. 95 * May be NULL. 96 */ 97 void (*data_destroy) (void *data); 98 99 100 /* preprocess_text() 101 * Called during shape(). 102 * Shapers can use to modify text before shaping starts. 103 * May be NULL. 104 */ 105 void (*preprocess_text) (const hb_ot_shape_plan_t *plan, 106 hb_buffer_t *buffer, 107 hb_font_t *font); 108 109 /* postprocess_glyphs() 110 * Called during shape(). 111 * Shapers can use to modify glyphs after shaping ends. 112 * May be NULL. 113 */ 114 void (*postprocess_glyphs) (const hb_ot_shape_plan_t *plan, 115 hb_buffer_t *buffer, 116 hb_font_t *font); 117 118 119 hb_ot_shape_normalization_mode_t normalization_preference; 120 121 /* decompose() 122 * Called during shape()'s normalization. 123 * May be NULL. 124 */ 125 bool (*decompose) (const hb_ot_shape_normalize_context_t *c, 126 hb_codepoint_t ab, 127 hb_codepoint_t *a, 128 hb_codepoint_t *b); 129 130 /* compose() 131 * Called during shape()'s normalization. 132 * May be NULL. 133 */ 134 bool (*compose) (const hb_ot_shape_normalize_context_t *c, 135 hb_codepoint_t a, 136 hb_codepoint_t b, 137 hb_codepoint_t *ab); 138 139 /* setup_masks() 140 * Called during shape(). 141 * Shapers should use map to get feature masks and set on buffer. 142 * Shapers may NOT modify characters. 143 * May be NULL. 144 */ 145 void (*setup_masks) (const hb_ot_shape_plan_t *plan, 146 hb_buffer_t *buffer, 147 hb_font_t *font); 148 149 /* disable_otl() 150 * Called during shape(). 151 * If set and returns true, GDEF/GSUB/GPOS of the font are ignored 152 * and fallback operations used. 153 * May be NULL. 154 */ 155 bool (*disable_otl) (const hb_ot_shape_plan_t *plan); 156 157 hb_ot_shape_zero_width_marks_type_t zero_width_marks; 158 159 bool fallback_position; 160 }; 161 162 #define HB_COMPLEX_SHAPER_IMPLEMENT(name) extern HB_INTERNAL const hb_ot_complex_shaper_t _hb_ot_complex_shaper_##name; 163 HB_COMPLEX_SHAPERS_IMPLEMENT_SHAPERS 164 #undef HB_COMPLEX_SHAPER_IMPLEMENT 165 166 167 static inline const hb_ot_complex_shaper_t * 168 hb_ot_shape_complex_categorize (const hb_ot_shape_planner_t *planner) 169 { 170 switch ((hb_tag_t) planner->props.script) 171 { 172 default: 173 return &_hb_ot_complex_shaper_default; 174 175 176 /* Unicode-1.1 additions */ 177 case HB_SCRIPT_ARABIC: 178 179 /* Unicode-3.0 additions */ 180 case HB_SCRIPT_MONGOLIAN: 181 case HB_SCRIPT_SYRIAC: 182 183 /* Unicode-5.0 additions */ 184 case HB_SCRIPT_NKO: 185 case HB_SCRIPT_PHAGS_PA: 186 187 /* Unicode-6.0 additions */ 188 case HB_SCRIPT_MANDAIC: 189 190 /* Unicode-7.0 additions */ 191 case HB_SCRIPT_MANICHAEAN: 192 case HB_SCRIPT_PSALTER_PAHLAVI: 193 194 /* For Arabic script, use the Arabic shaper even if no OT script tag was found. 195 * This is because we do fallback shaping for Arabic script (and not others). 196 * But note that Arabic shaping is applicable only to horizontal layout; for 197 * vertical text, just use the generic shaper instead. */ 198 if ((planner->map.chosen_script[0] != HB_OT_TAG_DEFAULT_SCRIPT || 199 planner->props.script == HB_SCRIPT_ARABIC) && 200 HB_DIRECTION_IS_HORIZONTAL(planner->props.direction)) 201 return &_hb_ot_complex_shaper_arabic; 202 else 203 return &_hb_ot_complex_shaper_default; 204 205 206 /* Unicode-1.1 additions */ 207 case HB_SCRIPT_THAI: 208 case HB_SCRIPT_LAO: 209 210 return &_hb_ot_complex_shaper_thai; 211 212 213 /* Unicode-1.1 additions */ 233 #if 0 234 /* Unicode-4.1 additions */ 235 case HB_SCRIPT_NEW_TAI_LUE: 236 #endif 237 238 /* Unicode-1.1 additions */ 239 case HB_SCRIPT_BENGALI: 240 case HB_SCRIPT_DEVANAGARI: 241 case HB_SCRIPT_GUJARATI: 242 case HB_SCRIPT_GURMUKHI: 243 case HB_SCRIPT_KANNADA: 244 case HB_SCRIPT_MALAYALAM: 245 case HB_SCRIPT_ORIYA: 246 case HB_SCRIPT_TAMIL: 247 case HB_SCRIPT_TELUGU: 248 249 /* Unicode-3.0 additions */ 250 case HB_SCRIPT_SINHALA: 251 252 /* If the designer designed the font for the 'DFLT' script, 253 * use the default shaper. Otherwise, use the specific shaper. 254 * Note that for some simple scripts, there may not be *any* 255 * GSUB/GPOS needed, so there may be no scripts found! */ 256 if (planner->map.chosen_script[0] == HB_TAG ('D','F','L','T')) 257 return &_hb_ot_complex_shaper_default; 258 else 259 return &_hb_ot_complex_shaper_indic; 260 261 case HB_SCRIPT_KHMER: 262 /* A number of Khmer fonts in the wild don't have a 'pref' feature, 263 * and as such won't shape properly via the Indic shaper; 264 * however, they typically have 'liga' / 'clig' features that implement 265 * the necessary "reordering" by means of ligature substitutions. 266 * So we send such pref-less fonts through the generic shaper instead. */ 267 if (planner->map.found_script[0] && 268 hb_ot_layout_language_find_feature (planner->face, HB_OT_TAG_GSUB, 269 planner->map.script_index[0], 270 planner->map.language_index[0], 271 HB_TAG ('p','r','e','f'), 272 NULL)) 273 return &_hb_ot_complex_shaper_indic; 274 else 275 return &_hb_ot_complex_shaper_default; 276 277 case HB_SCRIPT_MYANMAR: 278 if (planner->map.chosen_script[0] == HB_TAG ('m','y','m','2')) 279 return &_hb_ot_complex_shaper_myanmar; 280 else if (planner->map.chosen_script[0] == HB_TAG ('m','y','m','r')) 281 return &_hb_ot_complex_shaper_myanmar_old; 282 else 283 return &_hb_ot_complex_shaper_default; 284 285 286 /* Unicode-2.0 additions */ 287 //case HB_SCRIPT_TIBETAN: 288 289 /* Unicode-3.0 additions */ 290 //case HB_SCRIPT_MONGOLIAN: 291 //case HB_SCRIPT_SINHALA: 292 342 case HB_SCRIPT_GRANTHA: 343 case HB_SCRIPT_KHOJKI: 344 case HB_SCRIPT_KHUDAWADI: 345 case HB_SCRIPT_MAHAJANI: 346 //case HB_SCRIPT_MANICHAEAN: 347 case HB_SCRIPT_MODI: 348 case HB_SCRIPT_PAHAWH_HMONG: 349 //case HB_SCRIPT_PSALTER_PAHLAVI: 350 case HB_SCRIPT_SIDDHAM: 351 case HB_SCRIPT_TIRHUTA: 352 353 /* Unicode-8.0 additions */ 354 case HB_SCRIPT_AHOM: 355 //case HB_SCRIPT_MULTANI: 356 357 /* Unicode-9.0 additions */ 358 case HB_SCRIPT_BHAIKSUKI: 359 case HB_SCRIPT_MARCHEN: 360 case HB_SCRIPT_NEWA: 361 362 /* If the designer designed the font for the 'DFLT' script, 363 * use the default shaper. Otherwise, use the specific shaper. 364 * Note that for some simple scripts, there may not be *any* 365 * GSUB/GPOS needed, so there may be no scripts found! */ 366 if (planner->map.chosen_script[0] == HB_TAG ('D','F','L','T')) 367 return &_hb_ot_complex_shaper_default; 368 else 369 return &_hb_ot_complex_shaper_use; 370 } 371 } 372 373 374 #endif /* HB_OT_SHAPE_COMPLEX_PRIVATE_HH */ | 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 42 #define HB_OT_SHAPE_COMPLEX_MAX_COMBINING_MARKS 32 43 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 48 }; 49 50 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 (myanmar_old) \ 58 HB_COMPLEX_SHAPER_IMPLEMENT (indic) \ 59 HB_COMPLEX_SHAPER_IMPLEMENT (myanmar) \ 60 HB_COMPLEX_SHAPER_IMPLEMENT (thai) \ 61 HB_COMPLEX_SHAPER_IMPLEMENT (tibetan) \ 62 HB_COMPLEX_SHAPER_IMPLEMENT (use) \ 63 /* ^--- Add new shapers here */ 64 65 66 struct hb_ot_complex_shaper_t 67 { 68 /* collect_features() 69 * Called during shape_plan(). 70 * Shapers should use plan->map to add their features and callbacks. 71 * May be nullptr. 72 */ 73 void (*collect_features) (hb_ot_shape_planner_t *plan); 74 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. 79 * May be nullptr. 80 */ 81 void (*override_features) (hb_ot_shape_planner_t *plan); 82 83 84 /* data_create() 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. 88 */ 89 void *(*data_create) (const hb_ot_shape_plan_t *plan); 90 91 /* data_destroy() 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. 95 * May be nullptr. 96 */ 97 void (*data_destroy) (void *data); 98 99 100 /* preprocess_text() 101 * Called during shape(). 102 * Shapers can use to modify text before shaping starts. 103 * May be nullptr. 104 */ 105 void (*preprocess_text) (const hb_ot_shape_plan_t *plan, 106 hb_buffer_t *buffer, 107 hb_font_t *font); 108 109 /* postprocess_glyphs() 110 * Called during shape(). 111 * Shapers can use to modify glyphs after shaping ends. 112 * May be nullptr. 113 */ 114 void (*postprocess_glyphs) (const hb_ot_shape_plan_t *plan, 115 hb_buffer_t *buffer, 116 hb_font_t *font); 117 118 119 hb_ot_shape_normalization_mode_t normalization_preference; 120 121 /* decompose() 122 * Called during shape()'s normalization. 123 * May be nullptr. 124 */ 125 bool (*decompose) (const hb_ot_shape_normalize_context_t *c, 126 hb_codepoint_t ab, 127 hb_codepoint_t *a, 128 hb_codepoint_t *b); 129 130 /* compose() 131 * Called during shape()'s normalization. 132 * May be nullptr. 133 */ 134 bool (*compose) (const hb_ot_shape_normalize_context_t *c, 135 hb_codepoint_t a, 136 hb_codepoint_t b, 137 hb_codepoint_t *ab); 138 139 /* setup_masks() 140 * Called during shape(). 141 * Shapers should use map to get feature masks and set on buffer. 142 * Shapers may NOT modify characters. 143 * May be nullptr. 144 */ 145 void (*setup_masks) (const hb_ot_shape_plan_t *plan, 146 hb_buffer_t *buffer, 147 hb_font_t *font); 148 149 /* disable_otl() 150 * Called during shape(). 151 * If set and returns true, GDEF/GSUB/GPOS of the font are ignored 152 * and fallback operations used. 153 * May be nullptr. 154 */ 155 bool (*disable_otl) (const hb_ot_shape_plan_t *plan); 156 157 /* reorder_marks() 158 * Called during shape(). 159 * Shapers can use to modify ordering of combining marks. 160 * May be nullptr. 161 */ 162 void (*reorder_marks) (const hb_ot_shape_plan_t *plan, 163 hb_buffer_t *buffer, 164 unsigned int start, 165 unsigned int end); 166 167 hb_ot_shape_zero_width_marks_type_t zero_width_marks; 168 169 bool fallback_position; 170 }; 171 172 #define HB_COMPLEX_SHAPER_IMPLEMENT(name) extern HB_INTERNAL const hb_ot_complex_shaper_t _hb_ot_complex_shaper_##name; 173 HB_COMPLEX_SHAPERS_IMPLEMENT_SHAPERS 174 #undef HB_COMPLEX_SHAPER_IMPLEMENT 175 176 177 static inline const hb_ot_complex_shaper_t * 178 hb_ot_shape_complex_categorize (const hb_ot_shape_planner_t *planner) 179 { 180 switch ((hb_tag_t) planner->props.script) 181 { 182 default: 183 return &_hb_ot_complex_shaper_default; 184 185 186 /* Unicode-1.1 additions */ 187 case HB_SCRIPT_ARABIC: 188 189 /* Unicode-3.0 additions */ 190 case HB_SCRIPT_MONGOLIAN: 191 case HB_SCRIPT_SYRIAC: 192 193 /* Unicode-5.0 additions */ 194 case HB_SCRIPT_NKO: 195 case HB_SCRIPT_PHAGS_PA: 196 197 /* Unicode-6.0 additions */ 198 case HB_SCRIPT_MANDAIC: 199 200 /* Unicode-7.0 additions */ 201 case HB_SCRIPT_MANICHAEAN: 202 case HB_SCRIPT_PSALTER_PAHLAVI: 203 204 /* Unicode-9.0 additions */ 205 case HB_SCRIPT_ADLAM: 206 207 /* For Arabic script, use the Arabic shaper even if no OT script tag was found. 208 * This is because we do fallback shaping for Arabic script (and not others). 209 * But note that Arabic shaping is applicable only to horizontal layout; for 210 * vertical text, just use the generic shaper instead. */ 211 if ((planner->map.chosen_script[0] != HB_OT_TAG_DEFAULT_SCRIPT || 212 planner->props.script == HB_SCRIPT_ARABIC) && 213 HB_DIRECTION_IS_HORIZONTAL(planner->props.direction)) 214 return &_hb_ot_complex_shaper_arabic; 215 else 216 return &_hb_ot_complex_shaper_default; 217 218 219 /* Unicode-1.1 additions */ 220 case HB_SCRIPT_THAI: 221 case HB_SCRIPT_LAO: 222 223 return &_hb_ot_complex_shaper_thai; 224 225 226 /* Unicode-1.1 additions */ 246 #if 0 247 /* Unicode-4.1 additions */ 248 case HB_SCRIPT_NEW_TAI_LUE: 249 #endif 250 251 /* Unicode-1.1 additions */ 252 case HB_SCRIPT_BENGALI: 253 case HB_SCRIPT_DEVANAGARI: 254 case HB_SCRIPT_GUJARATI: 255 case HB_SCRIPT_GURMUKHI: 256 case HB_SCRIPT_KANNADA: 257 case HB_SCRIPT_MALAYALAM: 258 case HB_SCRIPT_ORIYA: 259 case HB_SCRIPT_TAMIL: 260 case HB_SCRIPT_TELUGU: 261 262 /* Unicode-3.0 additions */ 263 case HB_SCRIPT_SINHALA: 264 265 /* If the designer designed the font for the 'DFLT' script, 266 * (or we ended up arbitrarily pick 'latn'), use the default shaper. 267 * Otherwise, use the specific shaper. 268 * Note that for some simple scripts, there may not be *any* 269 * GSUB/GPOS needed, so there may be no scripts found! */ 270 if (planner->map.chosen_script[0] == HB_TAG ('D','F','L','T') || 271 planner->map.chosen_script[0] == HB_TAG ('l','a','t','n')) 272 return &_hb_ot_complex_shaper_default; 273 else 274 return &_hb_ot_complex_shaper_indic; 275 276 case HB_SCRIPT_KHMER: 277 /* A number of Khmer fonts in the wild don't have a 'pref' feature, 278 * and as such won't shape properly via the Indic shaper; 279 * however, they typically have 'liga' / 'clig' features that implement 280 * the necessary "reordering" by means of ligature substitutions. 281 * So we send such pref-less fonts through the generic shaper instead. */ 282 if (planner->map.found_script[0] && 283 hb_ot_layout_language_find_feature (planner->face, HB_OT_TAG_GSUB, 284 planner->map.script_index[0], 285 planner->map.language_index[0], 286 HB_TAG ('p','r','e','f'), 287 nullptr)) 288 return &_hb_ot_complex_shaper_indic; 289 else 290 return &_hb_ot_complex_shaper_default; 291 292 case HB_SCRIPT_MYANMAR: 293 if (planner->map.chosen_script[0] == HB_TAG ('m','y','m','2')) 294 return &_hb_ot_complex_shaper_myanmar; 295 else if (planner->map.chosen_script[0] == HB_TAG ('m','y','m','r')) 296 return &_hb_ot_complex_shaper_myanmar_old; 297 else 298 return &_hb_ot_complex_shaper_default; 299 300 301 /* Unicode-2.0 additions */ 302 //case HB_SCRIPT_TIBETAN: 303 304 /* Unicode-3.0 additions */ 305 //case HB_SCRIPT_MONGOLIAN: 306 //case HB_SCRIPT_SINHALA: 307 357 case HB_SCRIPT_GRANTHA: 358 case HB_SCRIPT_KHOJKI: 359 case HB_SCRIPT_KHUDAWADI: 360 case HB_SCRIPT_MAHAJANI: 361 //case HB_SCRIPT_MANICHAEAN: 362 case HB_SCRIPT_MODI: 363 case HB_SCRIPT_PAHAWH_HMONG: 364 //case HB_SCRIPT_PSALTER_PAHLAVI: 365 case HB_SCRIPT_SIDDHAM: 366 case HB_SCRIPT_TIRHUTA: 367 368 /* Unicode-8.0 additions */ 369 case HB_SCRIPT_AHOM: 370 //case HB_SCRIPT_MULTANI: 371 372 /* Unicode-9.0 additions */ 373 case HB_SCRIPT_BHAIKSUKI: 374 case HB_SCRIPT_MARCHEN: 375 case HB_SCRIPT_NEWA: 376 377 /* Unicode-10.0 additions */ 378 case HB_SCRIPT_MASARAM_GONDI: 379 case HB_SCRIPT_SOYOMBO: 380 case HB_SCRIPT_ZANABAZAR_SQUARE: 381 382 /* If the designer designed the font for the 'DFLT' script, 383 * (or we ended up arbitrarily pick 'latn'), use the default shaper. 384 * Otherwise, use the specific shaper. 385 * Note that for some simple scripts, there may not be *any* 386 * GSUB/GPOS needed, so there may be no scripts found! */ 387 if (planner->map.chosen_script[0] == HB_TAG ('D','F','L','T') || 388 planner->map.chosen_script[0] == HB_TAG ('l','a','t','n')) 389 return &_hb_ot_complex_shaper_default; 390 else 391 return &_hb_ot_complex_shaper_use; 392 } 393 } 394 395 396 #endif /* HB_OT_SHAPE_COMPLEX_PRIVATE_HH */ |