From 0f3bad8152c561a6767e767f985b2ec90aadfdce Mon Sep 17 00:00:00 2001 From: Tom Poole Date: Tue, 15 Oct 2024 12:12:21 +0100 Subject: [PATCH] Font: Avoid a crash on systems with no fonts installed --- modules/juce_graphics/fonts/juce_Font.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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)