# Fonts and typefaces

**URL:** <https://forum.juce.com/t/fonts-and-typefaces/66962>\
**Category:** General JUCE discussion\
**Created:** [August 28, 2025, 10:58am UTC](https://forum.juce.com/t/fonts-and-typefaces/66962 "2025-08-28T10:58:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![leehu](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/leehu/32/3280_2.png) [@leehu](https://forum.juce.com/u/leehu)\
**Post date:** [August 28, 2025, 10:58am UTC](https://forum.juce.com/t/fonts-and-typefaces/66962/1 "2025-08-28T10:58:59Z")

</div>

Hi,

I don’t know why, but I always find working with Fonts in juce to be difficutl and hit and miss.

For instance, I’m calling Typeface::scanFolderForFonts() to scan for some fonts, and then if I call Font::findAllTypefaceNames() the new typefaces show up. All good.

I then try and use one of the fonts by:

```auto
auto the_font( Font( typeface_name, style, 14 ) );

```

and it fails as it can’t find the font.

Any ideas?

Ideally, I don’t want to have to load the fonts from disk and would prefer to have them in resources, but can’t find any equivalent to Typeface::scanFolderForFonts() that works on in memory fonts. e.g. what is the standard practice for registering for example 6 fonts at startup and then using them with

```auto
auto the_font( Font( typeface_name, style, 14 ) );

```

thx

---

<div class="post-metadata">

**Author:** ![ibisum](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/ibisum/32/21288_2.png) [@ibisum](https://forum.juce.com/u/ibisum)\
**Post date:** [August 28, 2025, 11:26am UTC](https://forum.juce.com/t/fonts-and-typefaces/66962/2 "2025-08-28T11:26:57Z")

</div>

Having had to debug fonts a few times myself, here’s some tips:

- Dump the font names and be sure you’ve got the name right - ensure the typeface\_name you pass to Font matches one of these exactly.

```cpp
StringArray typefaces = Font::findAllTypefaceNames();
for (const auto& typeface : typefaces)
    DBG(typeface);

```

- Same with styles:

```cpp
StringArray styles = Font::findAllTypefaceStyles(typeface_name);
for (const auto& style : styles)
    DBG(style);

```

- Try constructing the font with a basic style or no style to isolate the issue:

```cpp
Font the_font(typeface_name, 14.0f); // No style specified
DBG("Font loaded: " + the_font.getTypefaceName());

```

- If you really need to be sure, embed the font as a BinaryResource in your project, and load it that way:
- 

```cpp
 void registerFont(const void* fontData, size_t dataSize, const String& typefaceName)
    {
        // Create a typeface from the font data in memory
        auto typeface = Typeface::createSystemTypefaceFor(fontData, dataSize);

        if (typeface != nullptr)
        {
            // Optionally, you can store the typeface in a global Typeface::Ptr for reuse
            // typefaceCache.add(typefaceName, typeface);

            // Create a Font object to register the typeface with JUCE's font system
            Font font(typeface);
            font.setTypefaceName(typefaceName);

            // Log for debugging
            DBG("Registered font: " + typefaceName);
        }
        else
        {
            DBG("Failed to load font: " + typefaceName);
        }
    }

```

- 

```cpp

```

- 

```cpp
void registerAllBinaryFonts()
{
    // Example: List of font resources (manually defined or generated)
    struct FontResource { const void* data; size_t size; String name; };
    Array<FontResource> fonts = {
        { BinaryData::Font1_ttf, BinaryData::Font1_ttfSize, "Font1" },
        { BinaryData::Font2_ttf, BinaryData::Font2_ttfSize, "Font2" },
        // Add more fonts
    };

    for (const auto& font : fonts)
        registerFont(font.data, font.size, font.name);
}

```

---

<div class="post-metadata">

**Author:** ![leehu](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/leehu/32/3280_2.png) [@leehu](https://forum.juce.com/u/leehu)\
**Post date:** [August 28, 2025, 11:37am UTC](https://forum.juce.com/t/fonts-and-typefaces/66962/3 "2025-08-28T11:37:32Z")

</div>

thx for the speedy reply - will go through this.

---

<div class="post-metadata">

**Author:** ![ibisum](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/ibisum/32/21288_2.png) [@ibisum](https://forum.juce.com/u/ibisum)\
**Post date:** [August 28, 2025, 11:46am UTC](https://forum.juce.com/t/fonts-and-typefaces/66962/4 "2025-08-28T11:46:34Z")

</div>

Welcome, let us know how you proceed. I have to debug font issues every few months - in the end I just resorted to setting the policy “all fonts needed in the design are included in the bundle and we register and manage them ourselves” ..

---

<div class="post-metadata">

**Author:** ![leehu](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/leehu/32/3280_2.png) [@leehu](https://forum.juce.com/u/leehu)\
**Post date:** [August 28, 2025, 1:45pm UTC](https://forum.juce.com/t/fonts-and-typefaces/66962/5 "2025-08-28T13:45:52Z")

</div>

Not really had any joy. In order “register” a font it seems like we need to call getTypefacePtr() in order to place it into the TypefaceCache.

````auto
if ( auto typeface = Typeface::createSystemTypefaceFor( p_data, size ) ) {
   Font font( typeface->getName(), typeface->getStyle(), 12.0 );
   font.getTypefacePtr();

   DBG( "Registered: " << font.getTypefaceName() << "-" << font.getTypefaceStyle() );

```
If there is a later use of

````

```auto
Font font( name, style, 12.0 );

```

then it does fetch the correct typeface from the cache supposedly but it doesn’t work consistently.

So far, the only way I’ve found to do this is to call Typeface::createSystemTypefaceFor( p\_data, size ) in the draw code and set the font directly from that. Not sure how efficient this is though. Just making the lookup static so it’s only done once in the function.

Don’t know why Font stuff in JUCE always seems to much effort to just load a font by name and use it.

---

<div class="post-metadata">

**Author:** ![pmbk](https://avatars.discourse-cdn.com/v4/letter/p/dec6dc/32.png) [@pmbk](https://forum.juce.com/u/pmbk)\
**Post date:** [September 15, 2025, 9:45pm UTC](https://forum.juce.com/t/fonts-and-typefaces/66962/6 "2025-09-15T21:45:54Z")

</div>

If you’re going this route, you can also use `FontOptions::withFallbackEnabled(false)` to avoid a decent portion of `findSuitableFontsForText`.
