diff --git a/modules/juce_graphics/fonts/juce_Typeface.h b/modules/juce_graphics/fonts/juce_Typeface.h index e433a6046d01..f1019a38d037 100644 --- a/modules/juce_graphics/fonts/juce_Typeface.h +++ b/modules/juce_graphics/fonts/juce_Typeface.h @@ -133,7 +133,7 @@ class JUCE_API Typeface : public ReferenceCountedObject static void clearTypefaceCache(); /** On some platforms, this allows a specific path to be scanned. - Currently only available when using FreeType. + On macOS you can load .ttf and .otf files, otherwise this is only available when using FreeType. */ static void scanFolderForFonts (const File& folder); diff --git a/modules/juce_graphics/native/juce_mac_Fonts.mm b/modules/juce_graphics/native/juce_mac_Fonts.mm index 39fdc4ec343d..aa5cc8e78ccc 100644 --- a/modules/juce_graphics/native/juce_mac_Fonts.mm +++ b/modules/juce_graphics/native/juce_mac_Fonts.mm @@ -692,7 +692,8 @@ static void pathApplier (void* info, const CGPathElement* element) if (fontRef != nullptr) { #if JUCE_MAC && defined (MAC_OS_X_VERSION_10_8) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_8 - CTFontManagerUnregisterGraphicsFont (fontRef, nullptr); + if (dataCopy.getSize() != 0) + CTFontManagerUnregisterGraphicsFont (fontRef, nullptr); #endif CGFontRelease (fontRef); @@ -797,9 +798,16 @@ CTFontRef getCTFontFromTypeface (const Font& f) Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font) { return *new OSXTypeface (font); } Typeface::Ptr Typeface::createSystemTypefaceFor (const void* data, size_t size) { return *new OSXTypeface (data, size); } -void Typeface::scanFolderForFonts (const File&) +void Typeface::scanFolderForFonts (const File& folder) { - jassertfalse; // not implemented on this platform + for (auto& file : folder.findChildFiles (File::findFiles, false, "*.otf;*.ttf")) + { + if (auto urlref = CFURLCreateWithFileSystemPath (kCFAllocatorDefault, file.getFullPathName().toCFString(), kCFURLPOSIXPathStyle, true)) + { + CTFontManagerRegisterFontsForURL (urlref, kCTFontManagerScopeProcess, nullptr); + CFRelease (urlref); + } + } } struct DefaultFontNames