af_face_globals_free( AF_FaceGlobals globals ) { if ( globals ) { FT_Memory memory = globals->face->memory; FT_UInt nn; for ( nn = 0; nn < AF_SCRIPT_MAX; nn++ ) { if ( globals->metrics[nn] ) { AF_ScriptClass clazz = AF_SCRIPT_CLASSES_GET[nn]; FT_ASSERT( globals->metrics[nn]->clazz == clazz ); if ( clazz->script_metrics_done ) clazz->script_metrics_done( globals->metrics[nn] ); FT_FREE( globals->metrics[nn] ); } } globals->glyph_count = 0; globals->glyph_scripts = NULL; /* no need to free this one! */ globals->face = NULL; FT_FREE( globals ); } }
af_face_globals_get_metrics( AF_FaceGlobals globals, FT_UInt gindex, AF_ScriptMetrics *ametrics ) { AF_ScriptMetrics metrics = NULL; FT_UInt gidx; AF_ScriptClass clazz; FT_Error error = AF_Err_Ok; if ( gindex >= globals->glyph_count ) { error = AF_Err_Invalid_Argument; goto Exit; } gidx = globals->glyph_scripts[gindex]; clazz = af_script_classes[gidx]; metrics = globals->metrics[clazz->script]; if ( metrics == NULL ) { /* create the global metrics object when needed */ FT_Memory memory = globals->face->memory; if ( FT_ALLOC( metrics, clazz->script_metrics_size ) ) goto Exit; metrics->clazz = clazz; if ( clazz->script_metrics_init ) { error = clazz->script_metrics_init( metrics, globals->face ); if ( error ) { if ( clazz->script_metrics_done ) clazz->script_metrics_done( metrics ); FT_FREE( metrics ); goto Exit; } } globals->metrics[clazz->script] = metrics; } Exit: *ametrics = metrics; return error; }
af_face_globals_get_metrics( AF_FaceGlobals globals, FT_UInt gindex, FT_UInt options, AF_ScriptMetrics *ametrics ) { AF_ScriptMetrics metrics = NULL; FT_UInt gidx; AF_ScriptClass clazz; FT_UInt script = options & 15; const FT_Offset script_max = sizeof ( AF_SCRIPT_CLASSES_GET ) / sizeof ( AF_SCRIPT_CLASSES_GET[0] ); FT_Error error = AF_Err_Ok; if ( gindex >= (FT_ULong)globals->glyph_count ) { error = AF_Err_Invalid_Argument; goto Exit; } gidx = script; if ( gidx == 0 || gidx + 1 >= script_max ) gidx = globals->glyph_scripts[gindex] & AF_SCRIPT_LIST_NONE; clazz = AF_SCRIPT_CLASSES_GET[gidx]; if ( script == 0 ) script = clazz->script; metrics = globals->metrics[clazz->script]; if ( metrics == NULL ) { /* create the global metrics object when needed */ FT_Memory memory = globals->face->memory; if ( FT_ALLOC( metrics, clazz->script_metrics_size ) ) goto Exit; metrics->clazz = clazz; if ( clazz->script_metrics_init ) { error = clazz->script_metrics_init( metrics, globals->face ); if ( error ) { if ( clazz->script_metrics_done ) clazz->script_metrics_done( metrics ); FT_FREE( metrics ); goto Exit; } } globals->metrics[clazz->script] = metrics; } Exit: *ametrics = metrics; return error; }