Skip to content

Commit 4f38f21

Browse files
committed
Merge branch 'master' of git://github.com/b4winckler/macvim
Conflicts: src/MacVim/Info.plist src/MacVim/MMCoreTextView.h src/MacVim/MMCoreTextView.m src/MacVim/gui_macvim.m src/auto/configure src/os_mac.h
2 parents fbb5da9 + 5428a4b commit 4f38f21

File tree

7 files changed

+49
-63
lines changed

7 files changed

+49
-63
lines changed

src/MacVim/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1232,7 +1232,7 @@
12321232
</dict>
12331233
</array>
12341234
<key>CFBundleVersion</key>
1235-
<string>20131023</string>
1235+
<string>20131125</string>
12361236
<key>NSMainNibFile</key>
12371237
<string>MainMenu</string>
12381238
<key>NSPrincipalClass</key>

src/MacVim/MMCoreTextView.m

Lines changed: 24 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ - (void)dealloc
149149
[helper release]; helper = nil;
150150

151151
if (glyphs) { free(glyphs); glyphs = NULL; }
152-
if (advances) { free(advances); advances = NULL; }
153152
if (positions) { free(positions); positions = NULL; }
154153

155154
[super dealloc];
@@ -1054,47 +1053,29 @@ - (void)batchDrawData:(NSData *)data
10541053
}
10551054

10561055
static void
1057-
drawGlyphs(CTFontRef fontRef, const CGGlyph glyphs[], const CGSize advances[],
1058-
CGPoint positions[], size_t count, CGContextRef context)
1059-
{
1060-
CGAffineTransform matrix =
1061-
CGAffineTransformInvert(CGContextGetTextMatrix(context));
1062-
positions[0] = CGPointZero;
1063-
NSUInteger i;
1064-
for (i = 1; i < count; ++i) {
1065-
CGSize advance = CGSizeApplyAffineTransform(advances[i - 1], matrix);
1066-
positions[i].x = positions[i - 1].x + advance.width;
1067-
positions[i].y = positions[i - 1].y + advance.height;
1068-
}
1069-
CTFontDrawGlyphs(fontRef, glyphs, positions, count, context);
1070-
}
1071-
1072-
static void
1073-
recurseDraw(const unichar *chars, CGGlyph *glyphs, CGSize *advances,
1074-
CGPoint *positions, UniCharCount length, CGContextRef context,
1075-
CTFontRef fontRef, float x, float y, NSMutableArray *fontCache,
1076-
BOOL emojiEnabled)
1056+
recurseDraw(const unichar *chars, CGGlyph *glyphs, CGPoint *positions,
1057+
UniCharCount length, CGContextRef context, CTFontRef fontRef,
1058+
NSMutableArray *fontCache, BOOL emojiEnabled)
10771059
{
10781060

10791061
if (CTFontGetGlyphsForCharacters(fontRef, chars, glyphs, length)) {
10801062
// All chars were mapped to glyphs, so draw all at once and return.
10811063
CGContextSetTextPosition(context, x, y);
10821064
if (emojiEnabled) {
10831065
length = gatherGlyphs(glyphs, length);
1084-
drawGlyphs(fontRef, glyphs, advances, positions, length, context);
1066+
CTFontDrawGlyphs(fontRef, glyphs, positions, length, context);
10851067
} else {
10861068
CGFontRef cgFontRef = CTFontCopyGraphicsFont(fontRef, NULL);
10871069
CGContextSetFont(context, cgFontRef);
1088-
CGContextShowGlyphsWithAdvances(context, glyphs, advances, length);
1070+
CGContextShowGlyphsAtPositions(context, glyphs, positions, length);
10891071
CGFontRelease(cgFontRef);
10901072
}
10911073
return;
10921074
}
10931075

10941076
CGGlyph *glyphsEnd = glyphs+length, *g = glyphs;
1095-
CGSize *a = advances;
1077+
CGPoint *p = positions;
10961078
const unichar *c = chars;
1097-
float x0 = x;
10981079
while (glyphs < glyphsEnd) {
10991080
if (*g) {
11001081
// Draw as many consecutive glyphs as possible in the current font
@@ -1106,26 +1087,25 @@ - (void)batchDrawData:(NSData *)data
11061087
surrogatePair = YES;
11071088
g += 2;
11081089
c += 2;
1090+
p += 2;
11091091
} else {
11101092
++g;
11111093
++c;
1094+
++p;
11121095
}
1113-
x += a->width;
1114-
++a;
11151096
}
11161097

11171098
int count = g-glyphs;
11181099
CGContextSetTextPosition(context, x0, y);
11191100
if (emojiEnabled) {
11201101
if (surrogatePair)
11211102
count = gatherGlyphs(glyphs, count);
1122-
drawGlyphs(fontRef,
1123-
glyphs, advances, positions, count, context);
1103+
CTFontDrawGlyphs(fontRef, glyphs, positions, count, context);
11241104
} else {
11251105
CGFontRef cgFontRef = CTFontCopyGraphicsFont(fontRef, NULL);
11261106
CGContextSetFont(context, cgFontRef);
1127-
CGContextShowGlyphsWithAdvances(
1128-
context, glyphs, advances, count);
1107+
CGContextShowGlyphsAtPositions(context, glyphs, positions,
1108+
count);
11291109
CGFontRelease(cgFontRef);
11301110
}
11311111
} else {
@@ -1135,12 +1115,12 @@ - (void)batchDrawData:(NSData *)data
11351115
if (emojiEnabled && CFStringIsSurrogateHighCharacter(*c)) {
11361116
g += 2;
11371117
c += 2;
1118+
p += 2;
11381119
} else {
11391120
++g;
11401121
++c;
1122+
++p;
11411123
}
1142-
x += a->width;
1143-
++a;
11441124
}
11451125

11461126
// Figure out which font to draw these chars with.
@@ -1149,16 +1129,15 @@ - (void)batchDrawData:(NSData *)data
11491129
if (!newFontRef)
11501130
return;
11511131

1152-
recurseDraw(chars, glyphs, advances, positions, count, context,
1153-
newFontRef, x0, y, fontCache, emojiEnabled);
1132+
recurseDraw(chars, glyphs, positions, count, context, newFontRef,
1133+
fontCache, emojiEnabled);
11541134

11551135
CFRelease(newFontRef);
11561136
}
11571137

11581138
chars = c;
11591139
glyphs = g;
1160-
advances = a;
1161-
x0 = x;
1140+
positions = p;
11621141
}
11631142
}
11641143

@@ -1237,10 +1216,8 @@ - (void)drawString:(const UniChar *)chars length:(UniCharCount)length
12371216

12381217
if (length > maxlen) {
12391218
if (glyphs) free(glyphs);
1240-
if (advances) free(advances);
12411219
if (positions) free(positions);
12421220
glyphs = (CGGlyph*)malloc(length*sizeof(CGGlyph));
1243-
advances = (CGSize*)calloc(length, sizeof(CGSize));
12441221
positions = (CGPoint*)calloc(length, sizeof(CGPoint));
12451222
maxlen = length;
12461223
}
@@ -1250,9 +1227,13 @@ - (void)drawString:(const UniChar *)chars length:(UniCharCount)length
12501227
CGContextSetRGBFillColor(context, RED(fg), GREEN(fg), BLUE(fg), ALPHA(fg));
12511228
CGContextSetFontSize(context, [font pointSize]);
12521229

1230+
// Calculate position of each glyph relative to (x,y).
12531231
NSUInteger i;
1254-
for (i = 0; i < length; ++i)
1255-
advances[i].width = w;
1232+
float xrel = 0;
1233+
for (i = 0; i < length; ++i) {
1234+
positions[i].x = xrel;
1235+
xrel += w;
1236+
}
12561237

12571238
CTFontRef fontRef = (CTFontRef)(flags & DRAW_WIDE ? [fontWide retain]
12581239
: [font retain]);
@@ -1271,7 +1252,8 @@ - (void)drawString:(const UniChar *)chars length:(UniCharCount)length
12711252
}
12721253
}
12731254

1274-
recurseDraw(chars, glyphs, advances, positions, length, context, fontRef, x,
1255+
CGContextSetTextPosition(context, x, y+fontDescent);
1256+
recurseDraw(chars, glyphs, positions, length, context, fontRef, fontCache,
12751257
y+fontDescent, fontCache, (flags & DRAW_WIDE) && emojiEnabled);
12761258

12771259
CFRelease(fontRef);

src/MacVim/MacVim.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@
736736
buildSettings = {
737737
ARCHS = "$(NATIVE_ARCH_ACTUAL)";
738738
COPY_PHASE_STRIP = NO;
739-
CURRENT_PROJECT_VERSION = 71;
739+
CURRENT_PROJECT_VERSION = 72;
740740
FRAMEWORK_SEARCH_PATHS = (
741741
"$(inherited)",
742742
"$(FRAMEWORK_SEARCH_PATHS_QUOTED_FOR_TARGET_1)",
@@ -769,7 +769,7 @@
769769
buildSettings = {
770770
ARCHS = "$(NATIVE_ARCH_ACTUAL)";
771771
COPY_PHASE_STRIP = YES;
772-
CURRENT_PROJECT_VERSION = 71;
772+
CURRENT_PROJECT_VERSION = 72;
773773
FRAMEWORK_SEARCH_PATHS = (
774774
"$(inherited)",
775775
"$(FRAMEWORK_SEARCH_PATHS_QUOTED_FOR_TARGET_1)",

src/MacVim/gui_macvim.m

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1825,12 +1825,21 @@ void gui_macvim_get_window_layout(int *count, int *layout)
18251825
}
18261826
}
18271827

1828+
void *gui_macvim_new_autoreleasepool()
1829+
{
1830+
return (void *)[[NSAutoreleasePool alloc] init];
1831+
}
1832+
1833+
void gui_macvim_release_autoreleasepool(void *pool)
1834+
{
1835+
[(id)pool release];
1836+
}
1837+
18281838
void gui_macvim_set_proportional_font(int proportional_font)
18291839
{
18301840
[[MMBackend sharedInstance] setProportionalFont:proportional_font];
18311841
}
18321842

1833-
18341843
// -- Client/Server ---------------------------------------------------------
18351844

18361845
#ifdef MAC_CLIENTSERVER

src/main.c

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@
2323
# include <limits.h>
2424
#endif
2525

26-
#ifdef FEAT_GUI_MACVIM
27-
#include <objc/objc-runtime.h> /* for objc_*() and sel_*() */
28-
#endif
29-
3026
/* Maximum number of commands from + or -c arguments. */
3127
#define MAX_ARG_CMDS 10
3228

@@ -180,9 +176,7 @@ main
180176
// Cocoa needs an NSAutoreleasePool in place or it will leak memory.
181177
// This particular pool will hold autorelease objects created during
182178
// initialization.
183-
id autoreleasePool = objc_msgSend(objc_msgSend(
184-
objc_getClass("NSAutoreleasePool"),sel_getUid("alloc")
185-
), sel_getUid("init"));
179+
void *autoreleasePool = gui_macvim_new_autoreleasepool();
186180
#endif
187181

188182
/*
@@ -1066,13 +1060,11 @@ vim_main2(int argc UNUSED, char **argv UNUSED)
10661060
#ifdef FEAT_GUI_MACVIM
10671061
// The autorelease pool might have filled up quite a bit during
10681062
// initialization, so purge it before entering the main loop.
1069-
objc_msgSend(autoreleasePool, sel_getUid("release"));
1063+
gui_macvim_release_autoreleasepool(autoreleasePool);
10701064

10711065
// The main loop sets up its own autorelease pool, but to be safe we still
10721066
// realloc this one here.
1073-
autoreleasePool = objc_msgSend(objc_msgSend(
1074-
objc_getClass("NSAutoreleasePool"),sel_getUid("alloc")
1075-
), sel_getUid("init"));
1067+
autoreleasePool = gui_macvim_new_autoreleasepool();
10761068
#endif
10771069

10781070
/*
@@ -1081,7 +1073,7 @@ vim_main2(int argc UNUSED, char **argv UNUSED)
10811073
main_loop(FALSE, FALSE);
10821074

10831075
#ifdef FEAT_GUI_MACVIM
1084-
objc_msgSend(autoreleasePool, sel_getUid("release"));
1076+
gui_macvim_release_autoreleasepool(autoreleasePool);
10851077
#endif
10861078

10871079
return 0;
@@ -1152,9 +1144,7 @@ main_loop(cmdwin, noexmode)
11521144
#ifdef FEAT_GUI_MACVIM
11531145
// Cocoa needs an NSAutoreleasePool in place or it will leak memory.
11541146
// This particular pool gets released once every loop.
1155-
id autoreleasePool = objc_msgSend(objc_msgSend(
1156-
objc_getClass("NSAutoreleasePool"),sel_getUid("alloc")
1157-
), sel_getUid("init"));
1147+
void *autoreleasePool = gui_macvim_new_autoreleasepool();
11581148
#endif
11591149

11601150
if (stuff_empty())
@@ -1404,7 +1394,7 @@ main_loop(cmdwin, noexmode)
14041394
#ifdef FEAT_GUI_MACVIM
14051395
// TODO! Make sure there are no continue statements that will cause
14061396
// this not to be called or MacVim will leak memory!
1407-
objc_msgSend(autoreleasePool, sel_getUid("release"));
1397+
gui_macvim_release_autoreleasepool(autoreleasePool);
14081398
#endif
14091399
}
14101400
}

src/os_unix.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,9 @@ int mch_rename __ARGS((const char *src, const char *dest));
563563
# endif
564564
#endif
565565

566-
#define HAVE_DUP /* have dup() */
566+
#ifndef HAVE_DUP
567+
# define HAVE_DUP /* have dup() */
568+
#endif
567569
#define HAVE_ST_MODE /* have stat.st_mode */
568570

569571
/* We have three kinds of ACL support. */

src/proto/gui_macvim.pro

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,3 +247,6 @@ gui_mch_register_sign(char_u *signfile);
247247

248248
void
249249
gui_mch_destroy_sign(void *sign);
250+
251+
void *gui_macvim_new_autoreleasepool();
252+
void gui_macvim_release_autoreleasepool(void *pool);

0 commit comments

Comments
 (0)