How Can I use embedded font or install new fonts in my firemonkey application?
I tried this solution but WM_FONTCHANGE
is not defined in FMX!
I want
You can surely use the Winapi.Messages
unit in your FMX app which is clearly targeting Windows, and the message constant is defined there.
If you don't want to use Winapi.Messages
, just define the constant in your own code:
const
WM_FONTCHANGE = $001D;
I followed the instructions here, and they were of some help. I have a few extra hints that may help,
Now, I've adding the following code,
procedure TMainForm.FormCreate(Sender: TObject);
begin
AddFontResource('c:\fontpath\myfont.ttf');
SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0) ;
end;
procedure TMainForm.FormDestroy(Sender: TObject);
begin
RemoveFontResource('c:\fontpath\myfont.ttf');
SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0) ;
end;
When I run this in a firemonkey form, i've observed the following.
This tells me that my code works (see bullets 1. and 6.) - but FMX won't recognise the font on my main form if you use the name that appears in notepad. I've quadruple checked the font name.
I created two identical projects. One was VCL and the other was FMX. The VCL project works perfectly - both for static text and dynamic text. The FMX code works for neither. If I had to hazard a guess, i'd say that FMX is building a list of fonts on startup, and checking the list of available fonts against that list (ie. like a cache). I'd hazard a guess this is being done to abstract FMX from the underlying operating system...
If anyone has made this work under firemonkey, I would appreciate any advice. Also, if anyone knows how to achieve the same goal under a Mac, i'd appreciate a pointer too.
Regards,
Mr Ed.