Cocoa: Pick default fonts directly and not by changing a base value

This commit is contained in:
David Jenkins 2024-11-01 13:36:27 +00:00 committed by rich2014
parent 9af9ef8a87
commit c1d35f1303
2 changed files with 20 additions and 36 deletions

View File

@ -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

View File

@ -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;