TFont Full path lazarus / 66-Unix ---------------------------------------------------------------------- CanineQwer · 2020-03-20 16:44 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 · 2020-03-20 17:09 There is no cross-platform solution. In TAChart, I use this code: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure PopulateFontDirList(AList: TStrings);const  CSIDL_FONTS = 20;var  s: String;begin  if AList = nil then    raise Exception.Create('PopulateFontDirList: list not allocated.');  {$IFDEF WINDOWS}  s := SHGetFolderPathUTF8(CSIDL_FONTS);  if s <> '' then    AList.Add(s); {$ENDIF} {$IFDEF linux}  AList.Add('/usr/share/cups/fonts/');  AList.Add('/usr/share/fonts/truetype/');  AList.Add('/usr/local/lib/X11/fonts/');  AList.Add(GetUserDir + '.fonts/'); {$ENDIF} {$IFDEF LCLCarbon}  AList.Add('/Library/Fonts/');  AList.Add('/System/Library/Fonts/');  AList.Add('/Network/Library/Fonts/');  AList.Add('~/Library/Fonts/'); {$ENDIF} {$IFDEF LCLCocoa}  AList.Add('/Library/Fonts/');  AList.Add('/System/Library/Fonts/');  AList.Add('/Network/Library/Fonts/');  AList.Add('~/Library/Fonts/'); {$ENDIF}end; ---------------------------------------------------------------------- CanineQwer · 2020-03-20 17:15 I do not need cross-platform. I specifically need Linux. It is possible and specifically GTK. ---------------------------------------------------------------------- winni · 2020-03-20 17:17 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 · 2020-03-20 17:27 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 · 2020-03-20 18:44 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i          /usr/share/fonts        /usr/X11R6/lib/X11/fonts         /opt/kde3/share/fonts          /usr/local/share/fonts        fonts                ~/.fonts   As you see it is XML. Keep on hacking! Winni ---------------------------------------------------------------------- alanphys · 2020-07-09 16:14 Hi You can use unit fpTTF in fcl-pdf. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function GetFontFile(fName:string):string;var lFC:TFPFontCacheItem;begingTTFontCache.ReadStandardFonts;lFC := gTTFontCache.Find(fName, fBold, fItalic);Result := lFC.FileName;end;  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 ---------------------------------------------------------------------- jipété · 2023-06-24 09:29 Hello, Quote from: alanphys on July 09, 2020, 06:14:01 pmYou can use unit fpTTF in fcl-pdf. I tried to use your code in lazarus/examples/fontenum with a little change, like that : Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function GetFontFile(fName:string): string; // no help available :-(var  lFC: TFPFontCacheItem;begin  //gTTFontCache.ReadStandardFonts; // moved in FormShow  lFC := gTTFontCache.FindFont(fName);  Result := lFC.FileName;end; procedure TfrmMain.FormShow(Sender: TObject);begin  gTTFontCache.ReadStandardFonts; // jpt  ... procedure TfrmMain.SelectFont;var  F: TFont;  i: integer;  TTFS: TTrueTypeFontStyles; // set of TTrueTypeFontStyle -- added 19/06/2023 by jpt   function GetFontSize(s: string): Integer;  begin    i := pos('*',s);    if i<>0 then result := StrToInt(Copy(S, 1, i-1)) else result := StrToInt(s);  end;begin  if lbFamily.ItemIndex>=0 then    if lbCharSet.ItemIndex>=0 then      if lbStyles.ItemIndex>=0 then        if lbSizes.ItemIndex>=0 then        begin          F := TFont.Create;          try            F.Name := lbFamily.Items[lbFamily.ItemIndex];          F.CharSet := TFontCharSet(ptrint(lbCharSet.Items.Objects[lbCharset.ItemIndex]));          F.Size := GetFontSize(lbSizes.Items[lbSizes.ItemIndex]);          // jpt : added edtFullFileName, a TEdit with Align: Bottom          edtFullFileName.Text := ' Filename = ' + GetFontFile(lbFamily.Items.Strings[lbFamily.ItemIndex]); // jpt          i := ptrint(lbStyles.Items.Objects[lbStyles.ItemIndex]);          F.Style := [];            TTFS := []; // jpt : added for fpTTF//jpt          if i and 1 <> 0 then F.Style := F.Style + [fsItalic];//jpt          if i and 2 <> 0 then F.Style := F.Style + [fsBold];          if i and 1 <> 0 then TTFS := TTFS + [fsItalic]; // new by jpt          if i and 2 <> 0 then TTFS := TTFS + [fsBold]; // new by jpt          if chkUnderLine.Checked then F.Style := F.Style + [fsUnderline];          if chkStrike.Checked then F.Style := F.Style + [fsStrikeOut];          UpdateFont(F);            SaveSelection;          finally          F.Free;          end;        end;end;  Dont't forget : Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses  fpTTF;  // jpt for GetFontFile  For the fun, a missing line in RestoreSelection : Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i       ...    if i<>Sender.ItemIndex then Sender.ItemIndex := i;      Sender.TopIndex := Sender.ItemIndex // jpt, to display the selected line at power-up;    end;  end;end;  And now the problem : if I use fontenum without the changes for getting the full filename (= original fontenumeration), everything works fine. But if I setup things for retrieval of full filenames using fpTTF unit, some fonts (System-ui) hang program with SIGSEGV. Linux Debian 11.7 FPC 3.2.2 Laz 2.2.6 Step-by-step for debugging is not available in fpTTF.pp, I don't know why (works fine in mainunit.pas). AIRFOIL.TTF (in edtFullFileName.Text bottom image) is the first one in my fonts' folder. Any help welcome, thanks.