1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-09 23:34:20 +00:00

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
68d0ea9dfb.
This commit is contained in:
attila 2024-10-10 15:35:09 +02:00
parent 97cd4fc162
commit 83dc660a30

View file

@ -406,13 +406,17 @@ StringArray Font::findAllTypefaceStyles (const String& family)
if (FontStyleHelpers::isPlaceholderFamilyName (family))
return findAllTypefaceStyles (FontStyleHelpers::getConcreteFamilyNameFromPlaceholder (family));
std::set<String> results;
std::set<String> uniqueResults;
StringArray orderedResults;
for (const auto& font : CoreTextTypeface::findRegisteredStylesForFamily (family))
{
const CFUniquePtr<CTFontDescriptorRef> descriptor (CTFontCopyFontDescriptor (font.get()));
const CFUniquePtr<CFStringRef> 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<CFStringRef> cfsFontFamily (family.toCFString());
@ -433,16 +437,14 @@ StringArray Font::findAllTypefaceStyles (const String& family)
{
auto ctFontDescriptorRef = (CTFontDescriptorRef) CFArrayGetValueAtIndex (fontDescriptorArray.get(), i);
CFUniquePtr<CFStringRef> 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