diff --git a/lcl/interfaces/cocoa/cocoagdiobjects.pas b/lcl/interfaces/cocoa/cocoagdiobjects.pas index c9eec9c539..6e062ca24f 100644 --- a/lcl/interfaces/cocoa/cocoagdiobjects.pas +++ b/lcl/interfaces/cocoa/cocoagdiobjects.pas @@ -642,20 +642,17 @@ begin // we could use NSFontTraitsAttribute to request the desired font style (Bold/Italic) // but in this case we may get NIL as result. This way is safer. if cfs_Italic in Style then - FFont := NSFontManager.sharedFontManager.convertFont_toHaveTrait(FFont, NSItalicFontMask) - else - FFont := NSFontManager.sharedFontManager.convertFont_toNotHaveTrait(FFont, NSItalicFontMask); - if cfs_Bold in Style then - FFont := NSFontManager.sharedFontManager.convertFont_toHaveTrait(FFont, NSBoldFontMask) - else - FFont := NSFontManager.sharedFontManager.convertFont_toNotHaveTrait(FFont, NSBoldFontMask); - case ALogFont.lfPitchAndFamily and $F of - FIXED_PITCH, MONO_FONT: - FFont := NSFontManager.sharedFontManager.convertFont_toHaveTrait(FFont, NSFixedPitchFontMask); - VARIABLE_PITCH: - FFont := NSFontManager.sharedFontManager.convertFont_toNotHaveTrait(FFont, NSFixedPitchFontMask); + FFont := NSFontManager.sharedFontManager.convertFont_toHaveTrait(FFont, NSItalicFontMask); + if not IsDefault then + begin + if cfs_Bold in Style then + FFont := NSFontManager.sharedFontManager.convertFont_toHaveTrait(FFont, NSBoldFontMask); + case ALogFont.lfPitchAndFamily and $F of + FIXED_PITCH, MONO_FONT: + FFont := NSFontManager.sharedFontManager.convertFont_toHaveTrait(FFont, NSFixedPitchFontMask); + end; end; - if Win32Weight <> FW_DONTCARE then + if (Win32Weight <> FW_DONTCARE) and (not IsDefault or (Win32Weight <> FW_BOLD)) then begin // currently if we request the desired weight by Attributes we may get a nil font // so we need to get font weight and to convert it to lighter/heavier diff --git a/lcl/interfaces/cocoa/cocoawinapi.inc b/lcl/interfaces/cocoa/cocoawinapi.inc index 909b26089f..a853688fae 100644 --- a/lcl/interfaces/cocoa/cocoawinapi.inc +++ b/lcl/interfaces/cocoa/cocoawinapi.inc @@ -1440,37 +1440,24 @@ end; function TCocoaWidgetSet.InitStockFont(AFont: TObject; AStockFont: TStockFont): Boolean; var Font: TFont absolute AFont; - CTFont: CTFontRef; - CTFontName: CFStringRef; - CTFontSize: CGFloat; - CTFontType: CTFontUIFontType; + FontSize: CGFloat; begin Result := False; case AStockFont of sfSystem: // stock system font - CTFontType := kCTFontSystemFontType; + FontSize := NSFont.systemFontSize; sfHint: // stock hint font - CTFontType := kCTFontToolTipFontType; + FontSize := NSFont.toolTipsFontOfSize(0).pointSize; sfIcon: // stock icon font - CTFontType := kCTFontViewsFontType; - sfMenu: // stock menu font - CTFontType := kCTFontMenuItemFontType; + FontSize := NSFont.controlContentFontOfSize(0).pointSize; + sfMenu: // stock menu font + FontSize := NSFont.menuFontOfSize(0).pointSize; + else + Exit; end; - - CTFont := CTFontCreateUIFontForLanguage(CTFontType, 0, nil); - try - CTFontName := CTFontCopyFamilyName(CTFont); - try - Font.Name := CFStringToStr(CTFontName); - finally - CFRelease(CTFontName); - end; - CTFontSize := CTFontGetSize(CTFont); - Font.Height := -Round(CTFontSize); - finally - CFRelease(CTFont); - end; + Font.Name := 'default'; + Font.Height := -Round(FontSize); Result := True; end;