diff --git a/modules/juce_graphics/fonts/juce_Font.cpp b/modules/juce_graphics/fonts/juce_Font.cpp index 2be250479f..91d223d8b6 100644 --- a/modules/juce_graphics/fonts/juce_Font.cpp +++ b/modules/juce_graphics/fonts/juce_Font.cpp @@ -765,8 +765,13 @@ int Font::getStringWidth (const String& text) const float Font::getStringWidthFloat (const String& text) const { - const auto w = getTypefacePtr()->getStringWidth (getMetricsKind(), text, getHeight(), getHorizontalScale()); - return w + (getHeight() * getHorizontalScale() * getExtraKerningFactor() * (float) text.length()); + if (auto typeface = getTypefacePtr()) + { + const auto w = typeface->getStringWidth (getMetricsKind(), text, getHeight(), getHorizontalScale()); + return w + (getHeight() * getHorizontalScale() * getExtraKerningFactor() * (float) text.length()); + } + + return 0; } void Font::findFonts (Array& destArray)