Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2017-02

Embedded font

3 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Luca Olivetti
to Darius Blaszyk

El 06/02/17 a les 22:06, Darius Blaszyk via Lazarus ha escrit:

Show quoted text 5 lines
Hi, Is it possible to embed a font for a GUI application in Lazarus in a platform independent way? I've been looking on the internet and I only found windows specific solutions so far.

You already know the windows way, so I'll omit it.

With qt you can use QFontDatabase_addApplicationFont, e.g.

uses qt4;
...
procedure TForm1.FormCreate(Sender: TObject);
var ws:WideString;
begin
   ws:='/file/with/the/font.ttf';
   QFontDatabase_addApplicationFont(@ws)
end;

There's also a addApplicationFontFromData if you want to load the font from a resource.

With GTK you can use fontconfig, e.g.

uses fontconfig;
....
function FcConfigAppFontAddFile(config:pointer;
fname:Pchar):FcBool;stdcall;external 'libfontconfig.so';
....
procedure TForm1.FormCreate(Sender: TObject);
var
   res: FcBool;
begin
   res:=FcConfigAppFontAddFile(nil,'/file/with/the/font.ttf');
end;

There isn't a function to load the font from data, so if you want to use resources I guess you should save it to a temporary file and load the font from it.

What I couldn't find is a way to know if the application is using qt or gtk (or win): LCLWidgetType is an ide macro, not a define.

Bye

Luca Olivetti Wetron Automation Technology http://www.wetron.es/ Tel. +34 93 5883004 (Ext.3010) Fax +34 93 5883007

Reply by email