WPF Bold Font - Use a different font or set Font weight?

817 Views Asked by At

How do I know when I should be appending "Bold" to the name of the font vs setting the font weight? I have the following test function to demonstrate the issue:

public static bool IsBoldFont(string fontName, System.Windows.FontWeight fontWeight)
{
    var typeface = new System.Windows.Media.Typeface(new System.Windows.Media.FontFamily(fontName), System.Windows.FontStyles.Normal, fontWeight, System.Windows.FontStretches.Normal);
    typeface.TryGetGlyphTypeface(out System.Windows.Media.GlyphTypeface glyphTypeface);
    return glyphTypeface.Weight == System.Windows.FontWeights.Bold;
}

And these are the results:

IsBoldFont("Arial Narrow", System.Windows.FontWeights.Bold); // false
IsBoldFont("Arial Narrow Bold", System.Windows.FontWeights.Regular); // true
IsBoldFont("Arial", System.Windows.FontWeights.Bold); // true

-- Update --

I think I simplified my question a bit too much. I am converting from one software package to another. The font specified is "Arial Narrow" and Bold weight (like in MS Word - select the font, then apply the Bold Weight to it, the Font "Arial Narrow Bold" does not exist in the list of fonts).

When converting the text to draw on the canvas, the font is not drawing Bold when I am asking for ("Arial Narrow", System.Windows.FontWeights.Bold), however it is correct when changing the font family name to ("Arial Narrow Bold", System.Windows.FontWeights.Regular). How am I supposed to know to append " Bold" to the end of the family name?

0

There are 0 best solutions below