Is there an easy way (in .Net) to test if a Font is installed on the current machine?
A:
How do you get a list of all the installed fonts?
var fontsCollection = new InstalledFontCollection();
foreach (var fontFamiliy in fontsCollection.Families)
{
if (fontFamiliy.Name == fontName) ... \\ installed
}
See InstalledFontCollection class for details.
aku
2008-09-22 09:38:57
+2
A:
string fontName = "Consolas";
float fontSize = 12;
Font fontTester = new Font(
fontName,
fontSize,
FontStyle.Regular,
GraphicsUnit.Pixel );
if ( fontTester.Name == fontName )
{
// Font exists
}
else
{
// Font doesn't exist
}
Jeff Hillman
2008-09-22 09:39:17
+3
A:
Thanks to Jeff, I have better read the documentation of the Font class:
If the familyName parameter specifies a font that is not installed on the machine running the application or is not supported, Microsoft Sans Serif will be substituted.
The result of this knowledge:
private bool IsFontInstalled(string fontName) {
using (var testFont = new Font(fontName, 8)) {
return 0 == string.Compare(
fontName,
testFont.Name,
StringComparison.InvariantCultureIgnoreCase);
}
}
GvS
2008-09-22 09:56:24
A:
I would prefer the first solution of creating the font and testing that name rather than getting all the installed font names and searching for a particular name.
Regards,
Vijendra Kumar H.
2010-07-29 09:59:36