mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-27 10:20:19 +02:00
Cocoa: Pick default fonts directly and not by changing a base value
This commit is contained in:
parent
9af9ef8a87
commit
c1d35f1303
@ -642,20 +642,17 @@ begin
|
|||||||
// we could use NSFontTraitsAttribute to request the desired font style (Bold/Italic)
|
// 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.
|
// but in this case we may get NIL as result. This way is safer.
|
||||||
if cfs_Italic in Style then
|
if cfs_Italic in Style then
|
||||||
FFont := NSFontManager.sharedFontManager.convertFont_toHaveTrait(FFont, NSItalicFontMask)
|
FFont := NSFontManager.sharedFontManager.convertFont_toHaveTrait(FFont, NSItalicFontMask);
|
||||||
else
|
if not IsDefault then
|
||||||
FFont := NSFontManager.sharedFontManager.convertFont_toNotHaveTrait(FFont, NSItalicFontMask);
|
begin
|
||||||
if cfs_Bold in Style then
|
if cfs_Bold in Style then
|
||||||
FFont := NSFontManager.sharedFontManager.convertFont_toHaveTrait(FFont, NSBoldFontMask)
|
FFont := NSFontManager.sharedFontManager.convertFont_toHaveTrait(FFont, NSBoldFontMask);
|
||||||
else
|
case ALogFont.lfPitchAndFamily and $F of
|
||||||
FFont := NSFontManager.sharedFontManager.convertFont_toNotHaveTrait(FFont, NSBoldFontMask);
|
FIXED_PITCH, MONO_FONT:
|
||||||
case ALogFont.lfPitchAndFamily and $F of
|
FFont := NSFontManager.sharedFontManager.convertFont_toHaveTrait(FFont, NSFixedPitchFontMask);
|
||||||
FIXED_PITCH, MONO_FONT:
|
end;
|
||||||
FFont := NSFontManager.sharedFontManager.convertFont_toHaveTrait(FFont, NSFixedPitchFontMask);
|
|
||||||
VARIABLE_PITCH:
|
|
||||||
FFont := NSFontManager.sharedFontManager.convertFont_toNotHaveTrait(FFont, NSFixedPitchFontMask);
|
|
||||||
end;
|
end;
|
||||||
if Win32Weight <> FW_DONTCARE then
|
if (Win32Weight <> FW_DONTCARE) and (not IsDefault or (Win32Weight <> FW_BOLD)) then
|
||||||
begin
|
begin
|
||||||
// currently if we request the desired weight by Attributes we may get a nil font
|
// 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
|
// so we need to get font weight and to convert it to lighter/heavier
|
||||||
|
@ -1440,37 +1440,24 @@ end;
|
|||||||
function TCocoaWidgetSet.InitStockFont(AFont: TObject; AStockFont: TStockFont): Boolean;
|
function TCocoaWidgetSet.InitStockFont(AFont: TObject; AStockFont: TStockFont): Boolean;
|
||||||
var
|
var
|
||||||
Font: TFont absolute AFont;
|
Font: TFont absolute AFont;
|
||||||
CTFont: CTFontRef;
|
FontSize: CGFloat;
|
||||||
CTFontName: CFStringRef;
|
|
||||||
CTFontSize: CGFloat;
|
|
||||||
CTFontType: CTFontUIFontType;
|
|
||||||
begin
|
begin
|
||||||
Result := False;
|
Result := False;
|
||||||
|
|
||||||
case AStockFont of
|
case AStockFont of
|
||||||
sfSystem: // stock system font
|
sfSystem: // stock system font
|
||||||
CTFontType := kCTFontSystemFontType;
|
FontSize := NSFont.systemFontSize;
|
||||||
sfHint: // stock hint font
|
sfHint: // stock hint font
|
||||||
CTFontType := kCTFontToolTipFontType;
|
FontSize := NSFont.toolTipsFontOfSize(0).pointSize;
|
||||||
sfIcon: // stock icon font
|
sfIcon: // stock icon font
|
||||||
CTFontType := kCTFontViewsFontType;
|
FontSize := NSFont.controlContentFontOfSize(0).pointSize;
|
||||||
sfMenu: // stock menu font
|
sfMenu: // stock menu font
|
||||||
CTFontType := kCTFontMenuItemFontType;
|
FontSize := NSFont.menuFontOfSize(0).pointSize;
|
||||||
|
else
|
||||||
|
Exit;
|
||||||
end;
|
end;
|
||||||
|
Font.Name := 'default';
|
||||||
CTFont := CTFontCreateUIFontForLanguage(CTFontType, 0, nil);
|
Font.Height := -Round(FontSize);
|
||||||
try
|
|
||||||
CTFontName := CTFontCopyFamilyName(CTFont);
|
|
||||||
try
|
|
||||||
Font.Name := CFStringToStr(CTFontName);
|
|
||||||
finally
|
|
||||||
CFRelease(CTFontName);
|
|
||||||
end;
|
|
||||||
CTFontSize := CTFontGetSize(CTFont);
|
|
||||||
Font.Height := -Round(CTFontSize);
|
|
||||||
finally
|
|
||||||
CFRelease(CTFont);
|
|
||||||
end;
|
|
||||||
Result := True;
|
Result := True;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user