From 8c18cf2d276b189319e6c53bc196c96c6561a82e Mon Sep 17 00:00:00 2001 From: Bjorn Winckler Date: Sun, 14 Feb 2010 01:23:59 +0100 Subject: [PATCH] Add wide font support to Core Text renderer --- src/MacVim/MMCoreTextView.h | 1 + src/MacVim/MMCoreTextView.m | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/MacVim/MMCoreTextView.h b/src/MacVim/MMCoreTextView.h index aba94238..338bfcd9 100644 --- a/src/MacVim/MMCoreTextView.h +++ b/src/MacVim/MMCoreTextView.h @@ -23,6 +23,7 @@ NSColor *defaultForegroundColor; NSSize cellSize; NSFont *font; + NSFont *fontWide; float linespace; // From NSTextView diff --git a/src/MacVim/MMCoreTextView.m b/src/MacVim/MMCoreTextView.m index 2c16ae6e..fd50b585 100644 --- a/src/MacVim/MMCoreTextView.m +++ b/src/MacVim/MMCoreTextView.m @@ -159,6 +159,7 @@ defaultAdvanceForFont(CTFontRef fontRef) - (void)dealloc { [font release]; font = nil; + [fontWide release]; fontWide = nil; [defaultBackgroundColor release]; defaultBackgroundColor = nil; [defaultForegroundColor release]; defaultForegroundColor = nil; [drawData release]; drawData = nil; @@ -335,6 +336,16 @@ defaultAdvanceForFont(CTFontRef fontRef) - (void)setWideFont:(NSFont *)newFont { + if (!newFont) { + // Use the normal font as the wide font (note that the normal font may + // very well include wide characters.) + if (font) [self setWideFont:font]; + } else if (newFont != fontWide) { + // NOTE: No need to set point size etc. since this is taken from the + // regular font when drawing. + [fontWide release]; + fontWide = [newFont retain]; + } } - (NSFont *)font @@ -344,7 +355,7 @@ defaultAdvanceForFont(CTFontRef fontRef) - (NSFont *)fontWide { - return nil; + return fontWide; } - (NSSize)cellSize @@ -1156,8 +1167,8 @@ recurseDraw(const unichar *chars, CGGlyph *glyphs, CGSize *advances, for (i = 0; i < length; ++i) advances[i].width = w; - CTFontRef fontRef = (CTFontRef)[font retain]; - + CTFontRef fontRef = (CTFontRef)(flags & DRAW_WIDE ? [fontWide retain] + : [font retain]); unsigned traits = 0; if (flags & DRAW_ITALIC) traits |= kCTFontItalicTrait; -- 2.11.4.GIT