Recent

Author Topic: [Solved] Installing font if not exists  (Read 846 times)

madref

  • Hero Member
  • *****
  • Posts: 1082
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
[Solved] Installing font if not exists
« on: November 11, 2024, 11:58:11 am »
With this function I check if a font is installed on a system.
Code: Pascal  [Select][+][-]
  1. function FontIsAvailable(const FontName: string): Boolean;
  2. begin
  3.   Result := Screen.Fonts.IndexOf(FontName) >= 0;
  4. end;

How can I install a font if it is not on the system through code?
« Last Edit: November 13, 2024, 10:44:37 pm by madref »
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Main Platform:
--------------
Mac OS X Sonoma 14.7
Lazarus 3.99 (Lazarus 3.99 (rev main_3_99-2668-g6b352d830e) FPC 3.3.1 x86_64-darwin-cocoa)

Windows 10 Pro
Lazarus 3.99 (rev cbfd80ce39)

Thaddy

  • Hero Member
  • *****
  • Posts: 16199
  • Censorship about opinions does not belong here.
Re: Installing font if not exists
« Reply #1 on: November 11, 2024, 12:46:26 pm »
By using a font resource and compiling that into your program.
If I smell bad code it usually is bad code and that includes my own code.

madref

  • Hero Member
  • *****
  • Posts: 1082
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: Installing font if not exists
« Reply #2 on: November 11, 2024, 01:04:10 pm »
Again....how?
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Main Platform:
--------------
Mac OS X Sonoma 14.7
Lazarus 3.99 (Lazarus 3.99 (rev main_3_99-2668-g6b352d830e) FPC 3.3.1 x86_64-darwin-cocoa)

Windows 10 Pro
Lazarus 3.99 (rev cbfd80ce39)

rvk

  • Hero Member
  • *****
  • Posts: 6591
Re: Installing font if not exists
« Reply #3 on: November 11, 2024, 01:16:45 pm »
How can I install a font if it is not on the system through code?
Do you really want to install the font for the whole system?

You can even use any font without even installing it (and even loading it from resource instead of external file).
https://forum.lazarus.freepascal.org/index.php/topic,63107.msg477587.html#msg477587

O, and you didn't mention what platform.
You have multiple platforms in your signature.

madref

  • Hero Member
  • *****
  • Posts: 1082
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: Installing font if not exists
« Reply #4 on: November 12, 2024, 04:51:40 pm »
My main platform is Mac OSx.


And I want to integrate it in this : https://forum.lazarus.freepascal.org/index.php/topic,67070.75.html

« Last Edit: November 12, 2024, 05:04:30 pm by madref »
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Main Platform:
--------------
Mac OS X Sonoma 14.7
Lazarus 3.99 (Lazarus 3.99 (rev main_3_99-2668-g6b352d830e) FPC 3.3.1 x86_64-darwin-cocoa)

Windows 10 Pro
Lazarus 3.99 (rev cbfd80ce39)

rvk

  • Hero Member
  • *****
  • Posts: 6591
Re: Installing font if not exists
« Reply #5 on: November 12, 2024, 11:45:41 pm »
My main platform is Mac OSx.
Can't help you with Mac OS other than pointing you too this website for a solution.
https://www.tweaking4all.com/software-development/lazarus-development/macos-application-custom-font/

madref

  • Hero Member
  • *****
  • Posts: 1082
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: Installing font if not exists
« Reply #6 on: November 13, 2024, 12:35:13 am »
I don't want to use it for the whole app, but just for my graphics routines (Poppetjes).
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Main Platform:
--------------
Mac OS X Sonoma 14.7
Lazarus 3.99 (Lazarus 3.99 (rev main_3_99-2668-g6b352d830e) FPC 3.3.1 x86_64-darwin-cocoa)

Windows 10 Pro
Lazarus 3.99 (rev cbfd80ce39)

rvk

  • Hero Member
  • *****
  • Posts: 6591
Re: Installing font if not exists
« Reply #7 on: November 13, 2024, 12:49:19 am »
I don't want to use it for the whole app, but just for my graphics routines (Poppetjes).
So? The method is still the same.

My understanding is that after doing what is described on that page, you have access to that font like you do normally x.font.name := 'xxx'. But I could be mistaken (like I said, I don't do Mac).

Extra info
https://stackoverflow.com/questions/27680893/how-to-use-custom-fonts-in-a-mac-application
« Last Edit: November 13, 2024, 12:51:14 am by rvk »

madref

  • Hero Member
  • *****
  • Posts: 1082
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: Installing font if not exists
« Reply #8 on: November 13, 2024, 10:13:48 am »
Thanks RVK. This solution works great.


But now I have a strange behavior.
In run-time (the red one) I get the font to work, but in design-time (the green one) I don't het the same result.


Is there an explanation for?
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Main Platform:
--------------
Mac OS X Sonoma 14.7
Lazarus 3.99 (Lazarus 3.99 (rev main_3_99-2668-g6b352d830e) FPC 3.3.1 x86_64-darwin-cocoa)

Windows 10 Pro
Lazarus 3.99 (rev cbfd80ce39)

rvk

  • Hero Member
  • *****
  • Posts: 6591
Re: Installing font if not exists
« Reply #9 on: November 13, 2024, 11:38:45 am »
But now I have a strange behavior.
In run-time (the red one) I get the font to work, but in design-time (the green one) I don't het the same result.
As explained in the link, during design-time you need to install the font like normal. Otherwise the IDE doesn't have access to it.
The mentioned solution is only for running the app outside the ide and on computers where the font isn't present.

Quote
Tip: During development of your application – install the font!

When you’re still developing your application, I’d recommend installing the TTF font on your computer like any other regular font. This way you can access the font and see the result in the development phase of your application. Keep in mind that you need to restart Lazarus after installing or removing a font, for Lazarus to “see” the font.

Font installation is quite simple: double click the TTF file and follow the steps to install.
Removing the font (to test if your application actually picks up the custom font, even when the font is not installed) is pretty straight forward as well: open FontBook (“Applications”  “FontBook”), find your font, right click the font-name, and select “Remove XYZ family”.
https://www.tweaking4all.com/software-development/lazarus-development/macos-application-custom-font/

madref

  • Hero Member
  • *****
  • Posts: 1082
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: Installing font if not exists
« Reply #10 on: November 13, 2024, 10:44:23 pm »
oeps...hadn't read that part correctly :)

You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Main Platform:
--------------
Mac OS X Sonoma 14.7
Lazarus 3.99 (Lazarus 3.99 (rev main_3_99-2668-g6b352d830e) FPC 3.3.1 x86_64-darwin-cocoa)

Windows 10 Pro
Lazarus 3.99 (rev cbfd80ce39)

 

TinyPortal © 2005-2018