Update 'gfw' on Cmd--/Cmd-+

This commit is contained in:
Bjorn Winckler
2009-06-20 01:58:06 +02:00
parent 0978ebc1c6
commit 90e4752df4
5 changed files with 65 additions and 44 deletions
+1 -18
View File
@@ -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];
}
+28 -4
View File
@@ -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
+1 -22
View File
@@ -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
+1
View File
@@ -65,6 +65,7 @@ enum {
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender;
- (NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)sender;
- (void)setMouseShape:(int)shape;
- (void)changeFont:(id)sender;
// Input Manager
- (BOOL)hasMarkedText;
+34
View File
@@ -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;