cocoa: using the name filter for EnumFonts function, issue #39771

This commit is contained in:
Dmitry Boyarintsev 2022-05-31 20:43:10 -04:00 committed by Maxim Ganetsky
parent f6554ced9b
commit 6f5b2e4b66
2 changed files with 24 additions and 9 deletions

View File

@ -48,6 +48,8 @@ function CreateParamsToNSRect(const params: TCreateParams): NSRect;
function NSStringUtf8(s: PChar; len: Integer = -1): NSString; function NSStringUtf8(s: PChar; len: Integer = -1): NSString;
function NSStringUtf8(const s: String): NSString; function NSStringUtf8(const s: String): NSString;
function StrToNSString(const s: string; AutoRelease: Boolean = true): NSString;
function StrToNSStr(const s: string; AutoRelease: Boolean = true): NSString; inline;
function NSStringToString(ns: NSString): String; function NSStringToString(ns: NSString): String;
function GetNSObjectWindow(obj: NSObject): NSWindow; function GetNSObjectWindow(obj: NSObject): NSWindow;
@ -812,6 +814,18 @@ begin
end; end;
end; end;
function StrToNSString(const s: string; AutoRelease: Boolean): NSString;
begin
Result := NSStringUtf8(s);
if Assigned(Result) and AutoRelease then
Result := Result.autorelease;
end;
function StrToNSStr(const s: string; AutoRelease: Boolean = true): NSString; inline;
begin
Result := StrToNSString(s, AutoRelease);
end;
function NSStringToString(ns: NSString): String; function NSStringToString(ns: NSString): String;
begin begin
Result := CFStringToStr(CFStringRef(ns)); Result := CFStringToStr(CFStringRef(ns));

View File

@ -735,25 +735,28 @@ var
w : CGFloat; w : CGFloat;
t : Integer; t : Integer;
pitchFilter : Integer; names : NSArray;
nameFilter : string;
const const
FW_MAX = FW_HEAVY; FW_MAX = FW_HEAVY;
begin begin
Result := 0; Result := 0;
if not Assigned(Callback) then Exit; if not Assigned(Callback) then Exit;
pitchFilter := 0; names := nil;
if Assigned(lpLogFont) then if Assigned(lpLogFont) then
begin begin
pitchFilter := lpLogFont^.lfPitchAndFamily; nameFilter := lpLogFont^.lfFaceName;
if pitchFilter = MONO_FONT then pitchFilter := FIXED_PITCH; if nameFilter<>'' then
if (pitchFilter < 0) or (pitchFilter > VARIABLE_PITCH) then names := NSArray.arrayWithObject( StrToNSStr(nameFilter) );
pitchFilter := 0;
end; end;
fm := NSFontManager.sharedFontManager; fm := NSFontManager.sharedFontManager;
for fname in fm.availableFontFamilies do if not Assigned(names) then
names := fm.availableFontFamilies;
for fname in names do
begin begin
try try
FontName := NSStringToString(fname); FontName := NSStringToString(fname);
@ -800,8 +803,6 @@ begin
else else
ELogFont.elfLogFont.lfPitchAndFamily:=VARIABLE_PITCH; ELogFont.elfLogFont.lfPitchAndFamily:=VARIABLE_PITCH;
if (pitchFilter <> 0) and (ELogFont.elfLogFont.lfPitchAndFamily <> pitchFilter) then
continue;
Result := CallBack(ELogFont, Metric, TRUETYPE_FONTTYPE, lparam); Result := CallBack(ELogFont, Metric, TRUETYPE_FONTTYPE, lparam);
if Result = 0 then Break; if Result = 0 then Break;
end; end;