Skip to content

Commit

Permalink
macOS: Fixed an issue unregistering fonts
Browse files Browse the repository at this point in the history
  • Loading branch information
tpoole committed Jul 11, 2019
1 parent 79d3e8b commit 1b40422
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion modules/juce_graphics/fonts/juce_Typeface.h
Expand Up @@ -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);

Expand Down
14 changes: 11 additions & 3 deletions modules/juce_graphics/native/juce_mac_Fonts.mm
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1b40422

Please sign in to comment.