drawFittedText horizontal scale memory

I found that on OS X (CoreGraphicsContext) that drawFittedText affects the horizontal scale for later drawText calls.

Using "Font font = g.getCurrentFont();" around "g.setFont(font);" works around the problem.

CoreGraphicsContext::setFont gets called within drawFittedText and saves the squished font in state->font, which is used in later calls of drawText.

Thanks - I'll figure out a workaround for that! (I'll need to find something more efficient than just saving and restoring the font each time)

I just ran into this on JUCE 5.4.5 on MacOS 10.15. No fix in sight?


I’m also suffering this issue with JUCE 5.4.6

Had to resort to @yairadix method:

  Font font = g.getCurrentFont();

It would be preferable if JUCE did this on macOS by itself as an interim fix if there is not a more efficient method ready.

1 Like

I just checked whether this issue was still relevant, and it seems to have been fixed in this commit:

I tested by adding the following code to a resizable component:

void paint (Graphics& g) override
    auto b = getLocalBounds();
    g.setColour (juce::Colours::white);
    g.drawFittedText ("this is a long string which will compress and squish and stuff like that", b.removeFromTop (30), juce::Justification::left, 1);
    g.drawSingleLineText ("some text is here", 0, getHeight() / 2);
    g.drawText ("this is another line", b.removeFromTop (30), juce::Justification::left);

If you’re still seeing incorrect rendering, please could you provide a code example (preferably a PIP or similar) which demonstrates the problem? In the meantime, I’m considering this issue closed.

1 Like