Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if a font supports a specific style

I'm getting the following exception when changing my application font, because I use a strike out in a part of my application, and some fonts don't support it:

enter image description here

I change my application font using a font dialog. I need to check if the selected font supports the strikeout style after assigning it to my application.

What is the recommended way to do this? I know I could create a font with the style and catch the exception, but is there a more elegant way to do it?

Thanks in advance.


EDIT: The user selects a font, not necesary strikeout. In that moment I need to check if the font supports the style strikeout, because I create a strikeout font in a part of my application. If the font don't support the strikeout style would not allow the user to choose that font.

like image 672
Daniel Peñalba Avatar asked Oct 24 '22 01:10

Daniel Peñalba


1 Answers

Updated : (to reflect update in the initial post):

InstalledFontCollection ifc = new InstalledFontCollection();
for (int i = 0; i < ifc.Families.Length; i++)
    {
         if (ifc.Families[i].IsStyleAvailable(FontStyle.StrikeOut))
         {
             //add particular font with this family to your "font selector"
         }
    }
like image 172
Andrey Taptunov Avatar answered Nov 15 '22 05:11

Andrey Taptunov