Forum > LCL

Checking whether a certain font is installed or not

(1/1)

Leledumbo:
Any code snippets?

theo:

--- Quote from: Leledumbo on March 28, 2010, 09:06:37 am ---Any code snippets?

--- End quote ---

What do you mean exactly? If it's available to Lazarus?
You could basically check if the Name is in Screen.Fonts.
But this has some issues on GTK2. I have my own font-listing function. Tell me if it's this what you need.

And what do you need exactly as a result? Just Yes/No or do you need at least a similar or default font to work with?

Leledumbo:

--- Quote ---You could basically check if the Name is in Screen.Fonts
--- End quote ---
Aha, that's enough for me.

--- Quote ---But this has some issues on GTK2. I have my own font-listing function.
--- End quote ---
But it will be fixed in some time right? But it's worth seeing your function as well :D

theo:

--- Quote from: Leledumbo on March 29, 2010, 05:35:40 am ---But it's worth seeing your function as well

--- End quote ---

Here it is: http://www.theo.ch/lazarus/fontfinder.pas

I once wrote this for my own purpose (finding fonts from HTML-style lists).
Change it to suit you needs.
You will see, if it makes a difference to Screen.Fonts on your system (GTK2).

Try with this code:


--- Code: ---procedure TForm1.Button1Click(Sender:TObject);
var ff:TFontFinder;
begin
  Memo1.Lines.Assign(Screen.Fonts);
  fontfinder.EnumFonts(Memo2.Lines);
  ff:=TFontFinder.Create;
  Edit1.Text:=ff.FindAFontFromDelimitedString('Dummy, Arial, Helvetica, sans-serif');
  ff.free;
end;

--- End code ---

You see, that you can pass comma delimited lists of fonts (like HTML, CSS).
You will get the first that is found directly or by substring or via replacement list.
Probably not perfect but does the job for me.
You might want to get the fonts list only once in the intialization section, because it takes some time.

Navigation

[0] Message Index

Go to full version