From e226fb8015adf2f34c0be4eec96452760211a125 Mon Sep 17 00:00:00 2001 From: Markus Engelbrecht Date: Tue, 6 Sep 2016 18:01:50 +0200 Subject: [PATCH] Add macthinstrokes option The macthinstrokes option renders the text a little lighter which looks nice when using a dark colorscheme and a retina display. --- runtime/doc/gui_mac.txt | 4 ++-- runtime/doc/options.txt | 12 ++++++++++++ runtime/doc/quickref.txt | 1 + runtime/doc/tags | 2 ++ runtime/optwin.vim | 2 ++ src/MacVim/MMBackend.h | 1 + src/MacVim/MMBackend.m | 7 +++++++ src/MacVim/MMCoreTextView.h | 2 ++ src/MacVim/MMCoreTextView.m | 18 ++++++++++++++++++ src/MacVim/MMTextView.h | 2 ++ src/MacVim/MMTextView.m | 5 +++++ src/MacVim/MMVimController.m | 4 ++++ src/MacVim/MacVim.h | 2 ++ src/MacVim/MacVim.m | 2 ++ src/MacVim/gui_macvim.m | 5 +++++ src/option.c | 9 +++++++++ src/option.h | 1 + src/proto/gui_macvim.pro | 1 + 18 files changed, 78 insertions(+), 2 deletions(-) diff --git a/runtime/doc/gui_mac.txt b/runtime/doc/gui_mac.txt index a8df0c07a2..a5e2cdf4dc 100644 --- a/runtime/doc/gui_mac.txt +++ b/runtime/doc/gui_mac.txt @@ -111,8 +111,8 @@ to your .gvimrc file to revert back to the default Vim tab label. *macvim-options* These are the non-standard options that MacVim supports: 'antialias' 'blurradius' 'fullscreen' - 'fuoptions' 'macligatures' 'macmeta' 'toolbariconsize' - 'transparency' + 'fuoptions' 'macligatures' 'macmeta' 'macthinstrokes' + 'toolbariconsize' 'transparency' *macvim-commands* These are the non-standard commands that MacVim supports: diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt index 6a590bb7e0..6d8b67f389 100644 --- a/runtime/doc/options.txt +++ b/runtime/doc/options.txt @@ -5043,6 +5043,18 @@ A jump table for the options with a short description can be found at |Q_op|. 'guifont' supports them. Examples for such fonts are Fira Code or Haskelig. Note: Currently this option only has an effect if + 'Use Core Text renderer' is enabled in the GUI preferences pane. + + *'macthinstrokes'* *'nomacthinstrokes'* +'macthinstrokes' boolean (default off) + global + {not in Vi} + {only available when compiled with GUI enabled on + Mac OS X} + This option only has an effect in the GUI version of Vim on Mac OS X + v10.8 or later. When on, Vim will render the text a little lighter + which looks nice with a dark colorscheme. + Note: Currently this option only has an effect if 'Use Core Text renderer' is enabled in the GUI preferences pane. *'macmeta'* *'mmta'* *'nomacmeta'* *'nommta'* diff --git a/runtime/doc/quickref.txt b/runtime/doc/quickref.txt index c6149eb5e4..c641652347 100644 --- a/runtime/doc/quickref.txt +++ b/runtime/doc/quickref.txt @@ -785,6 +785,7 @@ Short explanation of each option: *option-list* 'macatsui' Mac GUI: use ATSUI text drawing 'macligatures' display ligatures (MacVim GUI only) 'macmeta' 'mmta' use option as meta key (MacVim GUI only) +'macthinstrokes' render the text lighter by using thin strokes (MacVim GUI only) 'magic' changes special characters in search patterns 'makeef' 'mef' name of the errorfile for ":make" 'makeprg' 'mp' program to use for the ":make" command diff --git a/runtime/doc/tags b/runtime/doc/tags index 65d690b7ff..075fcf26c8 100644 --- a/runtime/doc/tags +++ b/runtime/doc/tags @@ -433,6 +433,7 @@ $VIM_POSIX vi_diff.txt /*$VIM_POSIX* 'macatsui' options.txt /*'macatsui'* 'macligatures' options.txt /*'macligatures'* 'macmeta' options.txt /*'macmeta'* +'macthinstrokes' options.txt /*'macthinstrokes'* 'magic' options.txt /*'magic'* 'makeef' options.txt /*'makeef'* 'makeprg' options.txt /*'makeprg'* @@ -614,6 +615,7 @@ $VIM_POSIX vi_diff.txt /*$VIM_POSIX* 'nomacatsui' options.txt /*'nomacatsui'* 'nomacligatures' options.txt /*'nomacligatures'* 'nomacmeta' options.txt /*'nomacmeta'* +'nomacthinstrokes' options.txt /*'nomacthinstrokes'* 'nomagic' options.txt /*'nomagic'* 'nomh' options.txt /*'nomh'* 'noml' options.txt /*'noml'* diff --git a/runtime/optwin.vim b/runtime/optwin.vim index 130cbbb744..9a7c00bb05 100644 --- a/runtime/optwin.vim +++ b/runtime/optwin.vim @@ -665,6 +665,8 @@ if has("gui") call BinOptionG("macligatures", &macligatures) call append("$", "macmeta\tuse option as meta key") call append("$", "\t(local to buffer)") + call append("$", "macthinstrokes\tuse thin strokes") + call BinOptionG("macthinstrokes", &macthinstrokes) call BinOptionL("mmta") endif endif diff --git a/src/MacVim/MMBackend.h b/src/MacVim/MMBackend.h index 3262c715ee..4d4b41480e 100644 --- a/src/MacVim/MMBackend.h +++ b/src/MacVim/MMBackend.h @@ -135,6 +135,7 @@ extern NSTimeInterval MMBalloonEvalInternalDelay; - (void)setAntialias:(BOOL)antialias; - (void)setLigatures:(BOOL)ligatures; +- (void)setThinStrokes:(BOOL)thinStrokes; - (void)setBlurRadius:(int)radius; - (void)updateModifiedFlag; diff --git a/src/MacVim/MMBackend.m b/src/MacVim/MMBackend.m index 258f467b38..4f98541a8e 100644 --- a/src/MacVim/MMBackend.m +++ b/src/MacVim/MMBackend.m @@ -1183,6 +1183,13 @@ - (void)setLigatures:(BOOL)ligatures [self queueMessage:msgid data:nil]; } +- (void)setThinStrokes:(BOOL)thinStrokes +{ + int msgid = thinStrokes ? EnableThinStrokesMsgID : DisableThinStrokesMsgID; + + [self queueMessage:msgid data:nil]; +} + - (void)setBlurRadius:(int)radius { NSMutableData *data = [NSMutableData data]; diff --git a/src/MacVim/MMCoreTextView.h b/src/MacVim/MMCoreTextView.h index f0ed0c5cb8..f7599d57ad 100644 --- a/src/MacVim/MMCoreTextView.h +++ b/src/MacVim/MMCoreTextView.h @@ -29,6 +29,7 @@ float fontDescent; BOOL antialias; BOOL ligatures; + BOOL thinStrokes; NSMutableArray *drawData; MMTextViewHelper *helper; @@ -77,6 +78,7 @@ - (void)setMouseShape:(int)shape; - (void)setAntialias:(BOOL)state; - (void)setLigatures:(BOOL)state; +- (void)setThinStrokes:(BOOL)state; - (void)setImControl:(BOOL)enable; - (void)activateIm:(BOOL)enable; - (void)checkImState; diff --git a/src/MacVim/MMCoreTextView.m b/src/MacVim/MMCoreTextView.m index a9e8b9ba10..106950299e 100644 --- a/src/MacVim/MMCoreTextView.m +++ b/src/MacVim/MMCoreTextView.m @@ -48,6 +48,10 @@ #define kCTFontOrientationDefault kCTFontDefaultOrientation #endif // MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_8 +extern void CGContextSetFontSmoothingStyle(CGContextRef, int); +extern int CGContextGetFontSmoothingStyle(CGContextRef); +#define fontSmoothingStyleLight (2 << 3) + #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_7 static void CTFontDrawGlyphs(CTFontRef fontRef, const CGGlyph glyphs[], @@ -396,6 +400,11 @@ - (void)setLigatures:(BOOL)state ligatures = state; } +- (void)setThinStrokes:(BOOL)state +{ + thinStrokes = state; +} + - (void)setImControl:(BOOL)enable { [helper setImControl:enable]; @@ -1299,6 +1308,13 @@ - (void)drawString:(const UniChar *)chars length:(UniCharCount)length CGContextSaveGState(context); + int originalFontSmoothingStyle = 0; + if (thinStrokes) { + CGContextSetShouldSmoothFonts(context, YES); + originalFontSmoothingStyle = CGContextGetFontSmoothingStyle(context); + CGContextSetFontSmoothingStyle(context, fontSmoothingStyleLight); + } + // NOTE! 'cells' is zero if we're drawing a composing character CGFloat clipWidth = cells > 0 ? cells*cellSize.width : w; CGRect clipRect = { {x, y}, {clipWidth, cellSize.height} }; @@ -1389,6 +1405,8 @@ - (void)drawString:(const UniChar *)chars length:(UniCharCount)length recurseDraw(chars, glyphs, positions, length, context, fontRef, fontCache, ligatures); CFRelease(fontRef); + if (thinStrokes) + CGContextSetFontSmoothingStyle(context, originalFontSmoothingStyle); CGContextRestoreGState(context); } diff --git a/src/MacVim/MMTextView.h b/src/MacVim/MMTextView.h index 328ed0f23d..0bd9d74d5f 100644 --- a/src/MacVim/MMTextView.h +++ b/src/MacVim/MMTextView.h @@ -21,6 +21,7 @@ int insertionPointFraction; BOOL antialias; BOOL ligatures; + BOOL thinStrokes; NSRect *invertRects; int numInvertRects; @@ -34,6 +35,7 @@ - (void)setMouseShape:(int)shape; - (void)setAntialias:(BOOL)antialias; - (void)setLigatures:(BOOL)ligatures; +- (void)setThinStrokes:(BOOL)thinStrokes; - (void)setImControl:(BOOL)enable; - (void)activateIm:(BOOL)enable; - (void)checkImState; diff --git a/src/MacVim/MMTextView.m b/src/MacVim/MMTextView.m index 61309711d0..e36647d295 100644 --- a/src/MacVim/MMTextView.m +++ b/src/MacVim/MMTextView.m @@ -312,6 +312,11 @@ - (void)setLigatures:(BOOL)state ligatures = state; } +- (void)setThinStrokes:(BOOL)state +{ + thinStrokes = state; +} + - (void)setImControl:(BOOL)enable { [helper setImControl:enable]; diff --git a/src/MacVim/MMVimController.m b/src/MacVim/MMVimController.m index 8ee2626a36..0d5d9b647d 100644 --- a/src/MacVim/MMVimController.m +++ b/src/MacVim/MMVimController.m @@ -806,6 +806,10 @@ - (void)handleMessage:(int)msgid data:(NSData *)data [[[windowController vimView] textView] setLigatures:YES]; } else if (DisableLigaturesMsgID == msgid) { [[[windowController vimView] textView] setLigatures:NO]; + } else if (EnableThinStrokesMsgID == msgid) { + [[[windowController vimView] textView] setThinStrokes:YES]; + } else if (DisableThinStrokesMsgID == msgid) { + [[[windowController vimView] textView] setThinStrokes:NO]; } else if (SetVimStateMsgID == msgid) { NSDictionary *dict = [NSDictionary dictionaryWithData:data]; if (dict) { diff --git a/src/MacVim/MacVim.h b/src/MacVim/MacVim.h index c20c164aa5..570ee79554 100644 --- a/src/MacVim/MacVim.h +++ b/src/MacVim/MacVim.h @@ -203,6 +203,8 @@ enum { SetBlurRadiusMsgID, EnableLigaturesMsgID, DisableLigaturesMsgID, + EnableThinStrokesMsgID, + DisableThinStrokesMsgID, LastMsgID // NOTE: MUST BE LAST MESSAGE IN ENUM! }; diff --git a/src/MacVim/MacVim.m b/src/MacVim/MacVim.m index b86ce869b2..d889a3841c 100644 --- a/src/MacVim/MacVim.m +++ b/src/MacVim/MacVim.m @@ -102,6 +102,8 @@ "SetBlurRadiusMsgID", "EnableLigaturesMsgID", "DisableLigaturesMsgID", + "EnableThinStrokesMsgID", + "DisableThinStrokesMsgID", "END OF MESSAGE IDs" // NOTE: Must be last! }; diff --git a/src/MacVim/gui_macvim.m b/src/MacVim/gui_macvim.m index e0858f780a..60aac68960 100644 --- a/src/MacVim/gui_macvim.m +++ b/src/MacVim/gui_macvim.m @@ -1818,6 +1818,11 @@ { [[MMBackend sharedInstance] setLigatures:ligatures]; } + void +gui_macvim_set_thinstrokes(int thinStrokes) +{ + [[MMBackend sharedInstance] setThinStrokes:thinStrokes]; +} void gui_macvim_wait_for_startup() diff --git a/src/option.c b/src/option.c index be7ace03b6..a9461fbd3d 100644 --- a/src/option.c +++ b/src/option.c @@ -1834,6 +1834,11 @@ static struct vimoption options[] = (char_u *)NULL, PV_NONE, #endif {(char_u *)FALSE, (char_u *)0L}}, +#ifdef FEAT_GUI_MACVIM + {"macthinstrokes", NULL, P_BOOL|P_VI_DEF|P_RCLR, + (char_u *)&p_macthinstrokes, PV_NONE, + {(char_u *)FALSE, (char_u *)0L}}, +#endif {"magic", NULL, P_BOOL|P_VI_DEF, (char_u *)&p_magic, PV_NONE, {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT}, @@ -8238,6 +8243,10 @@ set_bool_option( { gui_macvim_set_ligatures(p_macligatures); } + else if ((int*)varp == &p_macthinstrokes) + { + gui_macvim_set_thinstrokes(p_macthinstrokes); + } #endif /* when 'textauto' is set or reset also change 'fileformats' */ diff --git a/src/option.h b/src/option.h index fb3672b9fb..031f113bc3 100644 --- a/src/option.h +++ b/src/option.h @@ -643,6 +643,7 @@ EXTERN int p_macatsui; /* 'macatsui' */ #endif #ifdef FEAT_GUI_MACVIM EXTERN int p_macligatures; /* 'macligatures' */ +EXTERN int p_macthinstrokes; /* 'macthinstrokes' */ #endif EXTERN int p_magic; /* 'magic' */ #ifdef FEAT_QUICKFIX diff --git a/src/proto/gui_macvim.pro b/src/proto/gui_macvim.pro index 997e3d640c..79d0617577 100644 --- a/src/proto/gui_macvim.pro +++ b/src/proto/gui_macvim.pro @@ -212,6 +212,7 @@ void gui_macvim_update_modified_flag(); void gui_macvim_add_to_find_pboard(char_u *pat); void gui_macvim_set_antialias(int antialias); void gui_macvim_set_ligatures(int ligatures); +void gui_macvim_set_thinstrokes(int thinStrokes); void gui_macvim_set_blur(int blur); int16_t odb_buffer_close(buf_T *buf);