Forum > Unix
TFont Full path
winni:
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 [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---<!-- Font directory list --> <dir>/usr/share/fonts</dir> <dir>/usr/X11R6/lib/X11/fonts</dir> <dir>/opt/kde3/share/fonts</dir> <dir>/usr/local/share/fonts</dir> <dir prefix="xdg">fonts</dir> <!-- the following element will be removed in the future --> <dir>~/.fonts</dir>
As you see it is XML.
Keep on hacking!
Winni
alanphys:
Hi
You can use unit fpTTF in fcl-pdf.
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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é:
Hello,
--- Quote from: alanphys on July 09, 2020, 06:14:01 pm ---You can use unit fpTTF in fcl-pdf.
--- End quote ---
I tried to use your code in lazarus/examples/fontenum with a little change, like that :
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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 [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---uses fpTTF; // jpt for GetFontFile
For the fun, a missing line in RestoreSelection :
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- ... 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.
Navigation
[0] Message Index
[*] Previous page