5
/* populate this list when you add new scripts
7
static AF_ScriptClass const af_script_classes[] =
9
& af_dummy_script_class,
10
& af_latin_script_class,
12
NULL /* do not remove */
15
#define AF_SCRIPT_LIST_DEFAULT 1 /* index of default script in 'af_script_classes' */
16
#define AF_SCRIPT_LIST_NONE 255 /* indicates an uncovered glyph */
19
* note that glyph_scripts[] is used to map each glyph into
20
* an index into the 'af_script_classes' array.
23
typedef struct AF_FaceGlobalsRec_
26
FT_UInt glyph_count; /* same as face->num_glyphs */
27
FT_Byte* glyph_scripts;
29
AF_ScriptMetrics metrics[ AF_SCRIPT_MAX ];
36
/* this function is used to compute the script index of each glyph
40
af_face_globals_compute_script_coverage( AF_FaceGlobals globals )
43
FT_Face face = globals->face;
44
FT_CharMap old_charmap = face->charmap;
45
FT_Byte* gscripts = globals->glyph_scripts;
48
/* the value 255 means "uncovered glyph"
50
FT_MEM_SET( globals->glyph_scripts,
52
globals->glyph_count );
54
error = FT_Select_Charmap( face, FT_ENCODING_UNICODE );
57
/* ignore this error, we'll simply use Latin as the standard
58
* script. XXX: Shouldn't we rather disable hinting ??
64
/* scan each script in a Unicode charmap
66
for ( ss = 0; af_script_classes[ss]; ss++ )
68
AF_ScriptClass clazz = af_script_classes[ss];
69
AF_Script_UniRange range;
71
if ( clazz->script_uni_ranges == NULL )
74
/* scan all unicode points in the range, and set the corresponding
77
for ( range = clazz->script_uni_ranges; range->first != 0; range++ )
79
FT_ULong charcode = range->first;
82
gindex = FT_Get_Char_Index( face, charcode );
85
gindex < globals->glyph_count &&
86
gscripts[ gindex ] == AF_SCRIPT_LIST_NONE )
88
gscripts[ gindex ] = (FT_Byte) ss;
92
charcode = FT_Get_Next_Char( face, charcode, &gindex );
94
if ( gindex == 0 || charcode > range->last )
97
if ( gindex < globals->glyph_count &&
98
gscripts[ gindex ] == AF_SCRIPT_LIST_NONE )
100
gscripts[ gindex ] = (FT_Byte) ss;
107
/* by default, all uncovered glyphs are set to the latin script
108
* XXX: shouldnt' we disable hinting or do something similar ?
113
for ( nn = 0; nn < globals->glyph_count; nn++ )
115
if ( gscripts[ nn ] == AF_SCRIPT_LIST_NONE )
116
gscripts[ nn ] = AF_SCRIPT_LIST_DEFAULT;
120
FT_Set_Charmap( face, old_charmap );
126
FT_LOCAL_DEF( FT_Error )
127
af_face_globals_new( FT_Face face,
128
AF_FaceGlobals *aglobals )
132
AF_FaceGlobals globals;
134
memory = face->memory;
136
if ( !FT_ALLOC( globals, sizeof(*globals) +
137
face->num_glyphs*sizeof(FT_Byte) ) )
139
globals->face = face;
140
globals->glyph_count = face->num_glyphs;
141
globals->glyph_scripts = (FT_Byte*)( globals+1 );
143
error = af_face_globals_compute_script_coverage( globals );
146
af_face_globals_free( globals );
157
af_face_globals_free( AF_FaceGlobals globals )
161
FT_Memory memory = globals->face->memory;
164
for ( nn = 0; nn < AF_SCRIPT_MAX; nn++ )
166
if ( globals->metrics[nn] )
168
AF_ScriptClass clazz = af_script_classes[nn];
170
FT_ASSERT( globals->metrics[nn]->clazz == clazz );
172
if ( clazz->script_metrics_done )
173
clazz->script_metrics_done( globals->metrics[nn] );
175
FT_FREE( globals->metrics[nn] );
179
globals->glyph_count = 0;
180
globals->glyph_scripts = NULL; /* no need to free this one !! */
181
globals->face = NULL;
187
FT_LOCAL_DEF( FT_Error )
188
af_face_globals_get_metrics( AF_FaceGlobals globals,
190
AF_ScriptMetrics *ametrics )
192
AF_ScriptMetrics metrics = NULL;
194
AF_ScriptClass clazz;
197
if ( gindex >= globals->glyph_count )
199
error = FT_Err_Invalid_Argument;
203
index = globals->glyph_scripts[ gindex ];
204
clazz = af_script_classes[ index ];
205
metrics = globals->metrics[ clazz->script ];
206
if ( metrics == NULL )
208
/* create the global metrics object when needed
210
FT_Memory memory = globals->face->memory;
212
if ( FT_ALLOC( metrics, clazz->script_metrics_size ) )
215
metrics->clazz = clazz;
217
if ( clazz->script_metrics_init )
219
error = clazz->script_metrics_init( metrics, globals->face );
222
if ( clazz->script_metrics_done )
223
clazz->script_metrics_done( metrics );
230
globals->metrics[ clazz->script ] = metrics;