Skip to content

Commit

Permalink
Support 'antialias' with ATSUI renderer
Browse files Browse the repository at this point in the history
This commit adds support for the 'antialias' option with the ATSUI
renderer (the NSTextView renderer still uses System Preferences).  The
docs on 'antialias' have been updated.

Some changes to the code used by Carbon Vim is affected by this commit.
A feature flag FEAT_ANTIALIAS was added to support easy disabling of
'antialias' support.

(Patch by Jjgod Jiang with some modifications by Bjorn Winckler.)
  • Loading branch information
jjgod authored and b4winckler committed Mar 16, 2008
1 parent 26349fc commit 4868c3c
Show file tree
Hide file tree
Showing 16 changed files with 110 additions and 16 deletions.
3 changes: 2 additions & 1 deletion 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
Expand Down Expand Up @@ -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]
Expand Down
24 changes: 15 additions & 9 deletions runtime/doc/options.txt
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions src/MacVim/MMAtsuiTextView.h
Expand Up @@ -30,6 +30,7 @@ enum { MMMaxCellsPerChar = 2 };
NSImage *contentImage;
NSSize imageSize;
ATSUStyle atsuStyles[MMMaxCellsPerChar];
BOOL antialias;
}

- (id)initWithFrame:(NSRect)frame;
Expand Down Expand Up @@ -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
Expand Down
36 changes: 36 additions & 0 deletions src/MacVim/MMAtsuiTextView.m
Expand Up @@ -108,6 +108,10 @@ - (id)initWithFrame:(NSRect)frame
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];
}

Expand Down Expand Up @@ -258,6 +262,15 @@ - (void)hideMarkedTextField
{
}

- (void)setMouseShape:(int)shape
{
}

- (void)setAntialias:(BOOL)state
{
antialias = state;
}




Expand Down Expand Up @@ -918,6 +931,9 @@ - (void)endDrawing
[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
Expand All @@ -929,6 +945,26 @@ - (void)drawString:(UniChar *)string length:(UniCharCount)length
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);
Expand Down
2 changes: 2 additions & 0 deletions src/MacVim/MMBackend.h
Expand Up @@ -115,6 +115,8 @@
- (void)enterFullscreen;
- (void)leaveFullscreen;

- (void)setAntialias:(BOOL)antialias;

- (void)updateModifiedFlag;

- (void)registerServerWithName:(NSString *)name;
Expand Down
7 changes: 7 additions & 0 deletions src/MacVim/MMBackend.m
Expand Up @@ -1065,6 +1065,13 @@ - (void)leaveFullscreen
[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
Expand Down
1 change: 1 addition & 0 deletions src/MacVim/MMTextView.h
Expand Up @@ -41,6 +41,7 @@
- (void)hideMarkedTextField;
- (void)performBatchDrawWithData:(NSData *)data;
- (void)setMouseShape:(int)shape;
- (void)setAntialias:(BOOL)antialias;

//
// MMTextStorage methods
Expand Down
6 changes: 6 additions & 0 deletions src/MacVim/MMTextView.m
Expand Up @@ -334,6 +334,12 @@ - (void)setMouseShape:(int)shape
[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];
Expand Down
4 changes: 4 additions & 0 deletions src/MacVim/MMVimController.m
Expand Up @@ -889,6 +889,10 @@ - (void)handleMessage:(int)msgid data:(NSData *)data
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);
}
Expand Down
2 changes: 2 additions & 0 deletions src/MacVim/MacVim.h
Expand Up @@ -160,6 +160,8 @@ enum {
ODBEditMsgID,
XcodeModMsgID,
LiveResizeMsgID,
EnableAntialiasMsgID,
DisableAntialiasMsgID,
};


Expand Down
2 changes: 2 additions & 0 deletions src/MacVim/MacVim.m
Expand Up @@ -73,6 +73,8 @@
"ODBEditMsgID",
"XcodeModMsgID",
"LiveResizeMsgID",
"EnableAntialiasMsgID",
"DisableAntialiasMsgID",
};


Expand Down
7 changes: 7 additions & 0 deletions src/MacVim/gui_macvim.m
Expand Up @@ -1542,6 +1542,13 @@
[pb setString:s forType:NSStringPboardType];
}

void
gui_macvim_set_antialias(int antialias)
{
[[MMBackend sharedInstance] setAntialias:antialias];
}





Expand Down
7 changes: 7 additions & 0 deletions src/feature.h
Expand Up @@ -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
17 changes: 13 additions & 4 deletions src/option.c
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/option.h
Expand Up @@ -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' */
Expand Down
1 change: 1 addition & 0 deletions src/proto/gui_macvim.pro
Expand Up @@ -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);
Expand Down

0 comments on commit 4868c3c

Please sign in to comment.