Request: Setting a default Sans Serif Style

There are many fonts which come with a set of variants like 'Light, Semilight, Bold, Semibold, Regular, etc...'

I would like to use some font as 'Semilight' throughout my entire applicaiton. How about adding an optional parameter to setDefaultSansSerifTypefaceName for the typeface style?

I guess you could set the typeface style in LookAndFeel::getTypefaceForFont. Just add f.setTypefaceStyle(defaultStyle), right after the 'setTypefaceName' line.


On a sidenote,

I have many fonts which act weird when are set as the default sans font and have their style untouched. Notably Microsoft's Segoe UI and Google's Open Sans.

When I set their style, even to 'Regular', the irregularities stop and the fonts are drawn fine.

Hello Tsury,
it’s a pity that nobody answered you for 8 years :slight_smile:

But actually I have exactly the same question. Maybe you found out best solutions for more font styles then those four in enum FontStyleFlags.

I also wonder what is the best manner to use FontStyleFlags while I have each style in separated ttf file?

You can use LookAndFeel::setDefaultSansSerifTypeface to set a default typeface with a specific name and style.

Hmm… thanks for your help.
But as I understand when I call:

Then the default font is set to font which I pointed by myTypefacePtr ?
But myTypefacePtr can point only to one ttf file and I have separated files for italian, regular, bold etc. So how I can use them? It looks like I need reset myTypefacePtr to new ttf file and then call again setDefaultSansSerifTypeface(myTypefacePtr) to be able to use various styles?

You can override LookAndFeel::getTypefaceForFont to return custom faces that you might have loaded using Typeface::createSystemTypefaceFor. The implementation would probably do something like check if (font.getTypefaceName() == Font::getDefaultSansSerifFontName()), and then check font.getTypefaceStyle() and return different typefaces depending on whether the style was Italic, Regular, Bold etc.

Hmm… I’ve just tested it and it works fine. But the problem when I have more styles.

Even though setStyleFlags(const int newFlags) takes int as a parameter it always cast it (in some sophisticated manner) to some bit combination of Font::FontStyleFlags enums. And Font::getStyleFlags() also return int but it is also always combination of Font::FontStyleFlags.

If Font::setStyleFlags() and getStyleFlags() were virtual methods then it would be fine. But they are not virtual so I have no idea how to manage more styles.