diff --git a/runtime/doc/gui.txt b/runtime/doc/gui.txt index 14e0ae8f00..0596eeb1fa 100644 --- a/runtime/doc/gui.txt +++ b/runtime/doc/gui.txt @@ -1135,10 +1135,18 @@ That's all. XLFDs are not used. For Chinese this is reported to work well: > MacVim *macvim-guifont* -For MacVim you can use something like this: > - :set guifont=Menlo:h10 -Fonts with spaces are set like this: > +In MacVim, you can specify fonts by either the full PostScript name or the +family name (both can be found in the Font Book app), followed by an optional +font size (which defaults to `h11`). Font names can also be completed in the +cmdline using |complete-set-option|. + +Basic example of setting the font to Menlo with default size: > + :set guifont=Menlo +To set a font by its family name which contains spaces: > :set guifont=DejaVu\ Sans\ Mono:h13 +When specifying family names with spaces, you can also use underscores +instead: > + :set guifont=DejaVu_Sans_Mono:h13 To use bold/italic fonts, use the fully specified PostScript name of the font, like so: > :set guifont=Menlo-Bold:h13 diff --git a/src/MacVim/gui_macvim.m b/src/MacVim/gui_macvim.m index 8ca89a23c8..de46c923c9 100644 --- a/src/MacVim/gui_macvim.m +++ b/src/MacVim/gui_macvim.m @@ -1196,12 +1196,6 @@ parseFailed = YES; } - if (!parseFailed) { - // Replace underscores with spaces. - fontName = [[fontName componentsSeparatedByString:@"_"] - componentsJoinedByString:@" "]; - } - const BOOL isSystemFont = [fontName hasPrefix:MMSystemFontAlias]; if (isSystemFont) { if (fontName.length > MMSystemFontAlias.length) { @@ -1228,6 +1222,16 @@ || isSystemFont || [NSFont fontWithName:fontName size:size]) return [[NSString alloc] initWithFormat:@"%@:h%d", fontName, size]; + + // If font loading failed, try to replace underscores with spaces for + // user convenience. This really only works if the name is a family + // name because PostScript names should not have spaces. + if ([fontName rangeOfString:@"_"].location != NSNotFound) { + fontName = [fontName stringByReplacingOccurrencesOfString:@"_" withString:@" "]; + if ([NSFont fontWithName:fontName size:size]) { + return [[NSString alloc] initWithFormat:@"%@:h%d", fontName, size]; + } + } } return NOFONT;