Embedding a font in delphi

后端 未结 2 1240
挽巷
挽巷 2020-12-15 21:47

I\'m working on an app that requires a particular barcode true type font that is unlikely to be on the user\'s PC.

Can I somehow embed the font in the app, or do I

2条回答
  •  鱼传尺愫
    2020-12-15 22:12

    In my opinion the most easy way is to use AddFontMemResourceEx in case the font is embedded as a resource into the EXE. It allows loading the font directly from memory, no need to save the font to file.

    Code Example:

    function LoadResourceFont( const ResourceName : string ) : boolean;
    var
       ResStream : tResourceStream;
       FontsCount : integer;
       hFont : tHandle;
    begin
       ResStream := tResourceStream.Create(hInstance, ResourceName, RT_RCDATA);
       hFont := AddFontMemResourceEx(ResStream.Memory, ResStream.Size, nil, @FontsCount);
       result := (hFont <> 0);
       ResStream.Free();
    end;
    

提交回复
热议问题