static FT_Int t1_lookup_glyph_by_stdcharcode( T1_Decoder decoder, FT_Int charcode ) { FT_UInt n; const FT_String* glyph_name; PSNames_Service 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; }
cff_index_get_sid_string( CFF_Index idx, FT_UInt sid, PSNames_Service psnames_service ) { /* if it is not a standard string, return it */ if ( sid > 390 ) return cff_index_get_name( idx, sid - 391 ); /* that's a standard string, fetch a copy from the PSName module */ { FT_String* name = 0; const char* adobe_name = psnames_service->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_Long CID_Get_Next_Char( FT_CharMap charmap, FT_Long charcode ) { T1_Face face; PSNames_Service psnames; face = (T1_Face)charmap->face; psnames = (PSNames_Service)face->psnames; if ( psnames ) switch ( charmap->encoding ) { /*******************************************************************/ /* */ /* Unicode encoding support */ /* */ case ft_encoding_unicode: /* use the `PSNames' module to synthetize the Unicode charmap */ return psnames->next_unicode (&face->unicode_map, (FT_ULong)charcode ); /*******************************************************************/ /* */ /* Custom Type 1 encoding */ /* */ case ft_encoding_adobe_custom: { T1_Encoding encoding = &face->type1.encoding; charcode++; if ( charcode < encoding->code_first ) charcode = encoding->code_first; while ( charcode <= encoding->code_last ) { if ( encoding->char_index[charcode] ) return charcode; charcode++; } } break; /*******************************************************************/ /* */ /* Adobe Standard & Expert encoding support */ /* */ default: while ( ++charcode < 256 ) { FT_UInt code; FT_Int n; const char* glyph_name; code = psnames->adobe_std_encoding[charcode]; if ( charmap->encoding == ft_encoding_adobe_expert ) code = psnames->adobe_expert_encoding[charcode]; glyph_name = psnames->adobe_std_strings( code ); if ( !glyph_name ) continue; for ( n = 0; n < face->type1.num_glyphs; n++ ) { const char* gname = face->type1.glyph_names[n]; if ( gname && gname[0] == glyph_name[0] && ft_strcmp( gname, glyph_name ) == 0 ) { return charcode; } } } } return 0; }
static FT_UInt CID_Get_Char_Index( FT_CharMap charmap, FT_Long charcode ) { T1_Face face; FT_UInt result = 0; PSNames_Service psnames; face = (T1_Face)charmap->face; psnames = (PSNames_Service)face->psnames; if ( psnames ) switch ( charmap->encoding ) { /*******************************************************************/ /* */ /* Unicode encoding support */ /* */ case ft_encoding_unicode: /* use the `PSNames' module to synthetize the Unicode charmap */ result = psnames->lookup_unicode( &face->unicode_map, (FT_ULong)charcode ); /* the function returns 0xFFFF if the Unicode charcode has */ /* no corresponding glyph. */ if ( result == 0xFFFF ) result = 0; goto Exit; /*******************************************************************/ /* */ /* Custom Type 1 encoding */ /* */ case ft_encoding_adobe_custom: { T1_Encoding encoding = &face->type1.encoding; if ( charcode >= encoding->code_first && charcode <= encoding->code_last ) result = encoding->char_index[charcode]; goto Exit; } /*******************************************************************/ /* */ /* Adobe Standard & Expert encoding support */ /* */ default: if ( charcode < 256 ) { FT_UInt code; FT_Int n; const char* glyph_name; code = psnames->adobe_std_encoding[charcode]; if ( charmap->encoding == ft_encoding_adobe_expert ) code = psnames->adobe_expert_encoding[charcode]; glyph_name = psnames->adobe_std_strings( code ); if ( !glyph_name ) break; for ( n = 0; n < face->type1.num_glyphs; n++ ) { const char* gname = face->type1.glyph_names[n]; if ( gname && gname[0] == glyph_name[0] && ft_strcmp( gname, glyph_name ) == 0 ) { result = n; break; } } } } Exit: return result; }
T42_CMap_CharIndex( FT_CharMap charmap, FT_Long charcode ) { T42_Face face; FT_UInt result = 0; PSNames_Service psnames; face = (T42_Face)charmap->face; psnames = (PSNames_Service)face->psnames; if (!psnames ) goto Exit; switch ( charmap->encoding ) { /*******************************************************************/ /* */ /* Unicode encoding support */ /* */ case ft_encoding_unicode: /* if this charmap is used, we ignore the encoding of the font and */ /* use the `PSNames' module to synthetize the Unicode charmap */ result = psnames->lookup_unicode( &face->unicode_map, (FT_ULong)charcode ); /* the function returns 0xFFFF if the Unicode charcode has */ /* no corresponding glyph */ if ( result == 0xFFFFU ) result = 0; /* The result returned is the index (position)in the CharStrings */ /* array. This must be used now to get the value associated to */ /* that glyph_name, which is the real index within the truetype */ /* structure. */ result = ft_atoi( (const char*)face->type1.charstrings[result] ); goto Exit; /*******************************************************************/ /* */ /* ISOLatin1 encoding support */ /* */ case ft_encoding_latin_1: /* ISOLatin1 is the first page of Unicode */ if ( charcode < 256 && psnames->unicode_value ) { result = psnames->lookup_unicode( &face->unicode_map, (FT_ULong)charcode ); /* the function returns 0xFFFF if the Unicode charcode has */ /* no corresponding glyph */ if ( result == 0xFFFFU ) result = 0; } goto Exit; /*******************************************************************/ /* */ /* Custom Type 1 encoding */ /* */ case ft_encoding_adobe_custom: { T1_Encoding encoding = &face->type1.encoding; if ( charcode >= encoding->code_first && charcode <= encoding->code_last ) { FT_UInt idx = encoding->char_index[charcode]; result = ft_atoi( (const char *)face->type1.charstrings[idx] ); } goto Exit; } /*******************************************************************/ /* */ /* Adobe Standard & Expert encoding support */ /* */ default: if ( charcode < 256 ) { FT_UInt code; FT_Int n; const char* glyph_name; code = psnames->adobe_std_encoding[charcode]; if ( charmap->encoding == ft_encoding_adobe_expert ) code = psnames->adobe_expert_encoding[charcode]; glyph_name = psnames->adobe_std_strings( code ); if ( !glyph_name ) break; for ( n = 0; n < face->type1.num_glyphs; n++ ) { const char* gname = face->type1.glyph_names[n]; if ( gname && ( ft_strcmp( gname, glyph_name ) == 0 ) ) { result = ft_atoi( (const char *)face->type1.charstrings[n] ); break; } } } } Exit: return result; }
T42_Face_Init( FT_Stream stream, T42_Face face, FT_Int face_index, FT_Int num_params, FT_Parameter* params) { FT_Error error; PSNames_Service psnames; PSAux_Service psaux; FT_Face root = (FT_Face)&face->root; FT_UNUSED( num_params ); FT_UNUSED( params ); FT_UNUSED( face_index ); FT_UNUSED( stream ); face->ttf_face = NULL; face->root.num_faces = 1; face->psnames = FT_Get_Module_Interface( FT_FACE_LIBRARY( face ), "psnames" ); psnames = (PSNames_Service)face->psnames; face->psaux = FT_Get_Module_Interface( FT_FACE_LIBRARY( face ), "psaux" ); psaux = (PSAux_Service)face->psaux; /* open the tokenizer, this will also check the font format */ error = T42_Open_Face( face ); if ( error ) goto Exit; /* if we just wanted to check the format, leave successfully now */ if ( face_index < 0 ) goto Exit; /* check the face index */ if ( face_index != 0 ) { FT_ERROR(( "T42_Face_Init: invalid face index\n" )); error = T42_Err_Invalid_Argument; goto Exit; } /* Now, load the font program into the face object */ /* Init the face object fields */ /* Now set up root face fields */ root->num_glyphs = face->type1.num_glyphs; root->num_charmaps = 0; root->face_index = face_index; root->face_flags = FT_FACE_FLAG_SCALABLE; root->face_flags |= FT_FACE_FLAG_HORIZONTAL; root->face_flags |= FT_FACE_FLAG_GLYPH_NAMES; if ( face->type1.font_info.is_fixed_pitch ) root->face_flags |= FT_FACE_FLAG_FIXED_WIDTH; /* XXX: TODO -- add kerning with .afm support */ /* get style name -- be careful, some broken fonts only */ /* have a `/FontName' dictionary entry! */ root->family_name = face->type1.font_info.family_name; if ( root->family_name ) { char* full = face->type1.font_info.full_name; char* family = root->family_name; if ( full ) { while ( *family && *full == *family ) { family++; full++; } root->style_name = ( *full == ' ' ? full + 1 : (char *)"Regular" ); } else root->style_name = (char *)"Regular"; } else { /* do we have a `/FontName'? */ if ( face->type1.font_name ) { root->family_name = face->type1.font_name; root->style_name = (char *)"Regular"; } } /* no embedded bitmap support */ root->num_fixed_sizes = 0; root->available_sizes = 0; /* Load the TTF font embedded in the T42 font */ error = FT_New_Memory_Face( FT_FACE_LIBRARY( face ), face->ttf_data, face->ttf_size, 0, &face->ttf_face ); if ( error ) goto Exit; FT_Done_Size( face->ttf_face->size ); /* Ignore info in FontInfo dictionary and use the info from the */ /* loaded TTF font. The PostScript interpreter also ignores it. */ root->bbox = face->ttf_face->bbox; root->units_per_EM = face->ttf_face->units_per_EM; root->ascender = face->ttf_face->ascender; root->descender = face->ttf_face->descender; root->height = face->ttf_face->height; root->max_advance_width = face->ttf_face->max_advance_width; root->max_advance_height = face->ttf_face->max_advance_height; root->underline_position = face->type1.font_info.underline_position; root->underline_thickness = face->type1.font_info.underline_thickness; root->internal->max_points = 0; root->internal->max_contours = 0; /* compute style flags */ root->style_flags = 0; if ( face->type1.font_info.italic_angle ) root->style_flags |= FT_STYLE_FLAG_ITALIC; if ( face->ttf_face->style_flags & FT_STYLE_FLAG_BOLD ) root->style_flags |= FT_STYLE_FLAG_BOLD; if ( face->ttf_face->face_flags & FT_FACE_FLAG_VERTICAL ) root->face_flags |= FT_FACE_FLAG_VERTICAL; #ifdef FT_CONFIG_OPTION_USE_CMAPS { if ( psnames && psaux ) { FT_CharMapRec charmap; T1_CMap_Classes cmap_classes = psaux->t1_cmap_classes; FT_CMap_Class clazz; charmap.face = root; /* first of all, try to synthetize a Unicode charmap */ charmap.platform_id = 3; charmap.encoding_id = 1; charmap.encoding = ft_encoding_unicode; FT_CMap_New( cmap_classes->unicode, NULL, &charmap, NULL ); /* now, generate an Adobe Standard encoding when appropriate */ charmap.platform_id = 7; clazz = NULL; switch ( face->type1.encoding_type ) { case T1_ENCODING_TYPE_STANDARD: charmap.encoding = ft_encoding_adobe_standard; charmap.encoding_id = 0; clazz = cmap_classes->standard; break; case T1_ENCODING_TYPE_EXPERT: charmap.encoding = ft_encoding_adobe_expert; charmap.encoding_id = 1; clazz = cmap_classes->expert; break; case T1_ENCODING_TYPE_ARRAY: charmap.encoding = ft_encoding_adobe_custom; charmap.encoding_id = 2; clazz = cmap_classes->custom; break; case T1_ENCODING_TYPE_ISOLATIN1: charmap.encoding = ft_encoding_latin_1; charmap.encoding_id = 3; clazz = cmap_classes->unicode; break; default: ; } if ( clazz ) FT_CMap_New( clazz, NULL, &charmap, NULL ); /* Select default charmap */ if (root->num_charmaps) root->charmap = root->charmaps[0]; } } #else /* !FT_CONFIG_OPTION_USE_CMAPS */ /* charmap support -- synthetize unicode charmap if possible */ { FT_CharMap charmap = face->charmaprecs; /* synthesize a Unicode charmap if there is support in the `PSNames' */ /* module */ if ( psnames && psnames->unicode_value ) { error = psnames->build_unicodes( root->memory, face->type1.num_glyphs, (const char**)face->type1.glyph_names, &face->unicode_map ); if ( !error ) { root->charmap = charmap; charmap->face = (FT_Face)face; charmap->encoding = ft_encoding_unicode; charmap->platform_id = 3; charmap->encoding_id = 1; charmap++; } /* XXX: Is the following code correct? It is used in t1objs.c */ /* simply clear the error in case of failure (which really) */ /* means that out of memory or no unicode glyph names */ error = T42_Err_Ok; } /* now, support either the standard, expert, or custom encoding */ charmap->face = (FT_Face)face; charmap->platform_id = 7; /* a new platform id for Adobe fonts? */ switch ( face->type1.encoding_type ) { case T1_ENCODING_TYPE_STANDARD: charmap->encoding = ft_encoding_adobe_standard; charmap->encoding_id = 0; break; case T1_ENCODING_TYPE_EXPERT: charmap->encoding = ft_encoding_adobe_expert; charmap->encoding_id = 1; break; case T1_ENCODING_TYPE_ARRAY: charmap->encoding = ft_encoding_adobe_custom; charmap->encoding_id = 2; break; case T1_ENCODING_TYPE_ISOLATIN1: charmap->encoding = ft_encoding_latin_1; charmap->encoding_id = 3; break; default: FT_ERROR(( "T42_Face_Init: invalid encoding\n" )); error = T42_Err_Invalid_File_Format; goto Exit; } root->charmaps = face->charmaps; root->num_charmaps = charmap - face->charmaprecs + 1; face->charmaps[0] = &face->charmaprecs[0]; face->charmaps[1] = &face->charmaprecs[1]; } #endif /* !FT_CONFIG_OPTION_USE_CMAPS */ Exit: return error; }