Since most platforms include more than 100 fonts which come in all shapes, design and size, scanning thru all these fonts looking for individual glyphs is not a viable solution in my opinion.
Instead, I think developers / designers should carefully select what fonts they wish to use on these platform and for any given language or groups of languages. This would ensure the selected system fonts not only include the appropriate glyph coverage for the target languages but also work well from a design point of view with other fonts used in the application.
Most platforms do publish a list of fonts available on their platforms. Here is a link to the fonts available on Apple platforms. No doubt a similar list is available for Android.
Alternatively, one can always use Font.GetPathsToOSFonts() on those different platforms to get a list of those fonts to then make their selection of which fonts they will specifically load / use at runtime and for any given language or groups of languages.
There are many popular fonts available on Android and iOS such as NotoSans which have coverage from most languages.
Basically, I recommend compiling a list of the various fonts you will be searching on specific platforms and for specific languages.
“Roboto”,
“Noto Sans CJK SC”,
“Noto Sans Mono CJK SC”,
“Noto Sans SC”,
“Noto Sans CJK TC”,
“Noto Sans Mono CJK TC”,
“Noto Sans TC”,
“Noto Sans CJK KR”,
“Noto Sans Mono CJK KR”,
“Noto Sans KR”,
“Droid Sans Hangul”,
“Noto Sans CJK JP”,
“Noto Sans Mono CJK JP”,
“Noto Sans JP”,
“Droid Sans Japanese”,
“MotoyaLMaru”,
“NanumGothic”,
“Droid Sans”,
“Droid Sans Fallback”,
“DroidSansFallback”
Note that I am planning on introducing “Dynamic OS” font assets where in the Editor, they will use whatever font you have assigned to them and at runtime on the target platform lookup that font by name. There are more details but the plan is to make it much easier to work with OS fonts.
Until then, I would suggest a revised approach to your implementation when it comes to searching font files for potential characters.
Instead of creating a new Font object and then creating a new font asset, I would use
public static FontEngineError LoadFontFace(string filePath)
to load the font using the path returned by PathsToOSFonts().
then use the following function to check if a valid glyphIndex is returned. Zero means a missing glyph.
public static bool TryGetGlyphIndex(uint unicode, out uint glyphIndex);
Then when you know the font file does contain the unicode you need, create the font object and font asset.
Doing the above should be more efficient.
The above is still not ideal. As a result of this thread, I will be adding a new function UnloadFontFace(); to unload the previously loaded font face. This would make it much more efficient to iterate through lots of font files to peek into them and then unload them when needed.
Although this new UnloadFontFace() function is not available, you can use FontEngine.DestroyFontEngine(); but since you will no longer be creating a Font object first and then a font asset, you should be able to load several fonts to check for those glyphIndex and then destroy as needed. Ie. Not sure I would destroy after each face loaded.
Note, I am currently testing all of this but wanted to give you some feedback while I finish testing / exploring all of this. Ie. Standby for more information … So give this a try and let me know how it behaves.