3. Windows has \Windows\Fonts
3. Windows has \Windows\Fonts
That's not a good solution. User might not want to have the fonts installed for every running application. The better solution:
procedure TForm1.FormCreate(Sender: TObject) ; begin AddFontResource('c:FONTSMyFont.TTF') ; SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0) ; end; {Remove font again on program termination} procedure TForm1.FormDestroy(Sender: TObject; var Action: TCloseAction) ; begin RemoveFontResource('C:FONTSMyFont.TTF') ; SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0) ; end;
3. Windows has \Windows\Fonts
That's not a good solution. User might not want to have the fonts installed for every running application. The better solution:
procedure TForm1.FormCreate(Sender: TObject) ; begin AddFontResource('c:FONTSMyFont.TTF') ; SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0) ; end; {Remove font again on program termination} procedure TForm1.FormDestroy(Sender: TObject; var Action: TCloseAction) ; begin RemoveFontResource('C:FONTSMyFont.TTF') ; SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0) ; end;
Tested and works on Windows 11.I don't have Win11 but on Windows7 and Windows 10 it works. It also works in Delphi. So seems like a solid solution.
3. Windows has \Windows\Fonts
That's not a good solution. User might not want to have the fonts installed for every running application. The better solution:
procedure TForm1.FormCreate(Sender: TObject) ; begin AddFontResource('c:FONTSMyFont.TTF') ; SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0) ; end; {Remove font again on program termination} procedure TForm1.FormDestroy(Sender: TObject; var Action: TCloseAction) ; begin RemoveFontResource('C:FONTSMyFont.TTF') ; SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0) ; end;
Linux
https://itsfoss.com/install-fonts-ubuntu/ (https://itsfoss.com/install-fonts-ubuntu/)
Basically on Ubuntu / Mint one can create HOME/.fonts directory and put the fonts there, maybe that can be done easily from an FPC program... extracting the fonts from the binary, or using a folder where then we copy it to the hidden fonts folder.
@Thaddy what if the HOME/.fonts can't be created. I have a Linux system with the HOME folder blocked.
Or they refer as HOME as HOME/username?
@Thaddy what if the HOME/.fonts can't be created. I have a Linux system with the HOME folder blocked.
Or they refer as HOME as HOME/username?
@Thaddy what if the HOME/.fonts can't be created. I have a Linux system with the HOME folder blocked.
Or they refer as HOME as HOME/username?
I have HOME folder and that's not writable, but yes HOME/username is writable.
I'm not Linux expert, for that I ask. AFAIK our custom Linux might have support for that .fonts directory, that was not removed AFAIK. Is based on Mint.
So I need to create the folder in HOME/username/.fonts/
How I can do that with FPC?
Edit: Say I have the fonts in my program directory I access with this function:I want to copy to HOME/username/.fonts/myfont.ttf
DirectorioAplicacion + 'myfont.ttf'
So I need to create the folder in HOME/username/.fonts/
How I can do that with FPC?
Edit: Say I have the fonts in my program directory I access with this function:I want to copy to HOME/username/.fonts/myfont.ttf
DirectorioAplicacion + 'myfont.ttf'
I'm thinking about how you can do this...
Not sure if would be considered the normal way.
Usually fonts would be in standard location, and you would just indicate in your application the details of the font you are using.
EDIT: Unless you mean when your program runs, it needs to update a standard location? (copy a font that is next to application to the standard location?)
Exactly, I have say
home/username/myprogram/myfont.ttf
and I want to copy it to
home/username/.fonts/myfont.ttf at runtime, so it's available, only once, if exists don't copy it again... and create the folder if don't exists, all by code
Thanks it works, it copies the fonts!
{$IFDEF LINUX} CopyFileToHomeDir('VictorMono-Bold.otf', '.fonts'); CopyFileToHomeDir('VictorMono-Regular.otf', '.fonts'); {$ENDIF}
Thanks =)
I need a function for free pascal.
It receives 2 strings. 1) a file 2) a folder
For the file, it chesks for it's existence in the folder the application is being run from. This file with the application directory path is prepended to the file as the source file.
For the folder, it checks for it's existence in the user's home directory (home directory must be prepended).
If the folder does exist, it creates it.
This folder in the user's home directory is the destination folder.
If the source file exists, the the existence of the same file is checked or in the destination folder. If it does not exist in the destionation folder it is copied there.