D2D: Embedded fonts don't work at all

My app uses embedded fonts (BinaryResource), and when switching to the Direct2D preview branch, no text is rendered at all.

OK, let’s sort that out.

I restested embedded fonts and they are working for me, except for painting a multi-line AttributedString.

Here’s what I’m doing:

    void paint(Graphics& g) override

        g.drawText(hindRegular.toString(), 0, 0, getWidth(), 50, juce::Justification::centred);

    Font const hindRegular{ Typeface::createSystemTypefaceFor(BinaryData::HindRegular_ttf, BinaryData::HindRegular_ttfSize) };

and of course the the font is embedded as a binary resource.

I also tried the rest of the text painting routines and they all seemed to work with the exception of the AttributedString issue I mentioned above. I’ll track that down.

Could you please provide more details, such as what font are you using, how you drawing your text, etc.?



OK, I found the AttributedString problem.

I don’t know if it’s related to the issue you’re reporting though. You could try commenting out this line in AttributedString::draw; of course, if you aren’t using AttributedString objects this won’t help much.

void AttributedString::draw (Graphics& g, const Rectangle<float>& area) const
    if (text.isNotEmpty() && g.clipRegionIntersects (area.getSmallestIntegerContainer()))
        jassert (text.length() == getLength (attributes));

        // comment out the if
        //if (! g.getInternalContext().drawTextLayout (*this, area.withHeight(std::numeric_limits<float>::max())))
            TextLayout layout;
            layout.createLayout (*this, area.getWidth());
            layout.draw (g, area);


Hey Matt,

First of all. Thanks for all this work!
After talking with you about it during the pup quiz at ADC I was looking forward to test it.

We do have the same issue though. No text rendering (and we’re using embedded fonts).
Commenting out the line did not help.

What we are doing is similar to what you suggested:

juce::Typeface::Ptr Look::getBaseFont()
    static const juce::Typeface::Ptr typeface = juce::Typeface::createSystemTypefaceFor (BinaryData::RobotoRegular_ttf, BinaryData::RobotoRegular_ttfSize);
    return typeface;

Would it not be beneficial to add an OTF and TTF font to the demo so as to test these embedded font features properly, and across the board? I don’t mean just for D2D’s sake, but for checking that the feature is working appropriately on each platform.


Hi Marcel-

Good to hear from you!

Is the problem that the creation of the typeface? Or is the typeface created properly, but the text doesn’t paint?


OK, I was able to reproduce it.


Not looked into it under the surface…
I can, if you need more details, but I see you’re able to reproduce it.

Same typeface (Roboto), although I’ve used the Medium variant.

Try changing the ‘>=’ to ‘>’ in:



        JUCE_COMRESULT ReadFileFragment (void const** fragmentStart,
                                         UINT64       fileOffset,
                                         UINT64       fragmentSize,
                                         void**       fragmentContext) noexcept override
            if (fileOffset + fragmentSize > rawData.numBytes) // should be '>', not '>='
                *fragmentStart   = nullptr;
                *fragmentContext = nullptr;
                return E_INVALIDARG;

            *fragmentStart   = addBytesToPointer (rawData.data, fileOffset);
            *fragmentContext = this;
            return S_OK;

Only happens with certain fonts - I was using Hind & Montserrat, which worked fine. Roboto works now with this fix.


That absolutely worked.
Oh and how much better the font rendering looks! :heart_eyes:

1 Like


Yep, font rendering works now. Great :smiley:

Attributed strings look different (thinner) than strings drawn with g.drawText. Not sure, why.

1 Like