Hello,
You can use unit fpTTF in fcl-pdf.
I tried to use your code in lazarus/examples/fontenum with a little change, like that :
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 :
uses
fpTTF; // jpt for GetFontFile
For the fun, a missing line in RestoreSelection :
...
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.