I had the same problem.
In a richtextbox editor, I fill a ribbon comobox with all the available font families and attach that font to that specific item in the combobox so that a user immediately sees how the font looks like.
When there was a font on the system which can't be rendered by WPF, the application would crash.
Looking at the stacktrace in the event viewer, I noticed that WPF tries to instantiate an object of the type System.Windows.Media.GlyphTypeface.
I found out that, when I try to instantiate that object myself in code (via the System.Windows.Media.Typeface type) and the TryGetGlyphTypeface() function would return false for my specific font settings, that font is not usable in WPF.
The code which solved the problem for me:
foreach (FontFamily aFontFamily in Fonts.SystemFontFamilies)
{
// Instantiate a TypeFace object with the font settings you want to use
Typeface ltypFace = new Typeface(aFontFamily, FontStyles.Normal, FontWeights.Normal, FontStretches.Normal);
// Try to create a GlyphTypeface object from the TypeFace object
GlyphTypeface lglyphTypeFace;
if (ltypFace.TryGetGlyphTypeface(out lglyphTypeFace))
{
// Creation of the GlyphTypeface worked. You can use the font
RibbonGalleryItem lribItem = new RibbonGalleryItem();
lribItem.Content = aFontFamily.Source;
lribItem.FontFamily = aFontFamily;
lribGalCatFont.Items.Add(lribItem);
}
}
To prevent that this code must be executed everytime I load the combobox (and that's quite a lot because it's in a user control), I do this one time at the start of the application and save the array of usable fonts in a global variable.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…