Jump to content
Sign in to follow this  
azrael_11

IcoMoon font with TText

Recommended Posts

I add IcoMoon free Font  https://icomoon.io/#preview-free with this code

 

AddFontResource(PChar(extrafe.prog.Paths.Fonts + 'icomoon.ttf'));
  SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);

 

Then i creat a TText component on run

  ex_load.Intro.Text:= TText.Create(ex_load.Intro.Video);
  ex_load.Intro.Text.Name:= 'Loading_Intro_Text';
  ex_load.Intro.Text.Parent:=  ex_load.Intro.Video;
  ex_load.Intro.Text.SetBounds(extrafe.res.Width- 300, 10, 300, 30);
  ex_load.Intro.Text.Font.Family:= "IcoMoon-Free';
  ex_load.Intro.Text.Text:= 'e900';
  ex_load.Intro.Text.TextSettings.FontColor:= TAlphaColorRec.White;
  ex_load.Intro.Text.TextSettings.Font.Size:= 32;
  ex_load.Intro.Text.TextSettings.HorzAlign:= TTextAlign.Trailing;
  ex_load.Intro.Text.OnClick:= ex_load.Input.mouse.Text.OnMouseClick;
  ex_load.Intro.Text.Visible:= True;

That is suppose to see a black house instead you see a e900

Is there anything i forget or have something to see the icon of the icomoon in my text?

 

Share this post


Link to post
2 hours ago, uligerhardt said:

I guess something like


ex_load.Intro.Text.Text := #$e900;

should work.

 

Nope doesn't work.

 

Share this post


Link to post

What does "doesn't work" mean for you? Computer exploding? Hard drive formatted?

 

I just created a FMX app with this:

procedure TForm1.FormCreate(Sender: TObject);
begin
  AddFontResource('C:\Users\uli\Documents\Embarcadero\Studio\Projekte\IcoMoon\IcoMoon-Free-master\Font\IcoMoon-Free.ttf');
  SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);
  Text1.Font.Family:= 'IcoMoon-Free';
  Text1.Text:= #$e900;
  Text1.TextSettings.FontColor:= TAlphaColorRec.Red;
  Text1.TextSettings.Font.Size:= 32;
  Text1.TextSettings.HorzAlign:= TTextAlign.Trailing;
end;

And I get a red house. I'm not sure if it matters that font file name and family are the same in my sample.

Share this post


Link to post
1 hour ago, uligerhardt said:

What does "doesn't work" mean for you? Computer exploding? Hard drive formatted?

 

I just created a FMX app with this:


procedure TForm1.FormCreate(Sender: TObject);
begin
  AddFontResource('C:\Users\uli\Documents\Embarcadero\Studio\Projekte\IcoMoon\IcoMoon-Free-master\Font\IcoMoon-Free.ttf');
  SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);
  Text1.Font.Family:= 'IcoMoon-Free';
  Text1.Text:= #$e900;
  Text1.TextSettings.FontColor:= TAlphaColorRec.Red;
  Text1.TextSettings.Font.Size:= 32;
  Text1.TextSettings.HorzAlign:= TTextAlign.Trailing;
end;

And I get a red house. I'm not sure if it matters that font file name and family are the same in my sample.

The font appear in the settings->personalization->fonts so that means it loading

 

But i get a square instead of the house.

 

But if i install the font permanently then everything works just fine...

Edited by azrael_11

Share this post


Link to post
10 hours ago, uligerhardt said:

What does AddFontResource return?

It returns the number 1 not 0 as suppose to return.

Share this post


Link to post

What happens if you install the font in Windows and just try to use it the same way as any other font? (Saw that was answered already).

 

AddFontResource is a WinAPI call, so if you plan for cross-platform FMX code, you should not use it. 

 

Also, https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-addfontresourcea
says that return value for success = the number of fonts installed, and 0 = failure.

Share this post


Link to post
On 3/11/2019 at 9:29 AM, Lars Fosdal said:

What happens if you install the font in Windows and just try to use it the same way as any other font? (Saw that was answered already).

 

AddFontResource is a WinAPI call, so if you plan for cross-platform FMX code, you should not use it. 

 

Also, https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-addfontresourcea
says that return value for success = the number of fonts installed, and 0 = failure.

I plan in the future to be multi platform so what is the best way  to do that?

 

Thank you.

Share this post


Link to post
21 hours ago, azrael_11 said:

I plan in the future to be multi platform so what is the best way  to do that?

 

Thank you.

For Windows, the norm would be to install the font. AddFontResource could be used, but as you demonstrated, it doesn't seem to work as intended?
For MacOS, I would also assume that installing the font is recommended.
I've not used custom fonts with FMX on Android or iOS, so I can't answer that.

  • Like 1

Share this post


Link to post
1 hour ago, Lars Fosdal said:

For Windows, the norm would be to install the font. AddFontResource could be used, but as you demonstrated, it doesn't seem to work as intended?
For MacOS, I would also assume that installing the font is recommended.
I've not used custom fonts with FMX on Android or iOS, so I can't answer that.

So the installation in every operation system is the best choice.

Maybe we send a message to embarcadero developers to make a better in delphi solution.

Thank you very much.

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  

×