25#ifdef FT_CONFIG_OPTION_USE_HARFBUZZ
38#define FT_COMPONENT afglobal
45#define SCRIPT( s, S, d, h, H, ss ) \
46 AF_DEFINE_SCRIPT_CLASS( \
47 af_ ## s ## _script_class, \
49 af_ ## s ## _uniranges, \
50 af_ ## s ## _nonbase_uniranges, \
58#define STYLE( s, S, d, ws, sc, ss, c ) \
59 AF_DEFINE_STYLE_CLASS( \
60 af_ ## s ## _style_class, \
71#define WRITING_SYSTEM( ws, WS ) \
72 &af_ ## ws ## _writing_system_class,
74 FT_LOCAL_ARRAY_DEF( AF_WritingSystemClass )
75 af_writing_system_classes[] =
85#define SCRIPT( s, S, d, h, H, ss ) \
86 &af_ ## s ## _script_class,
88 FT_LOCAL_ARRAY_DEF( AF_ScriptClass )
99#define STYLE( s, S, d, ws, sc, ss, c ) \
100 &af_ ## s ## _style_class,
102 FT_LOCAL_ARRAY_DEF( AF_StyleClass )
112#ifdef FT_DEBUG_LEVEL_TRACE
115#define STYLE( s, S, d, ws, sc, ss, c ) #s,
117 FT_LOCAL_ARRAY_DEF(
char* )
131 af_face_globals_compute_style_coverage( AF_FaceGlobals globals )
134 FT_Face face = globals->face;
135 FT_CharMap old_charmap = face->charmap;
136 FT_UShort* gstyles = globals->glyph_styles;
138 FT_UShort dflt = 0xFFFFU;
143 for ( i = 0; i < globals->glyph_count; i++ )
144 gstyles[i] = AF_STYLE_UNASSIGNED;
146 error = FT_Select_Charmap( face, FT_ENCODING_UNICODE );
158 for ( ss = 0; af_style_classes[ss]; ss++ )
160 AF_StyleClass style_class =
161 af_style_classes[ss];
162 AF_ScriptClass script_class =
163 af_script_classes[style_class->script];
164 AF_Script_UniRange range;
167 if ( !script_class->script_uni_ranges )
174 if ( style_class->coverage == AF_COVERAGE_DEFAULT )
176 if ( style_class->script == globals->module->default_script )
179 for ( range = script_class->script_uni_ranges;
183 FT_ULong charcode = range->first;
187 gindex = FT_Get_Char_Index( face, charcode );
190 gindex < globals->glyph_count &&
191 ( gstyles[gindex] & AF_STYLE_MASK ) == AF_STYLE_UNASSIGNED )
192 gstyles[gindex] = ss | AF_HAS_CMAP_ENTRY;
196 charcode = FT_Get_Next_Char( face, charcode, &gindex );
198 if ( gindex == 0 || charcode > range->last )
201 if ( gindex < globals->glyph_count &&
202 ( gstyles[gindex] & AF_STYLE_MASK ) == AF_STYLE_UNASSIGNED )
203 gstyles[gindex] = ss | AF_HAS_CMAP_ENTRY;
208 for ( range = script_class->script_uni_nonbase_ranges;
212 FT_ULong charcode = range->first;
216 gindex = FT_Get_Char_Index( face, charcode );
219 gindex < globals->glyph_count &&
220 ( gstyles[gindex] & AF_STYLE_MASK ) == ss )
221 gstyles[gindex] |= AF_NONBASE;
225 charcode = FT_Get_Next_Char( face, charcode, &gindex );
227 if ( gindex == 0 || charcode > range->last )
230 if ( gindex < globals->glyph_count &&
231 ( gstyles[gindex] & AF_STYLE_MASK ) == ss )
232 gstyles[gindex] |= AF_NONBASE;
239 af_shaper_get_coverage( globals, style_class, gstyles, 0 );
244 for ( ss = 0; af_style_classes[ss]; ss++ )
246 AF_StyleClass style_class = af_style_classes[ss];
249 if ( style_class->coverage == AF_COVERAGE_DEFAULT )
250 af_shaper_get_coverage( globals, style_class, gstyles, 0 );
254 af_shaper_get_coverage( globals, af_style_classes[dflt], gstyles, 1 );
257 for ( i = 0x30; i <= 0x39; i++ )
259 FT_UInt gindex = FT_Get_Char_Index( face, i );
262 if ( gindex != 0 && gindex < globals->glyph_count )
263 gstyles[gindex] |= AF_DIGIT;
271 if ( globals->module->fallback_style != AF_STYLE_UNASSIGNED )
276 for ( nn = 0; nn < globals->glyph_count; nn++ )
278 if ( ( gstyles[nn] & AF_STYLE_MASK ) == AF_STYLE_UNASSIGNED )
280 gstyles[nn] &= ~AF_STYLE_MASK;
281 gstyles[nn] |= globals->module->fallback_style;
286#ifdef FT_DEBUG_LEVEL_TRACE
289 FT_TRACE4((
"style coverage\n" ));
290 FT_TRACE4((
"==============\n" ));
293 for ( ss = 0; af_style_classes[ss]; ss++ )
295 AF_StyleClass style_class = af_style_classes[ss];
300 FT_TRACE4((
"%s:\n", af_style_names[style_class->style] ));
302 for ( idx = 0; idx < globals->glyph_count; idx++ )
304 if ( ( gstyles[idx] & AF_STYLE_MASK ) == style_class->style )
306 if ( !( count % 10 ) )
309 FT_TRACE4((
" %u", idx ));
312 if ( !( count % 10 ) )
318 FT_TRACE4((
" (none)\n" ));
325 face->charmap = old_charmap;
330 FT_LOCAL_DEF( FT_Error )
331 af_face_globals_new( FT_Face face,
332 AF_FaceGlobals *aglobals,
337 AF_FaceGlobals globals = NULL;
340 memory = face->memory;
344 if ( FT_QALLOC( globals,
345 sizeof ( *globals ) +
346 (FT_ULong)face->num_glyphs * sizeof ( FT_UShort ) ) )
349 FT_ZERO( &globals->metrics );
351 globals->face = face;
352 globals->glyph_count = (FT_UInt)face->num_glyphs;
354 globals->glyph_styles = (FT_UShort*)( globals + 1 );
355 globals->module =
module;
356 globals->stem_darkening_for_ppem = 0;
357 globals->darken_x = 0;
358 globals->darken_y = 0;
359 globals->standard_vertical_width = 0;
360 globals->standard_horizontal_width = 0;
361 globals->scale_down_factor = 0;
363#ifdef FT_CONFIG_OPTION_USE_HARFBUZZ
364 if ( ft_hb_enabled ( globals ) )
366 globals->hb_font = ft_hb_ft_font_create( globals );
367 globals->hb_buf = hb( buffer_create )();
369 af_parse_gsub( globals );
373 globals->hb_font = NULL;
374 globals->hb_buf = NULL;
376 globals->gsub = NULL;
377 globals->gsub_lookups_single_alternate = NULL;
381 error = af_face_globals_compute_style_coverage( globals );
384 af_face_globals_free( globals );
388 globals->increase_x_height = AF_PROP_INCREASE_X_HEIGHT_MAX;
397 af_face_globals_free(
void* globals_ )
399 AF_FaceGlobals globals = (AF_FaceGlobals)globals_;
404 FT_Memory memory = globals->face->memory;
408 for ( nn = 0; nn < AF_STYLE_MAX; nn++ )
410 if ( globals->metrics[nn] )
412 AF_StyleClass style_class =
413 af_style_classes[nn];
414 AF_WritingSystemClass writing_system_class =
415 af_writing_system_classes[style_class->writing_system];
418 if ( writing_system_class->style_metrics_done )
419 writing_system_class->style_metrics_done( globals->metrics[nn] );
421 FT_FREE( globals->metrics[nn] );
425#ifdef FT_CONFIG_OPTION_USE_HARFBUZZ
426 if ( ft_hb_enabled ( globals ) )
428 hb( font_destroy )( globals->hb_font );
429 hb( buffer_destroy )( globals->hb_buf );
431 FT_FREE( globals->gsub );
432 FT_FREE( globals->gsub_lookups_single_alternate );
443 FT_LOCAL_DEF( FT_Error )
444 af_face_globals_get_metrics( AF_FaceGlobals globals,
447 AF_StyleMetrics *ametrics )
449 AF_StyleMetrics metrics = NULL;
451 AF_Style style = (AF_Style)options;
452 AF_WritingSystemClass writing_system_class;
453 AF_StyleClass style_class;
455 FT_Error error = FT_Err_Ok;
458 if ( gindex >= globals->glyph_count )
460 error = FT_THROW( Invalid_Argument );
466 if ( style == AF_STYLE_NONE_DFLT || style + 1 >= AF_STYLE_MAX )
467 style = (AF_Style)( globals->glyph_styles[gindex] &
468 AF_STYLE_UNASSIGNED );
471 style_class = af_style_classes[style];
472 writing_system_class = af_writing_system_classes
473 [style_class->writing_system];
475 metrics = globals->metrics[style];
479 FT_Memory memory = globals->face->memory;
482 if ( FT_ALLOC( metrics, writing_system_class->style_metrics_size ) )
485 metrics->style_class = style_class;
486 metrics->globals = globals;
488 if ( writing_system_class->style_metrics_init )
490 error = writing_system_class->style_metrics_init( metrics,
494 if ( writing_system_class->style_metrics_done )
495 writing_system_class->style_metrics_done( metrics );
503 style = (AF_Style)( globals->glyph_styles[gindex] &
504 AF_STYLE_UNASSIGNED );
516 globals->metrics[style] = metrics;
526 FT_LOCAL_DEF( FT_Bool )
527 af_face_globals_is_digit( AF_FaceGlobals globals,
530 if ( gindex < globals->glyph_count )
531 return FT_BOOL( globals->glyph_styles[gindex] & AF_DIGIT );