static FT_Int t1_lookup_glyph_by_stdcharcode( T1_Decoder decoder, FT_Int charcode ) { FT_UInt n; const FT_String* glyph_name; FT_Service_PsCMaps psnames = decoder->psnames; /* check range of standard char code */ if ( charcode < 0 || charcode > 255 ) return -1; glyph_name = psnames->adobe_std_strings( psnames->adobe_std_encoding[charcode]); for ( n = 0; n < decoder->num_glyphs; n++ ) { FT_String* name = (FT_String*)decoder->glyph_names[n]; if ( name && name[0] == glyph_name[0] && ft_strcmp( name, glyph_name ) == 0 ) return n; } return -1; }
static FT_UInt cff_get_name_index( CFF_Face face, FT_String* glyph_name ) { CFF_Font cff; CFF_Charset charset; FT_Service_PsCMaps psnames; FT_Memory memory = FT_FACE_MEMORY( face ); FT_String* name; FT_UShort sid; FT_UInt i; FT_Int result; cff = (CFF_FontRec *)face->extra.data; charset = &cff->charset; FT_FACE_FIND_GLOBAL_SERVICE( face, psnames, POSTSCRIPT_CMAPS ); if ( !psnames ) return 0; for ( i = 0; i < cff->num_glyphs; i++ ) { sid = charset->sids[i]; if ( sid > 390 ) name = cff_index_get_name( &cff->string_index, sid - 391 ); else name = (FT_String *)psnames->adobe_std_strings( sid ); if ( !name ) continue; result = ft_strcmp( glyph_name, name ); if ( sid > 390 ) FT_FREE( name ); if ( !result ) return i; } return 0; }
cff_index_get_sid_string( CFF_Index idx, FT_UInt sid, FT_Service_PsCMaps psnames ) { /* value 0xFFFFU indicates a missing dictionary entry */ if ( sid == 0xFFFFU ) return 0; /* if it is not a standard string, return it */ if ( sid > 390 ) return cff_index_get_name( idx, sid - 391 ); /* CID-keyed CFF fonts don't have glyph names */ if ( !psnames ) return 0; /* that's a standard string, fetch a copy from the PSName module */ { FT_String* name = 0; const char* adobe_name = psnames->adobe_std_strings( sid ); FT_UInt len; if ( adobe_name ) { FT_Memory memory = idx->stream->memory; FT_Error error; len = (FT_UInt)ft_strlen( adobe_name ); if ( !FT_ALLOC( name, len + 1 ) ) { FT_MEM_COPY( name, adobe_name, len ); name[len] = 0; } FT_UNUSED( error ); } return name; } }
static FT_UInt cff_get_name_index( CFF_Face face, FT_String* glyph_name ) { CFF_Font cff; CFF_Charset charset; FT_Service_PsCMaps psnames; FT_String* name; FT_UShort sid; FT_UInt i; cff = (CFF_FontRec *)face->extra.data; charset = &cff->charset; /* CFF2 table does not have glyph names; */ /* we need to use `post' table method */ if ( cff->version_major == 2 ) { FT_Library library = FT_FACE_LIBRARY( face ); FT_Module sfnt_module = FT_Get_Module( library, "sfnt" ); FT_Service_GlyphDict service = (FT_Service_GlyphDict)ft_module_get_service( sfnt_module, FT_SERVICE_ID_GLYPH_DICT, 0 ); if ( service && service->name_index ) return service->name_index( FT_FACE( face ), glyph_name ); else { FT_ERROR(( "cff_get_name_index:" " cannot get glyph index from a CFF2 font\n" " " " without the `psnames' module\n" )); return 0; } } FT_FACE_FIND_GLOBAL_SERVICE( face, psnames, POSTSCRIPT_CMAPS ); if ( !psnames ) return 0; for ( i = 0; i < cff->num_glyphs; i++ ) { sid = charset->sids[i]; if ( sid > 390 ) name = cff_index_get_string( cff, sid - 391 ); else name = (FT_String *)psnames->adobe_std_strings( sid ); if ( !name ) continue; if ( !ft_strcmp( glyph_name, name ) ) return i; } return 0; }