From 207d162fb7ab98367002c44bb38335ad264a29dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rene=CC=81=20Ko=CC=88cher?= Date: Sun, 12 Jul 2015 15:54:05 +0200 Subject: [PATCH] Fix relative positioning once ligatures come into play. --- src/MacVim/MMCoreTextView.m | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/MacVim/MMCoreTextView.m b/src/MacVim/MMCoreTextView.m index 45f5739eb2..bf0245701e 100644 --- a/src/MacVim/MMCoreTextView.m +++ b/src/MacVim/MMCoreTextView.m @@ -1029,7 +1029,7 @@ lookupFont(NSMutableArray *fontCache, const unichar *chars, UniCharCount count, } static void -ligatureGlyphsForChars(const unichar *chars, CGGlyph *glyphs, UniCharCount *length, CTFontRef font ) +ligatureGlyphsForChars(const unichar *chars, CGGlyph *glyphs, CGPoint *positions, UniCharCount *length, CTFontRef font ) { /* CoreText has no simple wait of retrieving a ligature for a set of UniChars. * The way proposed on the CoreText ML is to convert the text to an attributed @@ -1048,6 +1048,8 @@ ligatureGlyphsForChars(const unichar *chars, CGGlyph *glyphs, UniCharCount *leng NSAttributedString *attrText = [[NSAttributedString alloc] initWithString:text attributes:attrs]; + CGPoint refPos = positions[0]; + CTLineRef line = CTLineCreateWithAttributedString((CFAttributedStringRef)attrText); UniCharCount offset = 0; @@ -1065,6 +1067,7 @@ ligatureGlyphsForChars(const unichar *chars, CGGlyph *glyphs, UniCharCount *leng CFRange range = CFRangeMake(0, count); CTRunGetGlyphs(run, range, &glyphs[offset]); + CTRunGetPositions(run, range, &positions[offset]); offset += count; if(offset >= *length) { @@ -1072,6 +1075,11 @@ ligatureGlyphsForChars(const unichar *chars, CGGlyph *glyphs, UniCharCount *leng break; } } + // fixup relative positioning + for( CFIndex i = 0; i < offset; ++i ) { + positions[i].x += refPos.x; + positions[i].y += refPos.y; + } // as ligatures combine characters it is required to adjust the // original length value *length = offset; @@ -1086,7 +1094,7 @@ recurseDraw(const unichar *chars, CGGlyph *glyphs, CGPoint *positions, // All chars were mapped to glyphs, so draw all at once and return. if (useLigatures) { memset(glyphs, 0, sizeof(CGGlyph) * length); - ligatureGlyphsForChars(chars, glyphs, &length, fontRef); + ligatureGlyphsForChars(chars, glyphs, positions, &length, fontRef); } CGFontRef cgFontRef = CTFontCopyGraphicsFont(fontRef, NULL);