How to get list of all characters (unicode and regular) supported by a Font?

I am attempting to create my own font fallback system in UI Toolkit (Label) for multilanguage support.

I have some stylized English fonts I really like which will be primary my first choice for some purposes. I want to make a list of all the unicode/regular characters in each of those fonts.

Then when I try to update a Label with a new string, I want to test the string to make sure it doesn’t have any characters outside the list supported by the intended “stylized” English Font. ie. Test each character of the new string against my lists of supported characters.

If the new string has a character outside that list, I will instead assign a more generic backup font which covers most of the full Unicode range.

I see a script here for creating lists of glyphs within a font:

However, I cannot use it in Unity as it seems to rely on System.Windows.Media which is not available in my Visual Studio from Unity.

Is there any default way of doing this for a given Font that you have loaded into Unity? Thanks.

TextMeshPro supports this already (if you are using it?)

https://docs.unity3d.com/Packages/com.unity.textmeshpro@3.2/manual/FontAssetsFallback.html

1 Like

Not using it. Using UI Toolkit (Label) so need to do a manual method to figure this out and solve it each time I update the Label text.

Well - you could just use TMPro to get the list of missing glyphs. When you create a font atlas, the TMPro window tells you what glyphs are missing. That could help?

Someone posted a method on StackExchange which should in theory work:

Font font = Resources.Load<Font>("path");
        Debug.Log("char info size " + font.characterInfo.Count());

        foreach (var item in font.characterInfo) {
            Debug.Log("Font index " + item.index);//unicode value
        }

However this code doesn’t work. Even with a correctly loaded Font (works for actual font purposes) font.characterInfo.Count() returns as zero.

Any thoughts?

Maybe something to do with your font import settings?

From the manual, just in case:

Thanks guys. It was an issue where if you don’t set the Font to Unicode it won’t give the charInfo. But if you set the Font to Unicode you can’t get it to display regular plain typed characters.

The better solution for my needs was to use Font.HasCharacter and just test each string I need character by character with it on demand.

1 Like

Anyone who is interested in getting the full char set of a dynamic font asset,
there is another thread which has a solution for that: ** Pick all chars from TTF **

1 Like