My application is a VCL Win64 application built with Delphi 10.3.3.
For some reason, AddFontResource()
is not working properly on Windows 11.
Here is what I have so far:
procedure TfrmMenuPrincipal.CriaFontesArialNarrow;
const
cFonteArialNarrow: array [0..3] of string = (
'ARIALN',
'ARIALNB',
'ARIALNBI',
'ARIALNI'
);
var
_FontFolder,
_Resorce,
_FontFile: string;
_Res: TResourceStream;
begin
_FontFolder := TSpecialFolders.GetAppDataFontFileFolder; // 'C:\Users\Leonardo\AppData\Roaming\MyApp\Fonts'
for _Resorce in cFonteArialNarrow do
begin
_FontFile := _FontFolder + _Resorce + '.TTF';
if not FileExists(_FontFile) then
begin
_Res := TResourceStream.Create(hInstance, _Resorce, 'FILE');
try
_Res.SaveToFile(_FontFile );
finally
_Res.Free;
end;
end;
AddFontResource(PChar(_FontFile));
//Screen.Fonts.Add(_FontFile );
SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);
end;
// Screen.Fonts.Add('Arial Narrow');
end;
No errors, app runs fine, but it can't use the fonts inside the application.
I read somewhere that font files should be on a folder that is contained in the PATH
environment variable, but I have tested that and it didn't work.
Also, I have checked several Google hits, and other threads here at StackOverflow, but no luck.
Any tips?
C:\Windows\Fonts
instead? That said, rather than saving your fonts from your app's resources to disk, why not simply useAddFontMemResourceEx()
instead to install the resource data as-is? Are you trying to allow other apps to use your fonts, or just your own app?