Jump to content
Sign in to follow this  
Linuxuser1234

How can i add a custom font to a windows fmx application

Recommended Posts

im trying to add a custom font 'DSEG' which is basically a seven segment display  does anyone have any code examples i can use i have tried some before but i couldn't get the code working 

Share this post


Link to post
3 minutes ago, Linuxuser1234 said:

i am using Delphi 10.4 Community Edition 

I asked because of an issue that was fixed in 11.2, but there's a patch for 10.4:

 

https://quality.embarcadero.com/browse/RSP-17030

 

I'm working on some code that should make it convenient to load fonts at runtime (on Windows), but for Delphi 10.4, that patch will be required.

Share this post


Link to post

Another option that works in XE7+ and cross-platform is use the Skia4delphi as your app render. Then you only need to add the follow code in the app initialization:

 

initialization
  TSkTypefaceManager.RegisterTypeface('Material Design Icons Desktop.ttf');

  • Like 1

Share this post


Link to post

@vfbb with skia4delphi can i also use that library to make a text rendering engine where i want to have a 2d troundrect with a shadow on to my viewport 3d to display wind data/temperature data and have the text change color based on the temp or wind data is that possible with skia4delphi 

Share this post


Link to post

@vfbb i also get a undeclared identifier errors 

initialization
 TSkTypefaceManager.RegisterTypeface('C:\Boltgui\Popups\Font\DSEG14ClassicMini-Bold.ttf');
end.

921745223_Screenshot2022-11-01230153.png.b2e089418cb398d2ccf652827b9c8863.png

Share this post


Link to post

here is the full unit file code 

unit Unit7;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Objects,
  FMX.Controls.Presentation, FMX.StdCtrls, FMX.ListBox, FMX.Effects, FMX.Edit,
  FMX.ComboEdit, FMX.Media, IdBaseComponent, IdComponent, IdTCPConnection,
  IdTCPClient, IdHTTP, IdMessage, IdAttachment, IdAuthentication;

type
  TForm7 = class(TForm)
    ArcDial1: TArcDial;
    Rectangle1: TRectangle;
    Label1: TLabel;
    Label2: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    ShadowEffect1: TShadowEffect;
    ComboEdit1: TComboEdit;
    Image1: TImage;
    Button1: TButton;
    Image2: TImage;
    Label3: TLabel;
    Button2: TButton;
    Image3: TImage;
    Image4: TImage;
    RoundRect1: TRoundRect;
    Line1: TLine;
    Rectangle2: TRectangle;
    Rectangle3: TRectangle;
    GlowEffect1: TGlowEffect;
    Label6: TLabel;
    MediaPlayer1: TMediaPlayer;
    IdHTTP1: TIdHTTP;
    Label7: TLabel;
    Label8: TLabel;
    RoundRect2: TRoundRect;
    Label9: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure IdHTTP1Authorization(Sender: TObject;
      Authentication: TIdAuthentication; var Handled: Boolean);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form7: TForm7;

implementation

{$R *.fmx}

procedure TForm7.Button1Click(Sender: TObject);
//This Button Connects to weatherusa radio server and change
//a few labels caption
begin
Label2.Text := '162.550 MHz';
Label6.Text := 'Status: Connected';
Label5.Text := 'KEC61';  //default Wx radio Station
Label7.Text := 'AL'; //default state
Label8.Text := 'Mobile';
Button1.Text := 'Click to disconnect from weatherusa.net';
end;
procedure TForm7.IdHTTP1Authorization(Sender: TObject;
  Authentication: TIdAuthentication; var Handled: Boolean);

begin
// connect to weatherusa

end;
initialization
 TSkTypefaceManager.RegisterTypeface('C:\Boltgui\Popups\Font\DSEG14ClassicMini-Bold.ttf');
end.

 

Share this post


Link to post

I'm not familiar with FMX internals, but won't that work?

 

    AddFontResourceEx(AFileName, FR_PRIVATE, nil);


 

Share this post


Link to post

@Linuxuser1234 To be clearer, follow the steps:

  1. Install Skia4Delphi via GetIt or by downloading the installer from github.
  2. Enable the use of Skia in your project: right click on the project > "Enable Skia"
  3. Open your project's dpr to enable Skia as your app's renderer and to register the custom font you want:
uses
  System.StartUpCopy,
  FMX.Forms,
  Skia, // <<
  Skia.FMX, // <<
  Unit1 in 'Unit1.pas' {Form1};

{$R *.res}

begin
  GlobalUseSkia := True; // <<
  TSkTypefaceManager.RegisterTypeface('C:\Boltgui\Popups\Font\DSEG14ClassicMini-Bold.ttf'); // <<
  Application.Initialize;
  ...

 

Share this post


Link to post
51 minutes ago, Linuxuser1234 said:

@vfbb ok so i added that to my dbr project file so in my unit7 file how would i apply that font to TLabel2 

You should use the font family name (which is not necessarily the same as the file name) in family property of controls. 

One problem you will face is that this property in designtime only lists the fonts registered on your system, so you must install the font on your system (by double clicking on it), and reopen your IDE, so that you can select your font on the Family property.

 

Note: only you will install the font on the system (to be able to select it inside the IDE), your clients will not need it.

Share this post


Link to post

I have a custom font in my Windows app. I created the font as a .ttf file. It gets installed under Windows with the app using Inno Setup. It can then be used like any other font within the app. You can do something similar for other platforms.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×