Mercurial > dwindows
comparison mac/dw.m @ 2262:fe64be23680e
Mac: Switch to using NSFontManager fontWithFamily instead of NSFont fontWithName
fontWithName: required the PostScript font name which could be the same as
the family name, but often had no spaces, or extra text associated.
Since we need to use the shared font manager, pull it out of the font chooser.
Also "New Times Roman" worked on most platforms but required "Times New Roman"
on Mac, so hopefully this will work on other platforms too.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Wed, 27 Jan 2021 19:07:25 +0000 |
parents | 7cd64f66f1cc |
children | 176470d75695 |
comparison
equal
deleted
inserted
replaced
2261:281e2df2c022 | 2262:fe64be23680e |
---|---|
838 @implementation DWTimerHandler | 838 @implementation DWTimerHandler |
839 -(void)runTimer:(id)sender { _event_handler(sender, nil, 0); } | 839 -(void)runTimer:(id)sender { _event_handler(sender, nil, 0); } |
840 @end | 840 @end |
841 | 841 |
842 NSApplication *DWApp = nil; | 842 NSApplication *DWApp = nil; |
843 NSFontManager *DWFontManager = nil; | |
843 NSMenu *DWMainMenu; | 844 NSMenu *DWMainMenu; |
844 NSFont *DWDefaultFont; | 845 NSFont *DWDefaultFont; |
845 DWTimerHandler *DWHandler; | 846 DWTimerHandler *DWHandler; |
846 #if !defined(GARBAGE_COLLECT) | 847 #if !defined(GARBAGE_COLLECT) |
847 NSAutoreleasePool *pool; | 848 NSAutoreleasePool *pool; |
2063 | 2064 |
2064 /* Subclass for a font chooser type */ | 2065 /* Subclass for a font chooser type */ |
2065 @interface DWFontChoose : NSFontPanel | 2066 @interface DWFontChoose : NSFontPanel |
2066 { | 2067 { |
2067 DWDialog *dialog; | 2068 DWDialog *dialog; |
2068 NSFontManager *fontManager; | |
2069 } | 2069 } |
2070 -(void)setDialog:(DWDialog *)input; | 2070 -(void)setDialog:(DWDialog *)input; |
2071 -(void)setFontManager:(NSFontManager *)input; | |
2072 -(DWDialog *)dialog; | 2071 -(DWDialog *)dialog; |
2073 @end | 2072 @end |
2074 | 2073 |
2075 @implementation DWFontChoose | 2074 @implementation DWFontChoose |
2076 -(BOOL)windowShouldClose:(id)window | 2075 -(BOOL)windowShouldClose:(id)window |
2077 { | 2076 { |
2078 DWDialog *d = dialog; dialog = nil; | 2077 DWDialog *d = dialog; dialog = nil; |
2079 NSFont *pickedfont = [fontManager selectedFont]; | 2078 NSFont *pickedfont = [DWFontManager selectedFont]; |
2080 dw_dialog_dismiss(d, pickedfont); | 2079 dw_dialog_dismiss(d, pickedfont); |
2081 [window orderOut:nil]; | 2080 [window orderOut:nil]; |
2082 return NO; | 2081 return NO; |
2083 } | 2082 } |
2084 -(void)setDialog:(DWDialog *)input { dialog = input; } | 2083 -(void)setDialog:(DWDialog *)input { dialog = input; } |
2085 -(void)setFontManager:(NSFontManager *)input { fontManager = input; } | |
2086 -(DWDialog *)dialog { return dialog; } | 2084 -(DWDialog *)dialog { return dialog; } |
2087 @end | 2085 @end |
2088 | 2086 |
2089 /* Subclass for a splitbar type */ | 2087 /* Subclass for a splitbar type */ |
2090 @interface DWSplitBar : NSSplitView | 2088 @interface DWSplitBar : NSSplitView |
8703 char *name = strchr(fontname, '.'); | 8701 char *name = strchr(fontname, '.'); |
8704 | 8702 |
8705 if(name && (name++)) | 8703 if(name && (name++)) |
8706 { | 8704 { |
8707 int size = atoi(fontname); | 8705 int size = atoi(fontname); |
8706 char *Italic = strstr(name, " Italic"); | |
8707 char *Bold = strstr(name, " Bold"); | |
8708 size_t len = (Italic ? (Bold ? (Italic > Bold ? (Bold - name) : (Italic - name)) : (Italic - name)) : (Bold ? (Bold - name) : strlen(name))); | |
8709 char *newname = alloca(len+1); | |
8710 | |
8711 memset(newname, 0, len+1); | |
8712 strncpy(newname, name, len); | |
8708 | 8713 |
8709 font = [NSFont fontWithName:[ NSString stringWithUTF8String:name ] size:(float)size]; | 8714 font = [DWFontManager fontWithFamily:[NSString stringWithUTF8String:newname] |
8715 traits:(Italic ? NSItalicFontMask : 0)|(Bold ? NSBoldFontMask : 0) | |
8716 weight:5 | |
8717 size:(float)size]; | |
8710 } | 8718 } |
8711 } | 8719 } |
8712 return font; | 8720 return font; |
8713 } | 8721 } |
8714 | 8722 |
10210 */ | 10218 */ |
10211 char * API dw_font_choose(const char *currfont) | 10219 char * API dw_font_choose(const char *currfont) |
10212 { | 10220 { |
10213 /* Create the Color Chooser Dialog class. */ | 10221 /* Create the Color Chooser Dialog class. */ |
10214 static DWFontChoose *fontDlg = nil; | 10222 static DWFontChoose *fontDlg = nil; |
10215 static NSFontManager *fontManager = nil; | |
10216 DWDialog *dialog; | 10223 DWDialog *dialog; |
10217 NSFont *font = nil; | 10224 NSFont *font = nil; |
10218 | 10225 |
10219 if(currfont) | 10226 if(currfont) |
10220 font = _dw_font_by_name(currfont); | 10227 font = _dw_font_by_name(currfont); |
10229 } | 10236 } |
10230 } | 10237 } |
10231 else | 10238 else |
10232 { | 10239 { |
10233 [NSFontManager setFontPanelFactory:[DWFontChoose class]]; | 10240 [NSFontManager setFontPanelFactory:[DWFontChoose class]]; |
10234 fontManager = [NSFontManager sharedFontManager]; | 10241 fontDlg = (DWFontChoose *)[DWFontManager fontPanel:YES]; |
10235 fontDlg = (DWFontChoose *)[fontManager fontPanel:YES]; | |
10236 } | 10242 } |
10237 | 10243 |
10238 dialog = dw_dialog_new(fontDlg); | 10244 dialog = dw_dialog_new(fontDlg); |
10239 if(font) | 10245 if(font) |
10240 [fontManager setSelectedFont:font isMultiple:NO]; | 10246 [DWFontManager setSelectedFont:font isMultiple:NO]; |
10241 else | 10247 else |
10242 [fontManager setSelectedFont:[NSFont fontWithName:@"Helvetica" size:9.0] isMultiple:NO]; | 10248 [DWFontManager setSelectedFont:[NSFont fontWithName:@"Helvetica" size:9.0] isMultiple:NO]; |
10243 [fontDlg setDialog:dialog]; | 10249 [fontDlg setDialog:dialog]; |
10244 [fontDlg setFontManager:fontManager]; | 10250 [DWFontManager orderFrontFontPanel:DWFontManager]; |
10245 [fontManager orderFrontFontPanel:fontManager]; | |
10246 | 10251 |
10247 | 10252 |
10248 /* Wait for them to pick a color */ | 10253 /* Wait for them to pick a color */ |
10249 font = (NSFont *)dw_dialog_wait(dialog); | 10254 font = (NSFont *)dw_dialog_wait(dialog); |
10250 if(font) | 10255 if(font) |
12510 DWMainMenu = _generate_main_menu(); | 12515 DWMainMenu = _generate_main_menu(); |
12511 [DWMainMenu retain]; | 12516 [DWMainMenu retain]; |
12512 [DWApp setMainMenu:DWMainMenu]; | 12517 [DWApp setMainMenu:DWMainMenu]; |
12513 DWObj = [[DWObject alloc] init]; | 12518 DWObj = [[DWObject alloc] init]; |
12514 DWDefaultFont = nil; | 12519 DWDefaultFont = nil; |
12520 DWFontManager = [NSFontManager sharedFontManager]; | |
12515 #ifdef BUILDING_FOR_MOJAVE | 12521 #ifdef BUILDING_FOR_MOJAVE |
12516 if (@available(macOS 10.14, *)) | 12522 if (@available(macOS 10.14, *)) |
12517 { | 12523 { |
12518 if([[NSBundle mainBundle] bundleIdentifier] != nil) | 12524 if([[NSBundle mainBundle] bundleIdentifier] != nil) |
12519 { | 12525 { |