Embedded TTF showing strange characters in AlertWindows

I am trying to embed a font by serializing it and then using the L&F getTypefaceForFont() method to supplying the typeface. This works on Windows but on Mac I get strange results in Alertwindows, see the attached image. In other places the text is showing just fine.

I tried other embedded fonts too, all have the same behavior.

Anyone knows what can cause this? I tried the tip too and it does the same.

Very odd.. I've been using embedded typefaces quite often but have never seen anything like this - can you give me some kind of project I could use to reproduce it?

sure, here is a link to a modified HelloWorld project that displays an AlertWindow if you click the Quit button. This shows normal text in Windows but not on Mac, at least on my 10.9 Mac



The CustomTypeface class can't be used with by the CoreGraphics text layout, which is used to create the text in an AlertWindow.

I've already mentioned this elsewhere, but I'd actually recommend treating the CustomTypeface class as deprecated nowadays. Since I added support for loading real TTF files with Typeface::createSystemTypefaceFor(), the easiest and best way to embed fonts is to simply embed the original TTF and use that.

But thanks for raising this - I'll add an assertion to catch people who are trying to use the CustomTypeface class in this way and explain what's wrong..

Thanks, I missed that.

It works now, except 1 little issue. I think that in the OS method for createSystemTypeFaceFor (I mean OSXTypeface (const void* data, size_t dataSize)) the name specifier constant kCTFontFamilyNameKey should be replaced by kCTFontFullNameKey otherwise it is difficult to distinguish between different versions of the same font, like bold, italic.


Ok, thanks for the tip, I'll take a look at that!

..actually, are you sure that makes sense?

It's deliberately trying to get the family name, not including the style. The style name is stored separately.

Can you give an example of what names you had that made you suggest this change?

I have a ttf font that has 4 styles with names MyFont, MyFont Bold, MyFont Italic and MyFont Bold Italic.

In L&F getTypefaceForFont() I have:

Typeface::Ptr MyLookAndFeel::getTypefaceForFont (const Font& font)
    if (myTypeface != nullptr && font.getTypefaceName() == myTypeface->getName())
        return myTypeface;
    else if (myTypefaceBoldItalic != nullptr && font.getTypefaceName() == myTypefaceBoldItalic->getName())
        return myTypefaceBoldItalic;
    else if (myTypefaceItalic != nullptr && font.getTypefaceName() == myTypefaceItalic->getName())
        return myTypefaceItalic;
    else if (myTypefaceBold != nullptr && font.getTypefaceName() == myTypefaceBold->getName())
        return myTypefaceBold;

    return LookAndFeel::getTypefaceForFont (font);


In Windows it works ok because myTypeface->getName() returns MyFont, MyFont Bold etc, but on Mac it returns the family name MyFont only. Changing the name specifier constant solves this.

Changing the name might make this bit of code work, but would break lots of other people's code! You should be comparing both the family name and the style name to decide whether it's a match, don't you think?

Ok, but how do I get the family name in Windows. It seems to return the full name now...

...and it also seems that typefaces that are imported with the createSystemTypefaceFor() method not necessarily have the style property filled in. So how do we separate different types from a font family?

On OSX the name is loaded in the same way regardless of whether it's from memory or from disk.

But if you search for "TTFNameExtractor" you'll see the horrific amount of behind-the-scenes hackery I had to do to get any sort of name out of the font data on Windows..