Problems with Embedded fonts


#1

I’ve two fonts in my project, a default font, and a monospaced font.
I use two functions:

Font getDefaultFont (float size, Font::FontStyleFlags style) noexcept
{
    Font font;

    if (style == Font::FontStyleFlags::plain)
        font = Font (Typeface::createSystemTypefaceFor (BinaryData::Vera_ttf, BinaryData::Vera_ttfSize));
        
    else if (style == Font::FontStyleFlags::italic)
        font = Font (Typeface::createSystemTypefaceFor (BinaryData::VeraItalic_ttf, BinaryData::VeraItalic_ttfSize));

    else if (style == Font::FontStyleFlags::bold)
        font = Font (Typeface::createSystemTypefaceFor (BinaryData::VeraBold_ttf, BinaryData::VeraBold_ttfSize));


    font.setHeight (size);
    return font;
};

Font getDefaultMonoFont (float size, Font::FontStyleFlags style) noexcept
{
    Font font;
    
    if (style == Font::FontStyleFlags::plain)
        font = Font (Typeface::createSystemTypefaceFor (BinaryData::VeraMono_ttf, BinaryData::VeraMono_ttfSize));
        
    else if (style == Font::FontStyleFlags::italic)
        font = Font (Typeface::createSystemTypefaceFor (BinaryData::VeraMonoItalic_ttf, BinaryData::VeraMonoItalic_ttfSize));

    else if (style == Font::FontStyleFlags::bold)
        font = Font (Typeface::createSystemTypefaceFor (BinaryData::VeraMonoBold_ttf, BinaryData::VeraMonoBold_ttfSize));
        
    font.setHeight (size);
    return font;
};

Every time I use Font f = getDefaultFont (size,style); in my components

In OSX works ok, but in windows, I get laggy text rendering, for example laggy popups menu.
I don’t know about typefaces or text rendering engines, but I think that is because Typeface::createSystemTypefaceFor needs to “compile” every time the ttf file.

Is there a juce way to use custom embed fonts?
Thanks!


#2

Ok i solved it, The solution:

CustomLookAndFeel::CustomLookAndFeel()
: monospaceTypefacePlain  (Typeface::createSystemTypefaceFor (BinaryData::VeraMono_ttf, BinaryData::VeraMono_ttfSize)),
  monospaceTypefaceItalic (Typeface::createSystemTypefaceFor (BinaryData::VeraMonoItalic_ttf, BinaryData::VeraMonoItalic_ttfSize)),
  monospaceTypefaceBold   (Typeface::createSystemTypefaceFor (BinaryData::VeraMonoBold_ttf, BinaryData::VeraMonoBold_ttfSize)),
  defaultTypefacePlain    (Typeface::createSystemTypefaceFor (BinaryData::Vera_ttf, BinaryData::Vera_ttfSize)),
  defaultTypefaceItalic   (Typeface::createSystemTypefaceFor (BinaryData::VeraItalic_ttf, BinaryData::VeraItalic_ttfSize)),
  defaultTypefaceBold     (Typeface::createSystemTypefaceFor (BinaryData::VeraBold_ttf, BinaryData::VeraBold_ttfSize))
{}

Typeface::Ptr CustomLookAndFeel::getTypefaceForFont (const Font& font)
{
    if (font.getTypefaceName() == "Default")
    {
        if (font.isBold())      return defaultTypefaceBold;
        if (font.isItalic())    return defaultTypefaceItalic;
                                return defaultTypefacePlain;
    }
    
    if (font.getTypefaceName() == "Monospace")
    {
        if (font.isBold())      return monospaceTypefaceBold;
        if (font.isItalic())    return monospaceTypefaceItalic;
                                return monospaceTypefacePlain;
    }
    
    return LookAndFeel::getTypefaceForFont(font);
};