From 83dc660a306388302f24788695d29d827408e6f3 Mon Sep 17 00:00:00 2001 From: attila Date: Thu, 10 Oct 2024 15:35:09 +0200 Subject: [PATCH] Fonts: MacOS: Return styles in the order reported by the system This is more likely to place the regular/default style first in the list of styles. This change partially reverts a behavioural change in 68d0ea9dfb4b04e45413b2e11ecce6e54ca5ce10. --- .../juce_graphics/native/juce_Fonts_mac.mm | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/modules/juce_graphics/native/juce_Fonts_mac.mm b/modules/juce_graphics/native/juce_Fonts_mac.mm index 15e06729be..83cdda94d7 100644 --- a/modules/juce_graphics/native/juce_Fonts_mac.mm +++ b/modules/juce_graphics/native/juce_Fonts_mac.mm @@ -406,13 +406,17 @@ StringArray Font::findAllTypefaceStyles (const String& family) if (FontStyleHelpers::isPlaceholderFamilyName (family)) return findAllTypefaceStyles (FontStyleHelpers::getConcreteFamilyNameFromPlaceholder (family)); - std::set results; + std::set uniqueResults; + StringArray orderedResults; for (const auto& font : CoreTextTypeface::findRegisteredStylesForFamily (family)) { const CFUniquePtr descriptor (CTFontCopyFontDescriptor (font.get())); const CFUniquePtr cfsFontStyle ((CFStringRef) CTFontDescriptorCopyAttribute (descriptor.get(), kCTFontStyleNameAttribute)); - results.insert (String::fromCFString (cfsFontStyle.get())); + const auto name = String::fromCFString (cfsFontStyle.get()); + + if (uniqueResults.insert (name).second) + orderedResults.add (name); } CFUniquePtr cfsFontFamily (family.toCFString()); @@ -433,16 +437,14 @@ StringArray Font::findAllTypefaceStyles (const String& family) { auto ctFontDescriptorRef = (CTFontDescriptorRef) CFArrayGetValueAtIndex (fontDescriptorArray.get(), i); CFUniquePtr cfsFontStyle ((CFStringRef) CTFontDescriptorCopyAttribute (ctFontDescriptorRef, kCTFontStyleNameAttribute)); - results.insert (String::fromCFString (cfsFontStyle.get())); + const auto name = String::fromCFString (cfsFontStyle.get()); + + if (uniqueResults.insert (name).second) + orderedResults.add (name); } } - StringArray stringArray; - - for (const auto& result : results) - stringArray.add (result); - - return stringArray; + return orderedResults; } struct DefaultFontNames