Install font in firemonkey
Asked Answered
P

2

0

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 to use custom font in my application, how I can do this?

Paintbox answered 13/4, 2013 at 7:39 Comment(2)
Using a new font is not going to make your text look any better, if my guess that this question is related to your other question is correctCassey
No its different problem!Paintbox
S
3

I followed the instructions here, and they were of some help. I have a few extra hints that may help,

  • The two inclusions that you will need to make this work is WinAPI.Windows and WinAPI.Messages.
  • If you put these inclusions at the start of your "uses" clause, you're unlikely to have name conflicts with things like TBitmap.

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.

  1. The code runs
  2. Other applications (eg. notepad, office) can suddenly see the new font
  3. Text objects in my application don't recognise the new font
  4. If I dynamically name my text object with the font name, it still won't change.
  5. If I dynamically name my text object with another obvious font, it changes.
  6. If I shut down my application, other applications stop seeing the new font.

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.

Seismoscope answered 24/8, 2013 at 0:48 Comment(1)
Did anyone find a solution or workaround? - I can use custom fonts on iOS and OS X, but not on Windows because of this problem.Klockau
C
1

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;
Cassey answered 13/4, 2013 at 8:29 Comment(2)
I accept this answer, but when I test this method in a new system, the new font not installed!Paintbox
I believe this is not sufficient because it seems that FMX can't see the font. Perhaps FMX is using DirectWrite.Postulant

© 2022 - 2024 — McMap. All rights reserved.