I have a WPF application that uses the Roboto FontFamily as the primary font, but there may be languages that are not compatible with Roboto (i.e. Chinese). How can I programmatically determine if the language is not compatible with Roboto so that I can load the proper FontFamily? Roboto has different variations such as Light, Medium, Bold, Italic, etc. If the substitute font also has some of the variations, I would like to be able to choose those.
The list of languages supported by Windows 10 is as follows:
Afrikaans, Albanian, Amharic, Arabic, Armenian, Assamese, Azerbaijani, Bangla (Bangladesh), Bangla (India), Basque, Belarusian, Bosnian, Bulgarian, Catalan, Central Kurdish, Cherokee, Chinese (Simplified), Chinese (Traditional), Croatian, Czech, Danish, Dari - Persian (Afghanistan), Dutch, German, Greek, English (United Kingdom), English (United States), Estonian, Finnish, Filipino, French (Canada), French (France), Galician, Georgian, Gujarati, Hausa, Hebrew, Hindi, Hungarian, Icelandic, Igbo, Indonesian, Irish, Italian, Japanese, Kannada, Kazakh, Khmer, K'iche', Kinyarwanda, Konkani, Korean, Kyrgyz, Lao, Latvian, Lithuanian, Luxembourgish, Macedonian, Malay, Malayalam, Maltese, Maori, Marathi, Mongolian, Nepali, Northern Sotho, Norwegian Bokmål, Norwegian Nynorsk, Odia, Persian (Iran), Punjabi (Arabic), Punjabi (Gurmukhi), Polish, Portuguese (Brazil), Portuguese (Portugal), Quechua, Romanian, Russian, Scottish Gaelic, Serbian (Cyrillic, Bosnia & Herzegovina), Serbian (Cyrillic, Serbia), Serbian (Latin), Sindhi (Arabic), Sinhala, Slovak, Slovenian, Spanish (Spain), Spanish (Mexico), Swahili, Swedish, Tajik, Tamil, Tatar, Telugu, Thai, Tigrinya, Tswana, Turkish, Turkmen, Ukrainian, Urdu, Uyghur, Uzbek, Valencian, Vietnamese, Welsh, Wolof, Xhosa, Yoruba, Zulu.
Is there a list of Windows 10 languages that Roboto supports, or a list of languages that Roboto does not support? I have not been able to find such a list.
CodePudding user response:
- Knowing which language font supports is not really a thing; you can only know what glyphs it contains. (E.g. a comma is not per se a "English", "Russian", or "Farsi" symbol, but it is in a font). To more broadly know that a font is suitable for displaying certain language, you can check a range of symbols that are usually used for that language (you can look at them here or here). In C# 3.0 and later, you can use GlyphTypeface.CharacterToGlyphMap to do that. For example, if you want to know if your font supports arabic characters, you would first check which unicode range contains arabic glyphs (that would be 0600-06FF), and than you can check if your font file contains them. Here's an example (returns true if all relevant glyps are present, false if we failed to find something):
private bool FontSuitableForArabic()
{
(int, int) langSymbolsRange;
langSymbolsRange.Item1 = 0x600;
langSymbolsRange.Item2 = 0x6FF;
var families = Fonts.GetFontFamilies(@"C:\Users\User\Documents\Temp\TestFonts\Roboto-Regular.TTF");
foreach (var family in families)
{
var typefaces = family.GetTypefaces();
foreach (Typeface typeface in typefaces)
{
GlyphTypeface glyph;
typeface.TryGetGlyphTypeface(out glyph);
IDictionary<int, ushort> characterMap = glyph.CharacterToGlyphMap;
for (int i = langSymbolsRange.Item1; i != langSymbolsRange.Item2; i )
{
if (!characterMap.TryGetValue(i, out ushort _))
{
Console.WriteLine($"Failed to find Unicode Character {i:X} in this font!");
return false;
}
}
}
}
return true;
}
- Most of the times, you don't really need to do that, since WPF has font fallback system, as described in this question. To specify your own fallback fonts, you'd use the FontFamily class. E.g. you want to use Roboto, and when it doesn't have, say, Arabic characters, you want to use Janna LT Bold:
myTextBlock.FontFamily = new FontFamily("Roboto, Janna LT Bold");
or
<TextBlock FontFamily="Roboto, Janna LT Bold">Hello, world</TextBlock>
CodePudding user response:
I contacted the Google Fonts team about Roboto support for Windows 10 languages and the reply was:
Use hyperglot.rosettatype.com to determine language support for any font
Using this website, the following Windows 10 languages are NOT supported by Roboto:
Amharic, Arabic, Armenian, Assamese, Azerbaijani, Bangla (Bangladesh), Bangla (India), Belarusian, Bosnian, Cherokee, Chinese (Simplified), Chinese (Traditional), Dari - Persian (Afghanistan), Georgian, Gujarati, Hausa, Hebrew, Hindi, Igbo, Kannada, Khmer, Konkani, Korean, Kyrgyz, Lao, Malayalam, Marathi, Nepali, Odia, Persian, Punjabi, Romanian, Sindhi, Sinhala, Tamil, Telugu, Thai, Tigrinya, Urdu, Uyghur, Valencian, Yoruba