diff --git a/Credits.rtf b/Credits.rtf index 85c3cd2b60..822442526d 100644 --- a/Credits.rtf +++ b/Credits.rtf @@ -24,4 +24,6 @@ Toolbar icons borrowed from the {\field{\*\fldinst{HYPERLINK "http://www.everald \ Vim icons made by {\field{\*\fldinst{HYPERLINK "http://www.cs.princeton.edu/~mtwebb/vim_icon/vim_icons.html"}}{\fldrslt Matthew Webb}}.\ \ -The Bitstream Vera\'aa font is \'a9 2003 Bitstream, Inc.} \ No newline at end of file +DejaVu is the default font in MacVim.\ +\ +The Bitstream Vera\'aa font is \'a9 2003 by Bitstream, Inc. The Arev font is \'a9 2006 by Tavmjong Bah. The DejaVu changes to these fonts are in the public domain.} \ No newline at end of file diff --git a/MMAppController.h b/MMAppController.h index bc1bf6b09e..ee08c1ef67 100644 --- a/MMAppController.h +++ b/MMAppController.h @@ -16,8 +16,9 @@ @interface MMAppController : NSObject { - NSMutableArray *vimControllers; - NSString *openSelectionString; + NSMutableArray *vimControllers; + NSString *openSelectionString; + ATSFontContainerRef fontContainerRef; } - (void)removeVimController:(id)controller; diff --git a/MMAppController.m b/MMAppController.m index cec158df21..ddbca89379 100644 --- a/MMAppController.m +++ b/MMAppController.m @@ -34,7 +34,6 @@ static NSTimeInterval MMTerminateTimeout = 3; @interface MMAppController (Private) - (MMVimController *)keyVimController; - (MMVimController *)topmostVimController; -+ (void)loadFonts; @end @interface NSMenu (MMExtras) @@ -68,13 +67,13 @@ static NSTimeInterval MMTerminateTimeout = 3; NSArray *types = [NSArray arrayWithObject:NSStringPboardType]; [NSApp registerServicesMenuSendTypes:types returnTypes:types]; - - [self loadFonts]; } - (id)init { if ((self = [super init])) { + fontContainerRef = loadFonts(); + vimControllers = [NSMutableArray new]; // NOTE! If the name of the connection changes here it must also be @@ -289,7 +288,13 @@ static NSTimeInterval MMTerminateTimeout = 3; } } - // NOTE! Is this a correct way of releasing the MMAppController? + if (fontContainerRef) { + ATSFontDeactivate(fontContainerRef, NULL, kATSOptionFlagsDefault); + fontContainerRef = 0; + } + + // TODO: Is this a correct way of releasing the MMAppController? + // (It doesn't seem like dealloc is ever called.) [NSApp setDelegate:nil]; [self autorelease]; } @@ -548,28 +553,6 @@ static NSTimeInterval MMTerminateTimeout = 3; return nil; } -+ (void)loadFonts -{ - // This loads all fonts from the Resources folder. - // (Code taken from cocoadev.com) - NSString *fontsFolder; - if (fontsFolder = [[NSBundle mainBundle] resourcePath]) { - NSURL *fontsURL; - if (fontsURL = [NSURL fileURLWithPath:fontsFolder]) { - FSRef fsRef; - FSSpec fsSpec; - CFURLGetFSRef((CFURLRef)fontsURL, &fsRef); - - if (FSGetCatalogInfo(&fsRef, kFSCatInfoNone, NULL, NULL, &fsSpec, - NULL) == noErr) { - ATSFontActivateFromFileSpecification(&fsSpec, - kATSFontContextGlobal, kATSFontFormatUnspecified, NULL, - kATSOptionFlagsDefault, NULL); - } - } - } -} - @end diff --git a/MMBackend.h b/MMBackend.h index cca74e368e..f64753188c 100644 --- a/MMBackend.h +++ b/MMBackend.h @@ -51,6 +51,7 @@ NSMutableDictionary *clientProxyDict; NSMutableDictionary *serverReplyDict; NSString *alternateServerName; + ATSFontContainerRef fontContainerRef; } + (MMBackend *)sharedInstance; diff --git a/MMBackend.m b/MMBackend.m index 40f68a2506..52266644bb 100644 --- a/MMBackend.m +++ b/MMBackend.m @@ -21,9 +21,8 @@ static float MMFlushTimeoutInterval = 0.1f; static unsigned MMServerMax = 1000; //static NSTimeInterval MMEvaluateExpressionTimeout = 3; -// NOTE: The Bitstream Vera font is bundled with the application and loaded -// during initialization of MMAppController. -static NSString *MMDefaultFontName = @"Bitstream Vera Sans Mono"; +// NOTE: The default font is bundled with the application. +static NSString *MMDefaultFontName = @"DejaVu Sans Mono"; static float MMDefaultFontSize = 12.0f; // TODO: Move to separate file. @@ -78,6 +77,8 @@ enum { - (id)init { if ((self = [super init])) { + fontContainerRef = loadFonts(); + queue = [[NSMutableArray alloc] init]; #if MM_USE_INPUT_QUEUE inputQueue = [[NSMutableArray alloc] init]; @@ -413,6 +414,12 @@ enum { //NSLog(@"%@ %s", [self className], _cmd); [[NSNotificationCenter defaultCenter] removeObserver:self]; [connection invalidate]; + + if (fontContainerRef) { + ATSFontDeactivate(fontContainerRef, NULL, kATSOptionFlagsDefault); + fontContainerRef = 0; + } + } - (void)selectTab:(int)index @@ -800,6 +807,15 @@ enum { } NSFont *font = [NSFont fontWithName:fontName size:size]; + + if (!font && MMDefaultFontName == fontName) { + // If for some reason the MacVim default font is not in the app + // bundle, then fall back on the system default font. + size = 0; + font = [NSFont userFixedPitchFontOfSize:size]; + fontName = [font displayName]; + } + if (font) { //NSLog(@"Setting font '%@' of size %.2f", fontName, size); int len = [fontName diff --git a/MacVim.h b/MacVim.h index 08fb9ee1f8..685037973c 100644 --- a/MacVim.h +++ b/MacVim.h @@ -208,4 +208,9 @@ extern NSString *MMOpenFilesInTabsKey; +// 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(); + + // vim: set ft=objc: diff --git a/MacVim.m b/MacVim.m index 4c2d7f4b45..13b2ce7ec9 100644 --- a/MacVim.m +++ b/MacVim.m @@ -81,3 +81,37 @@ NSString *MMBaselineOffsetKey = @"MMBaselineOffset"; NSString *MMTranslateCtrlClickKey = @"MMTranslateCtrlClick"; NSString *MMTopLeftPointKey = @"MMTopLeftPoint"; NSString *MMOpenFilesInTabsKey = @"MMOpenFilesInTabs"; + + + + + 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; +} + diff --git a/MacVim.xcodeproj/project.pbxproj b/MacVim.xcodeproj/project.pbxproj index a7251aebc0..b5527d8b61 100644 --- a/MacVim.xcodeproj/project.pbxproj +++ b/MacVim.xcodeproj/project.pbxproj @@ -15,6 +15,10 @@ 1D1474B00C5678370038FA2B /* MMTextView.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D1474AE0C5678370038FA2B /* MMTextView.m */; }; 1D1474B60C56796D0038FA2B /* MMVimController.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D1474B40C56796D0038FA2B /* MMVimController.m */; }; 1D1474BC0C567A910038FA2B /* MMWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D1474BA0C567A910038FA2B /* MMWindowController.m */; }; + 1D3D19110CA690FF0004A0A5 /* DejaVuSansMono-Bold.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 1D3D190D0CA690FF0004A0A5 /* DejaVuSansMono-Bold.ttf */; }; + 1D3D19120CA690FF0004A0A5 /* DejaVuSansMono-BoldOblique.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 1D3D190E0CA690FF0004A0A5 /* DejaVuSansMono-BoldOblique.ttf */; }; + 1D3D19130CA690FF0004A0A5 /* DejaVuSansMono-Oblique.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 1D3D190F0CA690FF0004A0A5 /* DejaVuSansMono-Oblique.ttf */; }; + 1D3D19140CA690FF0004A0A5 /* DejaVuSansMono.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 1D3D19100CA690FF0004A0A5 /* DejaVuSansMono.ttf */; }; 1D493D580C5247BF00AB718C /* Vim in CopyFiles */ = {isa = PBXBuildFile; fileRef = 1D493D570C5247BF00AB718C /* Vim */; }; 1D493DBA0C52534300AB718C /* PSMTabBarControl.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 1D493DB90C52533B00AB718C /* PSMTabBarControl.framework */; }; 1D71ACB40BC702AB002F2B60 /* doc-bm-c.icns in Resources */ = {isa = PBXBuildFile; fileRef = 1D71ACA90BC702AB002F2B60 /* doc-bm-c.icns */; }; @@ -35,10 +39,6 @@ 1DD704310BA9F9C2008679E9 /* SpecialKeys.plist in Resources */ = {isa = PBXBuildFile; fileRef = 1DD704300BA9F9C2008679E9 /* SpecialKeys.plist */; }; 1DD9F5E50C85D60500E8D5A5 /* SystemColors.plist in Resources */ = {isa = PBXBuildFile; fileRef = 1DD9F5E40C85D60500E8D5A5 /* SystemColors.plist */; }; 1DDBEB6D0C7434150036EEDD /* EmptyWindow.nib in Resources */ = {isa = PBXBuildFile; fileRef = 1DDBEB6B0C7434150036EEDD /* EmptyWindow.nib */; }; - 1DE5F2520CA5B0B8005A40E4 /* VeraMoBd.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 1DE5F24E0CA5B0B8005A40E4 /* VeraMoBd.ttf */; }; - 1DE5F2530CA5B0B8005A40E4 /* VeraMoBI.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 1DE5F24F0CA5B0B8005A40E4 /* VeraMoBI.ttf */; }; - 1DE5F2540CA5B0B8005A40E4 /* VeraMoIt.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 1DE5F2500CA5B0B8005A40E4 /* VeraMoIt.ttf */; }; - 1DE5F2550CA5B0B8005A40E4 /* VeraMono.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 1DE5F2510CA5B0B8005A40E4 /* VeraMono.ttf */; }; 1DE608B40C587FDA0055263D /* runtime in CopyFiles */ = {isa = PBXBuildFile; fileRef = 1DE602470C587FD10055263D /* runtime */; }; 1DE8CC620C5E2AAD003F56E3 /* Actions.plist in Resources */ = {isa = PBXBuildFile; fileRef = 1DE8CC610C5E2AAD003F56E3 /* Actions.plist */; }; 1DED78600C6DE43D0079945F /* vimrc in CopyFiles */ = {isa = PBXBuildFile; fileRef = 1DED785F0C6DE43D0079945F /* vimrc */; }; @@ -141,6 +141,10 @@ 1D1474B40C56796D0038FA2B /* MMVimController.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = MMVimController.m; sourceTree = ""; }; 1D1474B90C567A910038FA2B /* MMWindowController.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = MMWindowController.h; sourceTree = ""; }; 1D1474BA0C567A910038FA2B /* MMWindowController.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = MMWindowController.m; sourceTree = ""; }; + 1D3D190D0CA690FF0004A0A5 /* DejaVuSansMono-Bold.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; name = "DejaVuSansMono-Bold.ttf"; path = "dejavu-ttf-2.20/DejaVuSansMono-Bold.ttf"; sourceTree = ""; }; + 1D3D190E0CA690FF0004A0A5 /* DejaVuSansMono-BoldOblique.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; name = "DejaVuSansMono-BoldOblique.ttf"; path = "dejavu-ttf-2.20/DejaVuSansMono-BoldOblique.ttf"; sourceTree = ""; }; + 1D3D190F0CA690FF0004A0A5 /* DejaVuSansMono-Oblique.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; name = "DejaVuSansMono-Oblique.ttf"; path = "dejavu-ttf-2.20/DejaVuSansMono-Oblique.ttf"; sourceTree = ""; }; + 1D3D19100CA690FF0004A0A5 /* DejaVuSansMono.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; name = DejaVuSansMono.ttf; path = "dejavu-ttf-2.20/DejaVuSansMono.ttf"; sourceTree = ""; }; 1D493D570C5247BF00AB718C /* Vim */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.executable"; name = Vim; path = ../Vim; sourceTree = SOURCE_ROOT; }; 1D493DB30C52533B00AB718C /* PSMTabBarControl.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = PSMTabBarControl.xcodeproj; path = PSMTabBarControl/PSMTabBarControl.xcodeproj; sourceTree = ""; }; 1D71ACA90BC702AB002F2B60 /* doc-bm-c.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = "doc-bm-c.icns"; sourceTree = ""; }; @@ -162,10 +166,6 @@ 1DD704300BA9F9C2008679E9 /* SpecialKeys.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = SpecialKeys.plist; sourceTree = ""; }; 1DD9F5E40C85D60500E8D5A5 /* SystemColors.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = SystemColors.plist; sourceTree = ""; }; 1DDBEB6C0C7434150036EEDD /* English */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = English; path = English.lproj/EmptyWindow.nib; sourceTree = ""; }; - 1DE5F24E0CA5B0B8005A40E4 /* VeraMoBd.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; name = VeraMoBd.ttf; path = "ttf-bitstream-vera-1.10/VeraMoBd.ttf"; sourceTree = ""; }; - 1DE5F24F0CA5B0B8005A40E4 /* VeraMoBI.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; name = VeraMoBI.ttf; path = "ttf-bitstream-vera-1.10/VeraMoBI.ttf"; sourceTree = ""; }; - 1DE5F2500CA5B0B8005A40E4 /* VeraMoIt.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; name = VeraMoIt.ttf; path = "ttf-bitstream-vera-1.10/VeraMoIt.ttf"; sourceTree = ""; }; - 1DE5F2510CA5B0B8005A40E4 /* VeraMono.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; name = VeraMono.ttf; path = "ttf-bitstream-vera-1.10/VeraMono.ttf"; sourceTree = ""; }; 1DE602470C587FD10055263D /* runtime */ = {isa = PBXFileReference; lastKnownFileType = folder; name = runtime; path = ../../runtime; sourceTree = SOURCE_ROOT; }; 1DE8CC610C5E2AAD003F56E3 /* Actions.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = Actions.plist; sourceTree = ""; }; 1DED785F0C6DE43D0079945F /* vimrc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = vimrc; sourceTree = ""; }; @@ -352,10 +352,10 @@ 29B97317FDCFA39411CA2CEA /* Resources */ = { isa = PBXGroup; children = ( - 1DE5F24E0CA5B0B8005A40E4 /* VeraMoBd.ttf */, - 1DE5F24F0CA5B0B8005A40E4 /* VeraMoBI.ttf */, - 1DE5F2500CA5B0B8005A40E4 /* VeraMoIt.ttf */, - 1DE5F2510CA5B0B8005A40E4 /* VeraMono.ttf */, + 1D3D190D0CA690FF0004A0A5 /* DejaVuSansMono-Bold.ttf */, + 1D3D190E0CA690FF0004A0A5 /* DejaVuSansMono-BoldOblique.ttf */, + 1D3D190F0CA690FF0004A0A5 /* DejaVuSansMono-Oblique.ttf */, + 1D3D19100CA690FF0004A0A5 /* DejaVuSansMono.ttf */, 1DD9F5E40C85D60500E8D5A5 /* SystemColors.plist */, 1DE8CC610C5E2AAD003F56E3 /* Actions.plist */, 1DD04DEB0C529C5E006CDC2B /* Credits.rtf */, @@ -483,10 +483,10 @@ 1DE8CC620C5E2AAD003F56E3 /* Actions.plist in Resources */, 1DDBEB6D0C7434150036EEDD /* EmptyWindow.nib in Resources */, 1DD9F5E50C85D60500E8D5A5 /* SystemColors.plist in Resources */, - 1DE5F2520CA5B0B8005A40E4 /* VeraMoBd.ttf in Resources */, - 1DE5F2530CA5B0B8005A40E4 /* VeraMoBI.ttf in Resources */, - 1DE5F2540CA5B0B8005A40E4 /* VeraMoIt.ttf in Resources */, - 1DE5F2550CA5B0B8005A40E4 /* VeraMono.ttf in Resources */, + 1D3D19110CA690FF0004A0A5 /* DejaVuSansMono-Bold.ttf in Resources */, + 1D3D19120CA690FF0004A0A5 /* DejaVuSansMono-BoldOblique.ttf in Resources */, + 1D3D19130CA690FF0004A0A5 /* DejaVuSansMono-Oblique.ttf in Resources */, + 1D3D19140CA690FF0004A0A5 /* DejaVuSansMono.ttf in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/MacVim.xcodeproj/winckler.mode1 b/MacVim.xcodeproj/winckler.mode1 index 5c10634098..772b46f982 100644 --- a/MacVim.xcodeproj/winckler.mode1 +++ b/MacVim.xcodeproj/winckler.mode1 @@ -368,9 +368,9 @@ TableOfContents - 1D50F01D0CA5B246007DB9E5 + 1DD15C5B0CA69E1F00C745CE 1CE0B1FE06471DED0097A5F4 - 1D50F01E0CA5B246007DB9E5 + 1DD15C5C0CA69E1F00C745CE 1CE0B20306471E060097A5F4 1CE0B20506471E060097A5F4 @@ -504,8 +504,8 @@ 5 WindowOrderList - 1C0AD2B3069F1EA900FABCE6 1D16B9EF0BA33E3800A69B33 + 1C0AD2B3069F1EA900FABCE6 /Users/winckler/Projects/vim7/src/MacVim/MacVim.xcodeproj WindowString @@ -547,8 +547,6 @@ 194pt - BecomeActive - ContentConfiguration PBXProjectModuleGUID @@ -588,7 +586,7 @@ TableOfContents 1D16B9EF0BA33E3800A69B33 - 1D50F01F0CA5B246007DB9E5 + 1DD15C5D0CA69E1F00C745CE 1CD0528F0623707200166675 XCMainBuildResultsModuleGUID @@ -960,9 +958,9 @@ TableOfContents 1C0AD2B3069F1EA900FABCE6 - 1D50F0200CA5B246007DB9E5 + 1DD15C570CA69E1700C745CE 1CD0528B0623707200166675 - 1D50F0210CA5B246007DB9E5 + 1DD15C580CA69E1700C745CE ToolbarConfiguration xcode.toolbar.config.run diff --git a/MacVim.xcodeproj/winckler.pbxuser b/MacVim.xcodeproj/winckler.pbxuser index 18d6f6becf..994d686a08 100644 --- a/MacVim.xcodeproj/winckler.pbxuser +++ b/MacVim.xcodeproj/winckler.pbxuser @@ -438,8 +438,8 @@ PBXFileDataSource_Warnings_ColumnID, ); }; - PBXPerProjectTemplateStateSaveDate = 212185620; - PBXWorkspaceStateSaveDate = 212185620; + PBXPerProjectTemplateStateSaveDate = 212246019; + PBXWorkspaceStateSaveDate = 212246019; }; sourceControlManager = 1D16B9DD0BA33BB000A69B33 /* Source Control */; userBuildSettings = {