From 90e4752df4fe28378888436e5ab477b22fd2b2e4 Mon Sep 17 00:00:00 2001 From: Bjorn Winckler Date: Sat, 20 Jun 2009 01:58:06 +0200 Subject: [PATCH] Update 'gfw' on Cmd--/Cmd-+ --- src/MacVim/MMAtsuiTextView.m | 19 +------------------ src/MacVim/MMBackend.m | 32 ++++++++++++++++++++++++++++---- src/MacVim/MMTextView.m | 23 +---------------------- src/MacVim/MMTextViewHelper.h | 1 + src/MacVim/MMTextViewHelper.m | 34 ++++++++++++++++++++++++++++++++++ 5 files changed, 65 insertions(+), 44 deletions(-) diff --git a/src/MacVim/MMAtsuiTextView.m b/src/MacVim/MMAtsuiTextView.m index 643badb0bd..269e773d5f 100644 --- a/src/MacVim/MMAtsuiTextView.m +++ b/src/MacVim/MMAtsuiTextView.m @@ -780,24 +780,7 @@ defaultLineHeightForFont(NSFont *font) - (void)changeFont:(id)sender { - NSFont *newFont = [sender convertFont:font]; - - if (newFont) { - NSString *name = [newFont displayName]; - unsigned len = [name lengthOfBytesUsingEncoding:NSUTF8StringEncoding]; - if (len > 0) { - NSMutableData *data = [NSMutableData data]; - float pointSize = [newFont pointSize]; - - [data appendBytes:&pointSize length:sizeof(float)]; - - ++len; // include NUL byte - [data appendBytes:&len length:sizeof(unsigned)]; - [data appendBytes:[name UTF8String] length:len]; - - [[self vimController] sendMessage:SetFontMsgID data:data]; - } - } + [helper changeFont:sender]; } diff --git a/src/MacVim/MMBackend.m b/src/MacVim/MMBackend.m index de19807391..d3b3fea8a0 100644 --- a/src/MacVim/MMBackend.m +++ b/src/MacVim/MMBackend.m @@ -2159,21 +2159,45 @@ extern GuiFont gui_mch_retain_font(GuiFont font); if (!data) return; const void *bytes = [data bytes]; - float pointSize = *((float*)bytes); bytes += sizeof(float); - //unsigned len = *((unsigned*)bytes); bytes += sizeof(unsigned); - bytes += sizeof(unsigned); // len not used + int pointSize = (int)*((float*)bytes); bytes += sizeof(float); + unsigned len = *((unsigned*)bytes); bytes += sizeof(unsigned); NSMutableString *name = [NSMutableString stringWithUTF8String:bytes]; - [name appendString:[NSString stringWithFormat:@":h%d", (int)pointSize]]; + bytes += len; + + [name appendString:[NSString stringWithFormat:@":h%d", pointSize]]; char_u *s = (char_u*)[name UTF8String]; + unsigned wlen = *((unsigned*)bytes); bytes += sizeof(unsigned); + char_u *ws = NULL; + if (wlen > 0) { + NSMutableString *wname = [NSMutableString stringWithUTF8String:bytes]; + bytes += wlen; + + [wname appendString:[NSString stringWithFormat:@":h%d", pointSize]]; + ws = (char_u*)[wname UTF8String]; + } + #ifdef FEAT_MBYTE s = CONVERT_FROM_UTF8(s); + if (ws) { + ws = CONVERT_FROM_UTF8(ws); + } #endif set_option_value((char_u*)"guifont", 0, s, 0); + if (ws && gui.wide_font != NOFONT) { + // NOTE: This message is sent on Cmd-+/Cmd-- and as such should only + // change the wide font if 'gfw' is non-empty (the frontend always has + // some wide font set, even if 'gfw' is empty). + set_option_value((char_u*)"guifontwide", 0, ws, 0); + } + #ifdef FEAT_MBYTE + if (ws) { + CONVERT_FROM_UTF8_FREE(ws); + } CONVERT_FROM_UTF8_FREE(s); #endif diff --git a/src/MacVim/MMTextView.m b/src/MacVim/MMTextView.m index bd1d71dbcf..a2aa406e0d 100644 --- a/src/MacVim/MMTextView.m +++ b/src/MacVim/MMTextView.m @@ -815,28 +815,7 @@ - (void)changeFont:(id)sender { - MMTextStorage *ts = (MMTextStorage*)[self textStorage]; - if (!ts) return; - - NSFont *oldFont = [ts font]; - NSFont *newFont = [sender convertFont:oldFont]; - - if (newFont) { - NSString *name = [newFont displayName]; - unsigned len = [name lengthOfBytesUsingEncoding:NSUTF8StringEncoding]; - if (len > 0) { - NSMutableData *data = [NSMutableData data]; - float pointSize = [newFont pointSize]; - - [data appendBytes:&pointSize length:sizeof(float)]; - - ++len; // include NUL byte - [data appendBytes:&len length:sizeof(unsigned)]; - [data appendBytes:[name UTF8String] length:len]; - - [[self vimController] sendMessage:SetFontMsgID data:data]; - } - } + [helper changeFont:sender]; } - (void)resetCursorRects diff --git a/src/MacVim/MMTextViewHelper.h b/src/MacVim/MMTextViewHelper.h index 6ac1e1cc25..d192acf50b 100644 --- a/src/MacVim/MMTextViewHelper.h +++ b/src/MacVim/MMTextViewHelper.h @@ -65,6 +65,7 @@ enum { - (NSDragOperation)draggingEntered:(id )sender; - (NSDragOperation)draggingUpdated:(id )sender; - (void)setMouseShape:(int)shape; +- (void)changeFont:(id)sender; // Input Manager - (BOOL)hasMarkedText; diff --git a/src/MacVim/MMTextViewHelper.m b/src/MacVim/MMTextViewHelper.m index 596376eef7..347d5e462c 100644 --- a/src/MacVim/MMTextViewHelper.m +++ b/src/MacVim/MMTextViewHelper.m @@ -578,6 +578,40 @@ static float MMDragAreaSize = 73.0f; [self setCursor]; } +- (void)changeFont:(id)sender +{ + NSFont *newFont = [sender convertFont:[textView font]]; + NSFont *newFontWide = [sender convertFont:[textView fontWide]]; + + if (newFont) { + NSString *name = [newFont displayName]; + NSString *wideName = [newFontWide displayName]; + unsigned len = [name lengthOfBytesUsingEncoding:NSUTF8StringEncoding]; + unsigned wideLen = [wideName lengthOfBytesUsingEncoding: + NSUTF8StringEncoding]; + if (len > 0) { + NSMutableData *data = [NSMutableData data]; + float pointSize = [newFont pointSize]; + + [data appendBytes:&pointSize length:sizeof(float)]; + + ++len; // include NUL byte + [data appendBytes:&len length:sizeof(unsigned)]; + [data appendBytes:[name UTF8String] length:len]; + + if (wideLen > 0) { + ++wideLen; // include NUL byte + [data appendBytes:&wideLen length:sizeof(unsigned)]; + [data appendBytes:[wideName UTF8String] length:wideLen]; + } else { + [data appendBytes:&wideLen length:sizeof(unsigned)]; + } + + [[self vimController] sendMessage:SetFontMsgID data:data]; + } + } +} + - (BOOL)hasMarkedText { return markedRange.length > 0 ? YES : NO;