2021年12月20日 星期一

EtheaDev IconFontsImageList https://githubhelp.com/EtheaDev/IconFontsImageList

 https://githubhelp.com/EtheaDev/IconFontsImageList

 

Four advanced components to simplify use of Icon Fonts as images and ImageList: TIconFontImage, TIconFontsImageCollection, TIconFontsVirtualImageList, TIconFontsImageList (for VCL and FMX). Full support for High-DPI apps. Rendering optimized with GDI+ 



delphi-code-coverage/JwaWinGDI.pas

 at master - GitHub


This is a clone of the code coverage tool for Delphi on ... function AddFontResource(lpszFileName: LPCTSTR): Integer; stdcall;.

load font

https://tipsfordev.com/firemonkey-load-alternative-font

FIREMONKEY - load alternative font

I would like to load an external font in a Delphi Firemonkey application.

Is there any information how to do that?


Not sure if it works for FireMonkey, but this code worked for me when I wanted to load custom fonts to my standard Delphi applications.
 
uses
  Windows, SysUtils, Messages, Classes, Generics.Collections;

type
  { .: TExternalFonts :. }
  TExternalFonts = class sealed(TList<HFONT>);

var
  ExternalFonts: TExternalFonts;

function AddExternalFont(const AFileName: String): HFONT; overload;
function AddExternalFont(const AStream: TStream): HFONT; overload;

implementation

{ .: DoCleanup :. }
procedure DoCleanup();
var
  I: Integer;
begin
  for I := ExternalFonts.Count -1 downto 0 do
  begin
    RemoveFontMemResourceEx(ExternalFonts[I]);
    ExternalFonts.Delete(I);
    //SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);
  end;
end;

{ .: AddExternalFont :. }
function AddExternalFont(const AFileName: String): HFONT; overload;
var
  FS: TFileStream;
begin
  Result := 0;

  if not FileExists(AFileName) then
    exit;

  FS := TFileStream.Create(AFileName, fmOpenRead + fmShareExclusive);
  try
    Result := AddExternalFont(FS);
  finally
    FS.Free();
  end;
end;

{ .: AddExternalFont :. }
function AddExternalFont(const AStream: TStream): HFONT; overload;
var
  MS: TMemoryStream;
  Temp: DWORD;
begin
  Result := 0;

  if not Assigned(AStream) then
    exit;

  Temp := 1;
  MS := TMemoryStream.Create();
  try
    MS.CopyFrom(AStream, 0);

    Result := AddFontMemResourceEx(MS.Memory, MS.Size, nil, @Temp);
    if (Result <> 0) then
      ExternalFonts.Add(Result);
    //SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);
  finally
    MS.Free();
  end;
end;

initialization
  ExternalFonts := TExternalFonts.Create();

finalization
  DoCleanup();
  ExternalFonts.Free();

end.
 

use external fonts font directly from resources in Delphi Resource Compiler brcc32 MSBuild

 use external fonts font directly from resources in Delphi
AddFontMemResourceEx
https://docs.microsoft.com/zh-tw/windows/win32/api/wingdi/nf-wingdi-addfontmemresourceex?redirectedfrom=MSDN
https://docs.microsoft.com/zh-tw/windows/win32/api/wingdi/nf-wingdi-addfontresourcea?redirectedfrom=MSDN
https://docs.microsoft.com/zh-tw/windows/win32/api/wingdi/nf-wingdi-addfontresourceexa?redirectedfrom=MSDN
https://docs.microsoft.com/zh-tw/windows/win32/api/wingdi/nf-wingdi-addfontmemresourceex?redirectedfrom=MSDN
https://sourceforge.net/projects/jvcl/
 JVCL's TjvDataEmbedded AddFontResource
https://docwiki.embarcadero.com/RADStudio/Sydney/en/Step_3_-_Add_Style-Resources_as_RCDATA_(Delphi)
Step 3 - Add Style-Resources as RCDATA (Delphi)


procedure TForm1.FormCreate(Sender: TObject) ;
begin
  AddFontResource('c:\FONTS\MyFont.TTF') ;
  SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0) ;
end;

//Before application terminates we must remove our font:
procedure TForm1.FormDestroy(Sender: TObject) ;
begin
  RemoveFontResource('C:\FONTS\MyFont.TTF') ;
  SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0) ;
end;
https://stackoverflow.com/questions/2984474/embedding-a-font-in-delphi
https://stackoverflow.com/questions/36224624/loading-font-from-resource-file

TResourceStream AddFontResource WM_FONTCHANGE message
   ResStream : tResourceStream;
   FontsCount : integer;
   hFont : tHandle;
 
   ResStream := tResourceStream.Create(hInstance, ResourceName, RT_RCDATA);
   hFont := AddFontMemResourceEx(ResStream.Memory, ResStream.Size, nil, @FontsCount);
   result := (hFont <> 0);
   ResStream.Free();
 

function LoadResourceFontByName( const ResourceName : string; ResType: PChar ) : Boolean;
var
  ResStream : TResourceStream;
  FontsCount : DWORD;
begin
  ResStream := TResourceStream.Create(hInstance, ResourceName, ResType);
  try
    Result := (AddFontMemResourceEx(ResStream.Memory, ResStream.Size, nil, @FontsCount) <> 0);
  finally
    ResStream.Free;
  end;
end;

function LoadResourceFontByID( ResourceID : Integer; ResType: PChar ) : Boolean;
var
  ResStream : TResourceStream;
  FontsCount : DWORD;
begin
  ResStream := TResourceStream.CreateFromID(hInstance, ResourceID, ResType);
  try
    Result := (AddFontMemResourceEx(ResStream.Memory, ResStream.Size, nil, @FontsCount) <> 0);
  finally
    ResStream.Free;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  if LoadResourceFontByName('MyFont1', RT_RCDATA) then
    Label1.Font.Name := 'My Font Name 1';

  if LoadResourceFontByID(2, RT_FONT) then
    Label2.Font.Name := 'My Font Name 2';
end;

LoadResourceFontByName
delphi add font resource file LoadResourceFontByName
[Solved] Embedding a font in delphi - Code Redirect
https://www.sql.ru/forum/1254355/delphi-zagruzit-shrift-iz-resursov

{$R MyNewFont.RES}
...
procedure TForm1.FormCreate(Sender: TObject);
var
  MyResStream: TResourceStream;
begin
  MyResStream:=TResourceStream.Create(hInstance, 'MYFONT', RT_RCDATA);
  MyResStream.SavetoFile('Gen4.ttf');
  AddFontResource(PChar('Gen4.ttf'));
  SendMessage(HWND_BROADCAST,WM_FONTCHANGE,0,0);
  Label1.Font.Charset:=SYMBOL_CHARSET;
  Label1.Font.Size:=24;
  Label1.Font.Name:='Gen4';
end;

MSBuild.exe C:/Project1.dproj /t:Build /p:configutation=Debug /p:platform=Win32

https://docwiki.embarcadero.com/RADStudio/Sydney/en/BRCC32.EXE,_the_Resource_Compiler
Resource Compiler, brcc32.exe

https://delphi.cjcsoft.net/viewthread.php?tid=47317

{$R MyFont.res}
  Res : TResourceStream;
 
  Res := TResourceStream.Create(hInstance, 'MY_FONT', Pchar('ANYOL1'));
  Res.SavetoFile('Bauhs93.ttf');
  Res.Free;
  AddFontResource(PChar('Bauhs93.ttf'));
  SendMessage(HWND_BROADCAST,WM_FONTCHANGE,0,0);
 
  RemoveFontResource(PChar("Bauhs93.ttf"))
  SendMessage(HWND_BROADCAST,WM_FONTCHANGE,0,0);