From d73b1768a78989694ed3415d68c129b71919fe65 Mon Sep 17 00:00:00 2001 From: attila Date: Tue, 7 Jan 2025 17:22:27 +0100 Subject: [PATCH] Fall back to default sans serif font if resolution would fail otherwise This restores the JUCE 7 behaviour when the JUCE 8 font fallback mechanism fails to resolve a non-null Typeface::Ptr. This behaviour is significant when the base font specified is not available on the system. --- modules/juce_graphics/fonts/juce_Font.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/modules/juce_graphics/fonts/juce_Font.cpp b/modules/juce_graphics/fonts/juce_Font.cpp index 59e07b3e13..92fd06192f 100644 --- a/modules/juce_graphics/fonts/juce_Font.cpp +++ b/modules/juce_graphics/fonts/juce_Font.cpp @@ -836,9 +836,19 @@ Font Font::findSuitableFontForText (const String& text, const String& language) return copy; } - if (auto current = getTypefacePtr()) + const auto fallbackTypefacePtr = std::invoke ([&] { - if (auto suggested = current->createSystemFallback (text, language)) + if (auto current = getTypefacePtr()) + return current; + + auto copy = *this; + copy.setTypefaceName (Font::getDefaultSansSerifFontName()); + return copy.getTypefacePtr(); + }); + + if (fallbackTypefacePtr != nullptr) + { + if (auto suggested = fallbackTypefacePtr->createSystemFallback (text, language)) { auto copy = *this;