Cocoa: Add some fixed pitch font checking for the font selector and gdiobjects

This commit is contained in:
David Jenkins 2024-11-01 14:39:45 +00:00 committed by rich2014
parent 309974b57c
commit 1b4edd6f41
3 changed files with 28 additions and 1 deletions

View File

@ -351,6 +351,18 @@ type
procedure setEnabled_(aenabled: ObjCBool); message 'setEnabled:';
end;
type
NSFontWeight = CGFloat;
const
NSFontWeightRegular = 0.0;
type
NSFontFix = objccategory external (NSFont)
// available in 10.15+
class function monospacedSystemFontOfSize_weight (fontSize: CGFloat; weight: NSFontWeight): NSFont;
message 'monospacedSystemFontOfSize:weight:';
end;
NSApplicationFix = objccategory external (NSApplication)
{$ifdef BOOLFIX}
procedure activateIgnoringOtherApps_(flag: ObjCBool); message 'activateIgnoringOtherApps:';
@ -642,6 +654,7 @@ const
NSAppKitVersionNumber10_13 = 1561;
//NSAppKitVersionNumber10_14 = 1641.10; // Mojave's beta?
NSAppKitVersionNumber10_14 = 1671;
NSAppKitVersionNumber10_15 = 1894;
NSAppKitVersionNumber11_0 = 2022; // 2000 starts with beta?
NSAppKitVersionNumber12_0 = 2113;
NSAppKitVersionNumber13_0 = 2299;

View File

@ -615,7 +615,19 @@ begin
// If this is not a "systemFont" Create the font ourselves
if IsDefault then
begin
FFont := NSFont.systemFontOfSize( FSize );
if ALogFont.lfPitchAndFamily = FIXED_PITCH then
begin
if NSAppKitVersionNumber >= NSAppKitVersionNumber10_15 then
FFont := NSFont.monospacedSystemFontOfSize_weight(FSize, NSFontWeightRegular)
else
FFont := NSFont.fontWithName_size(NSSTR('Menlo'), FSize);
if cfs_Bold in Style then
FFont := NSFontManager.sharedFontManager.convertFont_toHaveTrait(FFont, NSBoldFontMask);
end
else if cfs_Bold in Style then
FFont := NSFont.boldSystemFontOfSize( FSize )
else
FFont := NSFont.systemFontOfSize( FSize );
end else begin
FontName := NSStringUTF8(FName);
FFont := NSFont.fontWithName_size(FontName, FSize);

View File

@ -1398,6 +1398,8 @@ begin
ALogFont^.lfFaceName := AFont.Name;
ALogFont^.lfHeight := -AFont.Size; // Cocoa supports only full height (with leading) that corresponds with a negative value in WinAPI
Traits := NSFontManager.sharedFontManager.traitsOfFont(AFont.Font);
if AFont.Font.isFixedPitch then
ALogFont^.lfPitchAndFamily := FIXED_PITCH;
if (Traits and NSFontBoldTrait) <> 0 then
ALogFont^.lfWeight := FW_BOLD
else