void i_tt_dump_names(TT_Fonthandle *handle) { TT_Face_Properties props; int name_count; int i; TT_UShort platform_id, encoding_id, lang_id, name_id; TT_UShort name_len; TT_String *name; TT_Get_Face_Properties(handle->face, &props); name_count = props.num_Names; for (i = 0; i < name_count; ++i) { TT_Get_Name_ID(handle->face, i, &platform_id, &encoding_id, &lang_id, &name_id); TT_Get_Name_String(handle->face, i, &name, &name_len); printf("# %d: plat %d enc %d lang %d name %d value ", i, platform_id, encoding_id, lang_id, name_id); if (platform_id == TT_PLATFORM_APPLE_UNICODE) { printf("(unicode)\n"); } else { printf("'%s'\n", name); } } fflush(stdout); }
static void image_ttf_face__names(INT32 args) { int ns,res; TT_UShort i; TT_Face face=THISf->face; pop_n_elems(args); if ((ns=TT_Get_Name_Count(face))==-1) Pike_error("Image.TTF.Face->names(): Illegal face handler\n"); for (i=0; i<ns; i++) { unsigned short platformID,encodingID,languageID,nameID; TT_UShort length; char *stringPtr; if ((res=TT_Get_Name_ID(face,i, &platformID,&encodingID,&languageID,&nameID))) my_tt_error("Image.TTF.Face->names()","TT_Get_Name_ID: ",res); push_int(platformID); push_int(encodingID); push_int(languageID); push_int(nameID); if ((res=TT_Get_Name_String(face,i,&stringPtr,&length))) my_tt_error("Image.TTF.Face->names()","TT_Get_Name_String: ",res); push_string(make_shared_binary_string(stringPtr,length)); f_aggregate(5); } f_aggregate(ns); }
static char* LookUp_Name( int index ) { unsigned short i, n; unsigned short platform, encoding, language, id; char* string; unsigned short string_len; int j, found; n = properties.num_Names; for ( i = 0; i < n; i++ ) { TT_Get_Name_ID( face, i, &platform, &encoding, &language, &id ); TT_Get_Name_String( face, i, &string, &string_len ); if ( id == index ) { /* The following code was inspired from Mark Leisher's */ /* ttf2bdf package */ found = 0; /* Try to find a Microsoft English name */ if ( platform == 3 ) for ( j = 1; j >= 0; j-- ) if ( encoding == j ) /* Microsoft ? */ if ( (language & 0x3FF) == 0x009 ) /* English language */ { found = 1; break; } if ( !found && platform == 0 && language == 0 ) found = 1; /* Found a Unicode Name. */ if ( found ) { if ( string_len > 512 ) string_len = 512; name_len = 0; for ( i = 1; i < string_len; i += 2 ) name_buffer[name_len++] = string[i]; name_buffer[name_len] = '\0'; return name_buffer; } } } /* Not found */ return NULL; }
/* =item i_tt_face_name(handle, name_buf, name_buf_size) Retrieve's the font's postscript name. This is complicated by the need to handle encodings and so on. =cut */ size_t i_tt_face_name(TT_Fonthandle *handle, char *name_buf, size_t name_buf_size) { TT_Face_Properties props; int name_count; int i; TT_UShort platform_id, encoding_id, lang_id, name_id; TT_UShort name_len; TT_String *name; int want_index = -1; /* an acceptable but not perfect name */ int score = 0; i_clear_error(); TT_Get_Face_Properties(handle->face, &props); name_count = props.num_Names; for (i = 0; i < name_count; ++i) { TT_Get_Name_ID(handle->face, i, &platform_id, &encoding_id, &lang_id, &name_id); TT_Get_Name_String(handle->face, i, &name, &name_len); if (platform_id != TT_PLATFORM_APPLE_UNICODE && name_len && name_id == TT_NAME_ID_PS_NAME) { int might_want_index = -1; int might_score = 0; if ((platform_id == TT_PLATFORM_MACINTOSH && encoding_id == TT_MAC_ID_ROMAN) || (platform_id == TT_PLATFORM_MICROSOFT && encoding_id == TT_MS_LANGID_ENGLISH_UNITED_STATES)) { /* exactly what we want */ want_index = i; break; } if (platform_id == TT_PLATFORM_MICROSOFT && (encoding_id & 0xFF) == TT_MS_LANGID_ENGLISH_GENERAL) { /* any english is good */ might_want_index = i; might_score = 9; } /* there might be something in between */ else { /* anything non-unicode is better than nothing */ might_want_index = i; might_score = 1; } if (might_score > score) { score = might_score; want_index = might_want_index; } } } if (want_index != -1) { TT_Get_Name_String(handle->face, want_index, &name, &name_len); strncpy(name_buf, name, name_buf_size); name_buf[name_buf_size-1] = '\0'; return strlen(name) + 1; } else { i_push_error(0, "no face name present"); return 0; } }