Skip to content

Commit 2822896

Browse files
committed
Merge branch 'master' of git://github.com/b4winckler/macvim
Conflicts: src/auto/configure src/eval.c src/feature.h src/misc1.c src/normal.c
2 parents 0c9abb7 + 027c687 commit 2822896

File tree

11 files changed

+75
-35
lines changed

11 files changed

+75
-35
lines changed

src/MacVim/MMBackend.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2100,6 +2100,8 @@ - (void)handleInputEvent:(int)msgid data:(NSData *)data
21002100
[self setImState:YES];
21012101
} else if (DeactivatedImMsgID == msgid) {
21022102
[self setImState:NO];
2103+
} else if (BackingPropertiesChangedMsgID == msgid) {
2104+
[self redrawScreen];
21032105
} else {
21042106
ASLogWarn(@"Unknown message received (msgid=%d)", msgid);
21052107
}

src/MacVim/MMCoreTextView.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
unsigned maxlen;
3939
CGGlyph *glyphs;
4040
CGSize *advances;
41+
NSMutableArray *fontCache;
4142

4243
// These are used in MMCoreTextView+ToolTip.m
4344
id trackingRectOwner_; // (not retained)

src/MacVim/MMCoreTextView.m

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ - (id)initWithFrame:(NSRect)frame
125125
antialias = YES;
126126

127127
drawData = [[NSMutableArray alloc] init];
128+
fontCache = [[NSMutableArray alloc] init];
128129

129130
helper = [[MMTextViewHelper alloc] init];
130131
[helper setTextView:self];
@@ -142,6 +143,7 @@ - (void)dealloc
142143
[defaultBackgroundColor release]; defaultBackgroundColor = nil;
143144
[defaultForegroundColor release]; defaultForegroundColor = nil;
144145
[drawData release]; drawData = nil;
146+
[fontCache release]; fontCache = nil;
145147

146148
[helper setTextView:nil];
147149
[helper release]; helper = nil;
@@ -291,6 +293,8 @@ - (void)setFont:(NSFont *)newFont
291293
cellSize.height = linespace + defaultLineHeightForFont(font);
292294

293295
fontDescent = ceil(CTFontGetDescent(fontRef));
296+
297+
[fontCache removeAllObjects];
294298
}
295299

296300
- (void)setWideFont:(NSFont *)newFont
@@ -986,15 +990,42 @@ - (void)batchDrawData:(NSData *)data
986990
#endif
987991
}
988992

993+
static CTFontRef
994+
lookupFont(NSMutableArray *fontCache, const unichar *chars,
995+
CTFontRef currFontRef)
996+
{
997+
// See if font in cache can draw at least one character
998+
NSUInteger i;
999+
for (i = 0; i < [fontCache count]; ++i) {
1000+
NSFont *font = [fontCache objectAtIndex:i];
1001+
CGGlyph glyphs[1];
1002+
1003+
if (CTFontGetGlyphsForCharacters((CTFontRef)font, chars, glyphs, 1))
1004+
return (CTFontRef)[font retain];
1005+
}
1006+
1007+
// Ask Core Text for a font (can be *very* slow, which is why we cache
1008+
// fonts in the first place)
1009+
CFRange r = { 0, 1 };
1010+
CFStringRef strRef = CFStringCreateWithCharacters(NULL, chars, 1);
1011+
CTFontRef newFontRef = CTFontCreateForString(currFontRef, strRef, r);
1012+
CFRelease(strRef);
1013+
1014+
if (newFontRef)
1015+
[fontCache addObject:(NSFont *)newFontRef];
1016+
1017+
return newFontRef;
1018+
}
1019+
9891020
static void
9901021
recurseDraw(const unichar *chars, CGGlyph *glyphs, CGSize *advances,
9911022
UniCharCount length, CGContextRef context, CTFontRef fontRef,
992-
float x, float y)
1023+
float x, float y, NSMutableArray *fontCache)
9931024
{
994-
CGFontRef cgFontRef = CTFontCopyGraphicsFont(fontRef, NULL);
9951025

9961026
if (CTFontGetGlyphsForCharacters(fontRef, chars, glyphs, length)) {
9971027
// All chars were mapped to glyphs, so draw all at once and return.
1028+
CGFontRef cgFontRef = CTFontCopyGraphicsFont(fontRef, NULL);
9981029
CGContextSetFont(context, cgFontRef);
9991030
CGContextSetTextPosition(context, x, y);
10001031
CGContextShowGlyphsWithAdvances(context, glyphs, advances, length);
@@ -1019,9 +1050,11 @@ - (void)batchDrawData:(NSData *)data
10191050
}
10201051

10211052
int count = g-glyphs;
1053+
CGFontRef cgFontRef = CTFontCopyGraphicsFont(fontRef, NULL);
10221054
CGContextSetFont(context, cgFontRef);
10231055
CGContextSetTextPosition(context, x0, y);
10241056
CGContextShowGlyphsWithAdvances(context, glyphs, advances, count);
1057+
CGFontRelease(cgFontRef);
10251058
} else {
10261059
// Skip past as many consecutive chars as possible which cannot be
10271060
// drawn in the current font.
@@ -1034,18 +1067,12 @@ - (void)batchDrawData:(NSData *)data
10341067

10351068
// Figure out which font to draw these chars with.
10361069
UniCharCount count = c - chars;
1037-
CFRange r = { 0, count };
1038-
CFStringRef strRef = CFStringCreateWithCharactersNoCopy(
1039-
NULL, chars, count, kCFAllocatorNull);
1040-
CTFontRef newFontRef = CTFontCreateForString(fontRef, strRef, r);
1041-
CFRelease(strRef);
1042-
if (!newFontRef) {
1043-
CGFontRelease(cgFontRef);
1070+
CTFontRef newFontRef = lookupFont(fontCache, chars, fontRef);
1071+
if (!newFontRef)
10441072
return;
1045-
}
10461073

10471074
recurseDraw(chars, glyphs, advances, count, context, newFontRef,
1048-
x0, y);
1075+
x0, y, fontCache);
10491076

10501077
CFRelease(newFontRef);
10511078
}
@@ -1055,8 +1082,6 @@ - (void)batchDrawData:(NSData *)data
10551082
advances = a;
10561083
x0 = x;
10571084
}
1058-
1059-
CGFontRelease(cgFontRef);
10601085
}
10611086

10621087
- (void)drawString:(const UniChar *)chars length:(UniCharCount)length
@@ -1167,7 +1192,7 @@ - (void)drawString:(const UniChar *)chars length:(UniCharCount)length
11671192
}
11681193

11691194
recurseDraw(chars, glyphs, advances, length, context, fontRef, x,
1170-
y+fontDescent);
1195+
y+fontDescent, fontCache);
11711196

11721197
CFRelease(fontRef);
11731198
CGContextRestoreGState(context);
@@ -1251,7 +1276,6 @@ - (void)drawInsertionPointAtRow:(int)row column:(int)col shape:(int)shape
12511276
{
12521277
CGContextRef context = [[NSGraphicsContext currentContext] graphicsPort];
12531278
NSRect rect = [self rectForRow:row column:col numRows:1 numColumns:1];
1254-
CGRect clipRect = *(CGRect *)&rect;
12551279

12561280
CGContextSaveGState(context);
12571281

@@ -1272,18 +1296,16 @@ - (void)drawInsertionPointAtRow:(int)row column:(int)col shape:(int)shape
12721296
// over into adjacent display cells and it may look ugly.
12731297
CGContextSetShouldAntialias(context, NO);
12741298

1275-
// Even though antialiasing is disabled and we adjust the rect to fit
1276-
// inside the display cell it still happens on Retina displays (only) that
1277-
// the cursor bleeds over into the neighboring cells. To work around this
1278-
// issue we enable clipping.
1279-
CGContextClipToRect(context, clipRect);
1280-
12811299
if (MMInsertionPointHollow == shape) {
12821300
// When stroking a rect its size is effectively 1 pixel wider/higher
12831301
// than we want so make it smaller to avoid having it bleed over into
12841302
// the adjacent display cell.
1303+
// We also have to shift the rect by half a point otherwise it will be
1304+
// partially drawn outside its bounds on a Retina display.
12851305
rect.size.width -= 1;
12861306
rect.size.height -= 1;
1307+
rect.origin.x += 0.5;
1308+
rect.origin.y += 0.5;
12871309

12881310
CGContextSetRGBStrokeColor(context, RED(color), GREEN(color),
12891311
BLUE(color), ALPHA(color));

src/MacVim/MMWindowController.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,11 @@ - (void)windowDidResize:(id)sender
10021002
[vimView setFrameSize:[self contentSize]];
10031003
}
10041004

1005+
- (void)windowDidChangeBackingProperties:(NSNotification *)notification
1006+
{
1007+
[vimController sendMessage:BackingPropertiesChangedMsgID data:nil];
1008+
}
1009+
10051010
// This is not an NSWindow delegate method, our custom MMWindow class calls it
10061011
// instead of the usual windowWillUseStandardFrame:defaultFrame:.
10071012
- (IBAction)zoom:(id)sender

src/MacVim/MacVim.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ enum {
194194
SetTooltipDelayMsgID,
195195
GestureMsgID,
196196
AddToMRUMsgID,
197+
BackingPropertiesChangedMsgID,
197198
LastMsgID // NOTE: MUST BE LAST MESSAGE IN ENUM!
198199
};
199200

src/MacVim/MacVim.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
"SetTooltipDelayMsgID",
102102
"GestureMsgID",
103103
"AddToMRUMsgID",
104+
"BackingPropertiesChangedMsgID",
104105
"END OF MESSAGE IDs" // NOTE: Must be last!
105106
};
106107

src/MacVim/gui_macvim.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -961,12 +961,12 @@
961961
#if defined(FEAT_EVAL) || defined(PROTO)
962962
/*
963963
* Return the name of font "font" in allocated memory.
964-
* TODO: use 'font' instead of 'name'?
965964
*/
966965
char_u *
967966
gui_mch_get_fontname(GuiFont font, char_u *name)
968967
{
969-
return name ? vim_strsave(name) : NULL;
968+
return font ? [(NSString *)font vimStringSave]
969+
: (name ? vim_strsave(name) : NULL);
970970
}
971971
#endif
972972

src/eval.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11349,7 +11349,14 @@ f_getchar(argvars, rettv)
1134911349
rettv->vval.v_string = vim_strsave(temp);
1135011350

1135111351
#ifdef FEAT_MOUSE
11352-
if (is_mouse_key(n))
11352+
if (is_mouse_key(n)
11353+
# ifdef FEAT_GUI_MACVIM
11354+
|| n == K_SWIPELEFT
11355+
|| n == K_SWIPERIGHT
11356+
|| n == K_SWIPEUP
11357+
|| n == K_SWIPEDOWN
11358+
# endif
11359+
)
1135311360
{
1135411361
int row = mouse_row;
1135511362
int col = mouse_col;

src/feature.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@
639639
* Multibyte support doesn't work on z/OS Unix currently.
640640
*/
641641
#if (defined(FEAT_NORMAL) || defined(FEAT_GUI_GTK) || defined(FEAT_ARABIC) \
642-
|| defined(FEAT_GUI_MACVIM)) \
642+
|| defined(FEAT_GUI_MACVIM)) \
643643
&& !defined(FEAT_MBYTE) && !defined(WIN16) \
644644
&& SIZEOF_INT >= 4 && !defined(EBCDIC)
645645
# define FEAT_MBYTE

src/misc1.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3319,15 +3319,7 @@ is_mouse_key(c)
33193319
|| c == K_X1RELEASE
33203320
|| c == K_X2MOUSE
33213321
|| c == K_X2DRAG
3322-
|| c == K_X2RELEASE
3323-
# ifdef FEAT_GUI_MACVIM
3324-
|| n == K_SWIPELEFT
3325-
|| n == K_SWIPERIGHT
3326-
|| n == K_SWIPEUP
3327-
|| n == K_SWIPEDOWN
3328-
# endif
3329-
;
3330-
3322+
|| c == K_X2RELEASE;
33313323
}
33323324
#endif
33333325

@@ -3422,7 +3414,13 @@ get_keystroke()
34223414
#ifdef FEAT_GUI
34233415
|| n == K_VER_SCROLLBAR
34243416
|| n == K_HOR_SCROLLBAR
3425-
#endif
3417+
# endif
3418+
# ifdef FEAT_GUI_MACVIM
3419+
|| n == K_SWIPELEFT
3420+
|| n == K_SWIPERIGHT
3421+
|| n == K_SWIPEUP
3422+
|| n == K_SWIPEDOWN
3423+
# endif
34263424
)
34273425
{
34283426
if (buf[1] == KS_MODIFIER)

0 commit comments

Comments
 (0)