Skip to content

Commit 8041d3a

Browse files
committed
Stop using 10.9 deprecated CGContext function
1 parent 18c7318 commit 8041d3a

File tree

2 files changed

+22
-24
lines changed

2 files changed

+22
-24
lines changed

src/MacVim/MMCoreTextView.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
unsigned maxlen;
3939
CGGlyph *glyphs;
40-
CGSize *advances;
40+
CGPoint *positions;
4141
NSMutableArray *fontCache;
4242

4343
// These are used in MMCoreTextView+ToolTip.m

src/MacVim/MMCoreTextView.m

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ - (void)dealloc
148148
[helper release]; helper = nil;
149149

150150
if (glyphs) { free(glyphs); glyphs = NULL; }
151-
if (advances) { free(advances); advances = NULL; }
151+
if (positions) { free(positions); positions = NULL; }
152152

153153
[super dealloc];
154154
}
@@ -1013,25 +1013,23 @@ - (void)batchDrawData:(NSData *)data
10131013
}
10141014

10151015
static void
1016-
recurseDraw(const unichar *chars, CGGlyph *glyphs, CGSize *advances,
1016+
recurseDraw(const unichar *chars, CGGlyph *glyphs, CGPoint *positions,
10171017
UniCharCount length, CGContextRef context, CTFontRef fontRef,
1018-
float x, float y, NSMutableArray *fontCache)
1018+
NSMutableArray *fontCache)
10191019
{
10201020

10211021
if (CTFontGetGlyphsForCharacters(fontRef, chars, glyphs, length)) {
10221022
// All chars were mapped to glyphs, so draw all at once and return.
10231023
CGFontRef cgFontRef = CTFontCopyGraphicsFont(fontRef, NULL);
10241024
CGContextSetFont(context, cgFontRef);
1025-
CGContextSetTextPosition(context, x, y);
1026-
CGContextShowGlyphsWithAdvances(context, glyphs, advances, length);
1025+
CGContextShowGlyphsAtPositions(context, glyphs, positions, length);
10271026
CGFontRelease(cgFontRef);
10281027
return;
10291028
}
10301029

10311030
CGGlyph *glyphsEnd = glyphs+length, *g = glyphs;
1032-
CGSize *a = advances;
1031+
CGPoint *p = positions;
10331032
const unichar *c = chars;
1034-
float x0 = x;
10351033
while (glyphs < glyphsEnd) {
10361034
if (*g) {
10371035
// Draw as many consecutive glyphs as possible in the current font
@@ -1040,24 +1038,21 @@ - (void)batchDrawData:(NSData *)data
10401038
while (*g && g < glyphsEnd) {
10411039
++g;
10421040
++c;
1043-
x += a->width;
1044-
++a;
1041+
++p;
10451042
}
10461043

10471044
int count = g-glyphs;
10481045
CGFontRef cgFontRef = CTFontCopyGraphicsFont(fontRef, NULL);
10491046
CGContextSetFont(context, cgFontRef);
1050-
CGContextSetTextPosition(context, x0, y);
1051-
CGContextShowGlyphsWithAdvances(context, glyphs, advances, count);
1047+
CGContextShowGlyphsAtPositions(context, glyphs, positions, count);
10521048
CGFontRelease(cgFontRef);
10531049
} else {
10541050
// Skip past as many consecutive chars as possible which cannot be
10551051
// drawn in the current font.
10561052
while (0 == *g && g < glyphsEnd) {
10571053
++g;
10581054
++c;
1059-
x += a->width;
1060-
++a;
1055+
++p;
10611056
}
10621057

10631058
// Figure out which font to draw these chars with.
@@ -1066,16 +1061,15 @@ - (void)batchDrawData:(NSData *)data
10661061
if (!newFontRef)
10671062
return;
10681063

1069-
recurseDraw(chars, glyphs, advances, count, context, newFontRef,
1070-
x0, y, fontCache);
1064+
recurseDraw(chars, glyphs, positions, count, context, newFontRef,
1065+
fontCache);
10711066

10721067
CFRelease(newFontRef);
10731068
}
10741069

10751070
chars = c;
10761071
glyphs = g;
1077-
advances = a;
1078-
x0 = x;
1072+
positions = p;
10791073
}
10801074
}
10811075

@@ -1148,9 +1142,9 @@ - (void)drawString:(const UniChar *)chars length:(UniCharCount)length
11481142

11491143
if (length > maxlen) {
11501144
if (glyphs) free(glyphs);
1151-
if (advances) free(advances);
1145+
if (positions) free(positions);
11521146
glyphs = (CGGlyph*)malloc(length*sizeof(CGGlyph));
1153-
advances = (CGSize*)calloc(length, sizeof(CGSize));
1147+
positions = (CGPoint*)calloc(length, sizeof(CGPoint));
11541148
maxlen = length;
11551149
}
11561150

@@ -1159,9 +1153,13 @@ - (void)drawString:(const UniChar *)chars length:(UniCharCount)length
11591153
CGContextSetRGBFillColor(context, RED(fg), GREEN(fg), BLUE(fg), ALPHA(fg));
11601154
CGContextSetFontSize(context, [font pointSize]);
11611155

1156+
// Calculate position of each glyph relative to (x,y).
11621157
NSUInteger i;
1163-
for (i = 0; i < length; ++i)
1164-
advances[i].width = w;
1158+
float xrel = 0;
1159+
for (i = 0; i < length; ++i) {
1160+
positions[i].x = xrel;
1161+
xrel += w;
1162+
}
11651163

11661164
CTFontRef fontRef = (CTFontRef)(flags & DRAW_WIDE ? [fontWide retain]
11671165
: [font retain]);
@@ -1180,8 +1178,8 @@ - (void)drawString:(const UniChar *)chars length:(UniCharCount)length
11801178
}
11811179
}
11821180

1183-
recurseDraw(chars, glyphs, advances, length, context, fontRef, x,
1184-
y+fontDescent, fontCache);
1181+
CGContextSetTextPosition(context, x, y+fontDescent);
1182+
recurseDraw(chars, glyphs, positions, length, context, fontRef, fontCache);
11851183

11861184
CFRelease(fontRef);
11871185
CGContextRestoreGState(context);

0 commit comments

Comments
 (0)