Recent

Author Topic: TFont Full path  (Read 724 times)

CanineQwer

  • New Member
  • *
  • Posts: 18
TFont Full path
« on: March 20, 2020, 05:44:19 pm »
I have TFont.
How to get the full path to the font storage location?
Now I take TFont.Name and use it on the command line along with "fc-list" and "grep".
Please suggest a better solution.

*Linux.

wp

  • Hero Member
  • *****
  • Posts: 7553
Re: TFont Full path
« Reply #1 on: March 20, 2020, 06:09:39 pm »
There is no cross-platform solution. In TAChart, I use this code:

Code: Pascal  [Select][+][-]
  1. procedure PopulateFontDirList(AList: TStrings);
  2. const
  3.   CSIDL_FONTS = 20;
  4. var
  5.   s: String;
  6. begin
  7.   if AList = nil then
  8.     raise Exception.Create('PopulateFontDirList: list not allocated.');
  9.  
  10.  {$IFDEF WINDOWS}
  11.   s := SHGetFolderPathUTF8(CSIDL_FONTS);
  12.   if s <> '' then
  13.     AList.Add(s);
  14.  {$ENDIF}
  15.  {$IFDEF linux}
  16.   AList.Add('/usr/share/cups/fonts/');
  17.   AList.Add('/usr/share/fonts/truetype/');
  18.   AList.Add('/usr/local/lib/X11/fonts/');
  19.   AList.Add(GetUserDir + '.fonts/');
  20.  {$ENDIF}
  21.  {$IFDEF LCLCarbon}
  22.   AList.Add('/Library/Fonts/');
  23.   AList.Add('/System/Library/Fonts/');
  24.   AList.Add('/Network/Library/Fonts/');
  25.   AList.Add('~/Library/Fonts/');
  26.  {$ENDIF}
  27.  {$IFDEF LCLCocoa}
  28.   AList.Add('/Library/Fonts/');
  29.   AList.Add('/System/Library/Fonts/');
  30.   AList.Add('/Network/Library/Fonts/');
  31.   AList.Add('~/Library/Fonts/');
  32.  {$ENDIF}
  33. end;
  34.  
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

CanineQwer

  • New Member
  • *
  • Posts: 18
Re: TFont Full path
« Reply #2 on: March 20, 2020, 06:15:08 pm »
I do not need cross-platform.
I specifically need Linux.
It is possible and specifically GTK.

winni

  • Hero Member
  • *****
  • Posts: 1818
Re: TFont Full path
« Reply #3 on: March 20, 2020, 06:17:14 pm »
Hi!

For what reasons do you need the path to the font files?

The is the var screen.fonts which is a list of all fonts that Lazarus knows.

And for assigning a font to a component you dont need the path:

MyComponent.Font.Name := 'Arial' ;

Winni


CanineQwer

  • New Member
  • *
  • Posts: 18
Re: TFont Full path
« Reply #4 on: March 20, 2020, 06:27:46 pm »
I know that to use a font, the path is optional.
But I need a font file to transfer it to other people.
So just searching for it manually, as @wp suggested?
Is this the best solution?

winni

  • Hero Member
  • *****
  • Posts: 1818
Re: TFont Full path
« Reply #5 on: March 20, 2020, 07:44:06 pm »
Hi!

Okay, Linux only:

Look in /etc/fonts/fonts.conf

In the first lines there are the font directories of your system.
For Suse Linux it is:
Code: Text  [Select][+][-]
  1. <!-- Font directory list -->
  2.  
  3.         <dir>/usr/share/fonts</dir>
  4.         <dir>/usr/X11R6/lib/X11/fonts</dir>
  5.         <dir>/opt/kde3/share/fonts</dir>
  6.          <dir>/usr/local/share/fonts</dir>
  7.         <dir prefix="xdg">fonts</dir>
  8.         <!-- the following element will be removed in the future -->
  9.         <dir>~/.fonts</dir>
  10.  
  11.  

As you see it is XML.

Keep on hacking!
Winni

alanphys

  • New Member
  • *
  • Posts: 46
Re: TFont Full path
« Reply #6 on: July 09, 2020, 06:14:01 pm »
Hi

You can use unit fpTTF in fcl-pdf.

Code: Pascal  [Select][+][-]
  1. function GetFontFile(fName:string):string;
  2. var lFC:TFPFontCacheItem;
  3. begin
  4. gTTFontCache.ReadStandardFonts;
  5. lFC := gTTFontCache.Find(fName, fBold, fItalic);
  6. Result := lFC.FileName;
  7. end;
  8.  

My problem is gTTFontCache does not include font aliases. So the component 'default' font's name on my Fedora system is Sans Serif. If I look at the /usr/share/fonts directory there is no Sans Serif font. fc-match gives the Sans Serif font as Bitstream Vera Sans.

Listing Screen.fonts does list the Sans Serif font but I can't get the path to it.

There is an example under lazarus/examples/fontenum that lists the fonts including Serif and Sans Serif but doesn't appear to show how to get file info.

Perhaps the author of fpTTF @Graeme Geldenhys can help.

Regards
Alanphys
Fedora 32 + KDE/QT5, Tinycore 8, Windows XP-10
https://github.com/alanphys

 

TinyPortal © 2005-2018