Mercurial > dwindows
diff mac/dw.m @ 2252:5dbe950115c1
Mac: Fix crash in dw_window_set_font() with NULL font name.
Not sure if I am getting the default font correctly, may need to revisit.
Also switched Helv to Helvetica so it works on Mac, might need an
#ifdef if this doesn't work on other platforms.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sun, 24 Jan 2021 23:17:02 +0000 |
parents | 3e9c5bff0a57 |
children | 7cd64f66f1cc |
line wrap: on
line diff
--- a/mac/dw.m Sun Jan 24 21:00:15 2021 +0000 +++ b/mac/dw.m Sun Jan 24 23:17:02 2021 +0000 @@ -8691,18 +8691,19 @@ /* Internal function to convert fontname to NSFont */ NSFont *_dw_font_by_name(const char *fontname) { - char *fontcopy = strdup(fontname); - char *name = strchr(fontcopy, '.'); - NSFont *font = nil; - - if(name) - { - int size = atoi(fontcopy); - *name = 0; - name++; - font = [NSFont fontWithName:[ NSString stringWithUTF8String:name ] size:(float)size]; - } - free(fontcopy); + NSFont *font = DWDefaultFont; + + if(fontname) + { + char *name = strchr(fontname, '.'); + + if(name && (name++)) + { + int size = atoi(fontname); + + font = [NSFont fontWithName:[ NSString stringWithUTF8String:name ] size:(float)size]; + } + } return font; } @@ -10293,7 +10294,8 @@ */ int API dw_window_set_font(HWND handle, const char *fontname) { - NSFont *font = _dw_font_by_name(fontname); + NSFont *font = fontname ? _dw_font_by_name(fontname) : + (DWDefaultFont ? DWDefaultFont : [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]); if(font) { @@ -10308,6 +10310,12 @@ { [object setTitleFont:font]; } + else if([object isMemberOfClass:[DWMLE class]]) + { + DWMLE *mle = object; + + [[mle textStorage] setFont:font]; + } else if([object isKindOfClass:[NSControl class]]) { [object setFont:font]; @@ -12396,8 +12404,12 @@ void API dw_font_set_default(const char *fontname) { NSFont *oldfont = DWDefaultFont; - DWDefaultFont = _dw_font_by_name(fontname); - [DWDefaultFont retain]; + DWDefaultFont = nil; + if(fontname) + { + DWDefaultFont = _dw_font_by_name(fontname); + [DWDefaultFont retain]; + } [oldfont release]; }