Reputation: 683
I am building a Windows 10 universal app in C# that has to list the names of the installed fonts on the system. The app was a metro/modern ui/windows 8.1 app and I used the SharpDX 'trick' there to get the names.
SharpDX is not available (yet?) for Windows 10 UAP, so that does not work anymore.
Any other ways to achieve my goal? Should I consider a fixed list of font names as described here under recommended fonts? This seems rather limiting when on a desktop for instance.
Thanks in advance!
Upvotes: 5
Views: 3500
Reputation: 33397
I decided for the fixed list approach. It does not require Win2D.
If someone is interested, here is the list of fonts that are guaranteed to be available in all Windows 10 editions that support UWP apps:
Parsed from https://msdn.microsoft.com/en-us/library/windows/apps/hh700394.aspx
public static string[] FontNames = {
"Arial", "Calibri", "Cambria", "Cambria Math", "Comic Sans MS", "Courier New",
"Ebrima", "Gadugi", "Georgia",
"Javanese Text Regular Fallback font for Javanese script", "Leelawadee UI",
"Lucida Console", "Malgun Gothic", "Microsoft Himalaya", "Microsoft JhengHei",
"Microsoft JhengHei UI", "Microsoft New Tai Lue", "Microsoft PhagsPa",
"Microsoft Tai Le", "Microsoft YaHei", "Microsoft YaHei UI",
"Microsoft Yi Baiti", "Mongolian Baiti", "MV Boli", "Myanmar Text",
"Nirmala UI", "Segoe MDL2 Assets", "Segoe Print", "Segoe UI", "Segoe UI Emoji",
"Segoe UI Historic", "Segoe UI Symbol", "SimSun", "Times New Roman",
"Trebuchet MS", "Verdana", "Webdings", "Wingdings", "Yu Gothic",
"Yu Gothic UI"
};
Particularly, for my application, I removed from this list a few that do not interest me, like Javanese Text Regular Fallback font for Javanese script
plus those Microsoft *
asian languages and Segoe MDL2 Assets
plus (Web|Wing)dings
which are only for icons.
Upvotes: 2
Reputation: 21899
Same basic idea: you'll still use DirectWrite to get the font names.
You can use Win2D to get to DirectWrite from C# in both Windows 8.1 and Universal Windows Platform apps. CanvasTextFormat.GetSystemFontFamilies will return the font families:
string[] fonts = Microsoft.Graphics.Canvas.Text.CanvasTextFormat.GetSystemFontFamilies();
foreach (string font in fonts)
{
Debug.WriteLine(string.Format("Font: {0}", font));
}
Upvotes: 9