diff --git a/runtime/doc/gui_mac.txt b/runtime/doc/gui_mac.txt index 07b6a83cac..1470703a54 100644 --- a/runtime/doc/gui_mac.txt +++ b/runtime/doc/gui_mac.txt @@ -1,4 +1,4 @@ -*gui_mac.txt* For Vim version 7.1. Last change: 2008 Feb 05 +*gui_mac.txt* For Vim version 7.1. Last change: 2008 Mar 16 VIM REFERENCE MANUAL by Bjorn Winckler @@ -220,6 +220,7 @@ as general information regarding Mac OS X user defaults. Here is a list of relevant dictionary entries: KEY VALUE ~ +MMAtsuiRenderer enable ATSUI renderer [bool] MMCellWidthMultiplier width of a normal glyph in em units [float] MMLoginShellArgument login shell parameter [string] MMLoginShellCommand which shell to use to launch Vim [string] diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt index c1f557a90e..1180be98d5 100644 --- a/runtime/doc/options.txt +++ b/runtime/doc/options.txt @@ -666,17 +666,23 @@ A jump table for the options with a short description can be found at |Q_op|. Standard Annex #11 (http://www.unicode.org/reports/tr11). *'antialias'* *'anti'* *'noantialias'* *'noanti'* -'antialias' 'anti' boolean (default: off) +'antialias' 'anti' boolean (default off, on for MacVim) global {not in Vi} - {only available when compiled with Carbon GUI enabled - on Mac OS X} - This option only has an effect in the Carbon GUI version of Vim on Mac - OS X v10.2 or later. When on, Vim will use smooth ("antialiased") - fonts, which can be easier to read at certain sizes on certain - displays. Setting this option can sometimes cause problems if - 'guifont' is set to its default (empty string). - Note: Antialiasing is handled automatically on MacVim. + {only available when compiled with GUI enabled on + Mac OS X} + This option only has an effect in the Carbon GUI version of Vim on Mac + OS X v10.2 or later, and in MacVim when the ATSUI renderer is used. + When on, Vim will use smooth ("antialiased") fonts, which can be + easier to read at certain sizes on certain displays. + + Setting this option in the Carbon version can sometimes cause problems + if 'guifont' is set to its default (empty string). + + The default renderer in MacVim uses the System Preferences to control + antialiasing of text; this option is ignored. The ATSUI renderer on + the other hand does use this option (and ignores the System + Preferences setting). *'autochdir'* *'acd'* *'noautochdir'* *'noacd'* 'autochdir' 'acd' boolean (default off) diff --git a/src/MacVim/MMAtsuiTextView.h b/src/MacVim/MMAtsuiTextView.h index 320308abe4..97fabcc08e 100644 --- a/src/MacVim/MMAtsuiTextView.h +++ b/src/MacVim/MMAtsuiTextView.h @@ -30,6 +30,7 @@ enum { MMMaxCellsPerChar = 2 }; NSImage *contentImage; NSSize imageSize; ATSUStyle atsuStyles[MMMaxCellsPerChar]; + BOOL antialias; } - (id)initWithFrame:(NSRect)frame; @@ -57,6 +58,8 @@ enum { MMMaxCellsPerChar = 2 }; - (void)setShouldDrawInsertionPoint:(BOOL)on; - (void)setPreEditRow:(int)row column:(int)col; - (void)hideMarkedTextField; +- (void)setMouseShape:(int)shape; +- (void)setAntialias:(BOOL)state; // // NSTextView methods diff --git a/src/MacVim/MMAtsuiTextView.m b/src/MacVim/MMAtsuiTextView.m index e7ccffe780..f703249229 100644 --- a/src/MacVim/MMAtsuiTextView.m +++ b/src/MacVim/MMAtsuiTextView.m @@ -108,6 +108,10 @@ enum { imageSize = NSZeroSize; insetSize = NSZeroSize; + // NOTE: If the default changes to 'NO' then the intialization of + // p_antialias in option.c must change as well. + antialias = YES; + [self initAtsuStyles]; } @@ -258,6 +262,15 @@ enum { { } +- (void)setMouseShape:(int)shape +{ +} + +- (void)setAntialias:(BOOL)state +{ + antialias = state; +} + @@ -918,6 +931,9 @@ enum { [contentImage unlockFocus]; } +#define atsu_style_set_bool(s, t, b) \ + ATSUSetAttributes(s, 1, &t, &(sizeof(Boolean)), &&b); + - (void)drawString:(UniChar *)string length:(UniCharCount)length atRow:(int)row column:(int)col cells:(int)cells withFlags:(int)flags foregroundColor:(NSColor *)fg @@ -929,6 +945,26 @@ enum { ATSUStyle style = (flags & DRAW_WIDE) ? atsuStyles[1] : atsuStyles[0]; ATSUTextLayout layout; + // Font selection and rendering options for ATSUI + ATSUAttributeTag attribTags[3] = { kATSUQDBoldfaceTag, + kATSUQDItalicTag, + kATSUStyleRenderingOptionsTag }; + ByteCount attribSizes[] = { sizeof(Boolean), + sizeof(Boolean), + sizeof(UInt32) }; + Boolean useBold, useItalic; + UInt32 useAntialias; + ATSUAttributeValuePtr attribValues[3] = { &useBold, &useItalic, + &useAntialias }; + + useBold = (flags & DRAW_BOLD) ? true : false; + useItalic = (flags & DRAW_ITALIC) ? true : false; + useAntialias = antialias ? kATSStyleApplyAntiAliasing + : kATSStyleNoAntiAliasing; + + ATSUSetAttributes(style, sizeof(attribValues) / sizeof(attribValues[0]), + attribTags, attribSizes, attribValues); + // NSLog(@"drawString: %d", length); ATSUCreateTextLayout(&layout); diff --git a/src/MacVim/MMBackend.h b/src/MacVim/MMBackend.h index 008a97b860..95a03518fc 100644 --- a/src/MacVim/MMBackend.h +++ b/src/MacVim/MMBackend.h @@ -115,6 +115,8 @@ - (void)enterFullscreen; - (void)leaveFullscreen; +- (void)setAntialias:(BOOL)antialias; + - (void)updateModifiedFlag; - (void)registerServerWithName:(NSString *)name; diff --git a/src/MacVim/MMBackend.m b/src/MacVim/MMBackend.m index 55f09f08fc..afa6d024d1 100644 --- a/src/MacVim/MMBackend.m +++ b/src/MacVim/MMBackend.m @@ -1065,6 +1065,13 @@ static NSString *MMSymlinkWarningString = [self queueMessage:LeaveFullscreenMsgID data:nil]; } +- (void)setAntialias:(BOOL)antialias +{ + int msgid = antialias ? EnableAntialiasMsgID : DisableAntialiasMsgID; + + [self queueMessage:msgid data:nil]; +} + - (void)updateModifiedFlag { // Notify MacVim if _any_ buffer has changed from unmodified to modified or diff --git a/src/MacVim/MMTextView.h b/src/MacVim/MMTextView.h index 6a88b4ee82..928cbeb77f 100644 --- a/src/MacVim/MMTextView.h +++ b/src/MacVim/MMTextView.h @@ -41,6 +41,7 @@ - (void)hideMarkedTextField; - (void)performBatchDrawWithData:(NSData *)data; - (void)setMouseShape:(int)shape; +- (void)setAntialias:(BOOL)antialias; // // MMTextStorage methods diff --git a/src/MacVim/MMTextView.m b/src/MacVim/MMTextView.m index 6059781a71..c42b266673 100644 --- a/src/MacVim/MMTextView.m +++ b/src/MacVim/MMTextView.m @@ -334,6 +334,12 @@ enum { [self setCursor]; } +- (void)setAntialias:(BOOL)antialias +{ + // Antialiasing is handled by the System Preferences and there seems to be + // no way to control antialiasing with NSTextView. +} + - (NSFont *)font { return [(MMTextStorage*)[self textStorage] font]; diff --git a/src/MacVim/MMVimController.m b/src/MacVim/MMVimController.m index 1964cc38c8..7cb2fea462 100644 --- a/src/MacVim/MMVimController.m +++ b/src/MacVim/MMVimController.m @@ -889,6 +889,10 @@ static NSTimeInterval MMResendInterval = 0.5; const int *dim = (const int*)[data bytes]; [[[windowController vimView] textView] setPreEditRow:dim[0] column:dim[1]]; + } else if (EnableAntialiasMsgID == msgid) { + [[[windowController vimView] textView] setAntialias:YES]; + } else if (DisableAntialiasMsgID == msgid) { + [[[windowController vimView] textView] setAntialias:NO]; } else { NSLog(@"WARNING: Unknown message received (msgid=%d)", msgid); } diff --git a/src/MacVim/MacVim.h b/src/MacVim/MacVim.h index 07fb5cc7d2..d85e66b9ff 100644 --- a/src/MacVim/MacVim.h +++ b/src/MacVim/MacVim.h @@ -160,6 +160,8 @@ enum { ODBEditMsgID, XcodeModMsgID, LiveResizeMsgID, + EnableAntialiasMsgID, + DisableAntialiasMsgID, }; diff --git a/src/MacVim/MacVim.m b/src/MacVim/MacVim.m index b63e2b39bb..c7ce9687f9 100644 --- a/src/MacVim/MacVim.m +++ b/src/MacVim/MacVim.m @@ -73,6 +73,8 @@ char *MessageStrings[] = "ODBEditMsgID", "XcodeModMsgID", "LiveResizeMsgID", + "EnableAntialiasMsgID", + "DisableAntialiasMsgID", }; diff --git a/src/MacVim/gui_macvim.m b/src/MacVim/gui_macvim.m index 2e8782684b..c3b61c094e 100644 --- a/src/MacVim/gui_macvim.m +++ b/src/MacVim/gui_macvim.m @@ -1542,6 +1542,13 @@ gui_macvim_add_to_find_pboard(char_u *pat) [pb setString:s forType:NSStringPboardType]; } + void +gui_macvim_set_antialias(int antialias) +{ + [[MMBackend sharedInstance] setAntialias:antialias]; +} + + diff --git a/src/feature.h b/src/feature.h index 6f11753830..14ca568c14 100644 --- a/src/feature.h +++ b/src/feature.h @@ -1296,3 +1296,10 @@ #ifdef FEAT_GUI_MACVIM #define FEAT_GUI_SCROLL_WHEEL_FORCE #endif + +/* + * Support for enabling/disabling antialiased text. + */ +#if defined(FEAT_GUI) && defined(MACOS_X) +#define FEAT_ANTIALIAS +#endif diff --git a/src/option.c b/src/option.c index 173edbbae6..4fb801ac25 100644 --- a/src/option.c +++ b/src/option.c @@ -478,14 +478,16 @@ static struct vimoption #endif (char_u *)0L}}, {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR, -#if defined(FEAT_GUI) && defined(MACOS_X) +#ifdef FEAT_ANTIALIAS (char_u *)&p_antialias, PV_NONE, - {(char_u *)FALSE, (char_u *)FALSE} #else (char_u *)NULL, PV_NONE, - {(char_u *)FALSE, (char_u *)FALSE} #endif - }, +#if FEAT_GUI_MACVIM + {(char_u *)TRUE, (char_u *)0L}}, +#else + {(char_u *)FALSE, (char_u *)0L}}, +#endif {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM, #ifdef FEAT_ARABIC (char_u *)VAR_WIN, PV_ARAB, @@ -7308,6 +7310,13 @@ set_bool_option(opt_idx, varp, value, opt_flags) } #endif +#if defined(FEAT_ANTIALIAS) && defined(FEAT_GUI_MACVIM) + else if ((int *)varp == &p_antialias && gui.in_use) + { + gui_macvim_set_antialias(p_antialias); + } +#endif + /* when 'textauto' is set or reset also change 'fileformats' */ else if ((int *)varp == &p_ta) set_string_option_direct((char_u *)"ffs", -1, diff --git a/src/option.h b/src/option.h index 453ed358ce..948a1c6d8b 100644 --- a/src/option.h +++ b/src/option.h @@ -309,8 +309,8 @@ EXTERN int p_acd; /* 'autochdir' */ #ifdef FEAT_MBYTE EXTERN char_u *p_ambw; /* 'ambiwidth' */ #endif -#if defined(FEAT_GUI) && defined(MACOS_X) -EXTERN int *p_antialias; /* 'antialias' */ +#ifdef FEAT_ANTIALIAS +EXTERN int p_antialias; /* 'antialias' */ #endif EXTERN int p_ar; /* 'autoread' */ EXTERN int p_aw; /* 'autowrite' */ diff --git a/src/proto/gui_macvim.pro b/src/proto/gui_macvim.pro index 12fab1319c..18be4ecc2b 100644 --- a/src/proto/gui_macvim.pro +++ b/src/proto/gui_macvim.pro @@ -195,6 +195,7 @@ void gui_mch_leave_fullscreen(void); void gui_macvim_update_modified_flag(); void gui_macvim_add_to_find_pboard(char_u *pat); +void gui_macvim_set_antialias(int antialias); OSErr odb_buffer_close(buf_T *buf); OSErr odb_post_buffer_write(buf_T *buf);