Do not understand how fonts are working on Windows

I don’t understand what happens when you specify a font that doesn’t exist, on Windows.

For example, I’m moving a project over that I’ve been working on on Mac OS. I have a font specified which exists on the Mac, which is “PT Sans Caption”.

In the code, I’m doing something like:

	Font globalFont;

    globalFont = Font("PT Sans Caption", 14.0f, Font::plain);

On Windows, this font does not exist.

Instead, I get a sans serif font that I recently installed named “Hendra”.

So I try this on Windows:

    Font::setFallbackFontName("Microsoft Sans Serif");
    globalFont = Font("PT Sans Caption", 14.0f, Font::plain);

    String s = globalFont.getTypeface()->getName();

When I check the string, it still shows “PT Sans Caption” even after not finding it, and specifying a fallback font. It doesn’t show “Hendra” which is what it actually draws with.

What is it doing if the font does not exist? Locating something that it thinks will work? Why doesn’t it get the default, which is Microsoft Sans Serif? Why doesn’t it show the name of the actual font it is using, in the String?

I have a feeling I’m misunderstanding something here. Thanks.

Sets the (platform-specific) font family of the typeface to use to find glyphs that aren’t available in whatever font you’re trying to use.

It’s not a fallback font how you envisioned, instead if say your “PT Sans Caption” font had no glyph for é, then it would fallback to using which font was specified by Font::setFallbackName is the way I understand that.

The easiest way to achieve this would be just wrap two different code paths with the platform macros:

  globalFont = Font("PT Sans Caption", 14.0f, Font::plain);
  globalFont = Font("Microsoft Sans Serif", 14.0f, Font::plain);

(assuming you’re not targeting Linux)

Afraid I don’t know the answers to your other questions.

I see… thanks. Then what is it doing when I’m giving it a font that doesn’t exist?

Yes, I can do something like that; in fact, once I figure out what font I want to commit to using, I’ll embed it so it’s the same on both operating systems and all computers.

However, right now I’d like to understand what it is doing; and how it is intended to work - why it is using the font “Hendra” instead of the default Windows font…?

someone once suggested to me to do the following which worked:

  1. drag custom font into source folder

  2. use projucer to add the file to the project

  3. add this to your custom lookAndFeel-class:

    static const Font& getCustomFont() {
    static Font custFont(Font(Typeface::createSystemTypefaceFor(BinaryData::zig__ttf, BinaryData::zig__ttfSize)));
    return custFont;

then use this function to get your font from the binaryData. you just have to replace the word “zig” with your font’s name, because zig is how mine’s called.

I’m afraid I can’t answer that question, either a case of really deep diving in the code or asking someone from the JUCE team to give an answer.

I was hoping that was part of what I was doing here. :wink: