diff --git a/src/MacVim/MMAppController.m b/src/MacVim/MMAppController.m index a8b1e27350..2f53a88416 100644 --- a/src/MacVim/MMAppController.m +++ b/src/MacVim/MMAppController.m @@ -128,6 +128,7 @@ static int executeInLoginShell(NSString *path, NSArray *args); - (void)startWatchingVimDir; - (void)stopWatchingVimDir; - (void)handleFSEvent; +- (void)loadDefaultFont; #ifdef MM_ENABLE_PLUGINS - (void)removePlugInMenu; @@ -207,7 +208,7 @@ fsEventCallback(ConstFSEventStreamRef streamRef, { if (!(self = [super init])) return nil; - fontContainerRef = loadFonts(); + [self loadDefaultFont]; vimControllers = [NSMutableArray new]; cachedVimControllers = [NSMutableArray new]; @@ -1878,6 +1879,49 @@ fsEventCallback(ConstFSEventStreamRef streamRef, [self scheduleVimControllerPreloadAfterDelay:0.5]; } +- (void)loadDefaultFont +{ + if (fontContainerRef) + return; + + // Load all fonts in the Resouces folder of the app bundle. + NSString *fontsFolder = [[NSBundle mainBundle] resourcePath]; + if (fontsFolder) { + NSURL *fontsURL = [NSURL fileURLWithPath:fontsFolder]; + if (fontsURL) { + FSRef fsRef; + CFURLGetFSRef((CFURLRef)fontsURL, &fsRef); + +#if (MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_4) + // This is the font activation API for OS X 10.5. Only compile + // this code if we're building on OS X 10.5 or later. + if (NULL != ATSFontActivateFromFileReference) { // Weakly linked + ATSFontActivateFromFileReference(&fsRef, kATSFontContextLocal, + kATSFontFormatUnspecified, + NULL, kATSOptionFlagsDefault, + &fontContainerRef); + } +#endif +#if (MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4) + // The following font activation API was deprecated in OS X 10.5. + // Don't compile this code unless we're targeting OS X 10.4. + FSSpec fsSpec; + if (fontContainerRef == 0 && + FSGetCatalogInfo(&fsRef, kFSCatInfoNone, NULL, NULL, + &fsSpec, NULL) == noErr) { + ATSFontActivateFromFileSpecification(&fsSpec, + kATSFontContextLocal, kATSFontFormatUnspecified, NULL, + kATSOptionFlagsDefault, &fontContainerRef); + } +#endif + } + } + + if (!fontContainerRef) + NSLog(@"WARNING: Failed to activate the default font (the app bundle " + "may be incomplete)"); +} + @end // MMAppController (Private) diff --git a/src/MacVim/MacVim.h b/src/MacVim/MacVim.h index 7a41542d5f..88e5e3c0a5 100644 --- a/src/MacVim/MacVim.h +++ b/src/MacVim/MacVim.h @@ -225,11 +225,6 @@ extern NSString *VimPBoardType; -// Loads all fonts in the Resouces folder of the app bundle and returns a font -// container reference (which should be used to deactivate the loaded fonts). -ATSFontContainerRef loadFonts(); - - @interface NSString (MMExtras) - (NSString *)stringByEscapingSpecialFilenameCharacters; diff --git a/src/MacVim/MacVim.m b/src/MacVim/MacVim.m index 51ac78b473..dd6d21ea5a 100644 --- a/src/MacVim/MacVim.m +++ b/src/MacVim/MacVim.m @@ -100,39 +100,6 @@ NSString *VimPBoardType = @"VimPBoardType"; - ATSFontContainerRef -loadFonts() -{ - // This loads all fonts from the Resources folder. The fonts are only - // available to the process which loaded them, so loading has to be done - // once for MacVim and an additional time for each Vim process. The - // returned container ref should be used to deactiave the font. - // - // (Code taken from cocoadev.com) - ATSFontContainerRef fontContainerRef = 0; - NSString *fontsFolder = [[NSBundle mainBundle] resourcePath]; - if (fontsFolder) { - NSURL *fontsURL = [NSURL fileURLWithPath:fontsFolder]; - if (fontsURL) { - FSRef fsRef; - FSSpec fsSpec; - CFURLGetFSRef((CFURLRef)fontsURL, &fsRef); - - if (FSGetCatalogInfo(&fsRef, kFSCatInfoNone, NULL, NULL, &fsSpec, - NULL) == noErr) { - ATSFontActivateFromFileSpecification(&fsSpec, - kATSFontContextLocal, kATSFontFormatUnspecified, NULL, - kATSOptionFlagsDefault, &fontContainerRef); - } - } - } - - return fontContainerRef; -} - - - - @implementation NSString (MMExtras) - (NSString *)stringByEscapingSpecialFilenameCharacters