mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-13 13:49:30 +02:00
cocoa: using the name filter for EnumFonts function, issue #39771
(cherry picked from commit 6f5b2e4b66
)
This commit is contained in:
parent
5baac72672
commit
c7f93033ac
@ -48,6 +48,8 @@ function CreateParamsToNSRect(const params: TCreateParams): NSRect;
|
||||
|
||||
function NSStringUtf8(s: PChar): 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 GetNSObjectWindow(obj: NSObject): NSWindow;
|
||||
@ -802,6 +804,18 @@ begin
|
||||
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;
|
||||
begin
|
||||
Result := CFStringToStr(CFStringRef(ns));
|
||||
|
@ -735,25 +735,28 @@ var
|
||||
w : CGFloat;
|
||||
t : Integer;
|
||||
|
||||
pitchFilter : Integer;
|
||||
names : NSArray;
|
||||
nameFilter : string;
|
||||
const
|
||||
FW_MAX = FW_HEAVY;
|
||||
begin
|
||||
Result := 0;
|
||||
if not Assigned(Callback) then Exit;
|
||||
|
||||
pitchFilter := 0;
|
||||
names := nil;
|
||||
if Assigned(lpLogFont) then
|
||||
begin
|
||||
pitchFilter := lpLogFont^.lfPitchAndFamily;
|
||||
if pitchFilter = MONO_FONT then pitchFilter := FIXED_PITCH;
|
||||
if (pitchFilter < 0) or (pitchFilter > VARIABLE_PITCH) then
|
||||
pitchFilter := 0;
|
||||
nameFilter := lpLogFont^.lfFaceName;
|
||||
if nameFilter<>'' then
|
||||
names := NSArray.arrayWithObject( StrToNSStr(nameFilter) );
|
||||
end;
|
||||
|
||||
|
||||
fm := NSFontManager.sharedFontManager;
|
||||
for fname in fm.availableFontFamilies do
|
||||
if not Assigned(names) then
|
||||
names := fm.availableFontFamilies;
|
||||
|
||||
for fname in names do
|
||||
begin
|
||||
try
|
||||
FontName := NSStringToString(fname);
|
||||
@ -800,8 +803,6 @@ begin
|
||||
else
|
||||
ELogFont.elfLogFont.lfPitchAndFamily:=VARIABLE_PITCH;
|
||||
|
||||
if (pitchFilter <> 0) and (ELogFont.elfLogFont.lfPitchAndFamily <> pitchFilter) then
|
||||
continue;
|
||||
Result := CallBack(ELogFont, Metric, TRUETYPE_FONTTYPE, lparam);
|
||||
if Result = 0 then Break;
|
||||
end;
|
||||
|
Loading…
Reference in New Issue
Block a user