Recent

Author Topic: Checking whether a certain font is installed or not  (Read 6915 times)

Leledumbo

  • Hero Member
  • *****
  • Posts: 8436
  • Programming + Glam Metal + Tae Kwon Do = Me
Checking whether a certain font is installed or not
« on: March 28, 2010, 09:06:37 am »
Any code snippets?

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1891
Re: Checking whether a certain font is installed or not
« Reply #1 on: March 28, 2010, 11:45:43 am »
Any code snippets?

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?
« Last Edit: March 28, 2010, 11:59:50 am by theo »

Leledumbo

  • Hero Member
  • *****
  • Posts: 8436
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Checking whether a certain font is installed or not
« Reply #2 on: March 29, 2010, 05:35:40 am »
Quote
You could basically check if the Name is in Screen.Fonts
Aha, that's enough for me.
Quote
But this has some issues on GTK2. I have my own font-listing function.
But it will be fixed in some time right? But it's worth seeing your function as well :D

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1891
Re: Checking whether a certain font is installed or not
« Reply #3 on: March 29, 2010, 11:56:05 am »
But it's worth seeing your function as well

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: [Select]
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;

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.
« Last Edit: March 29, 2010, 12:06:42 pm by theo »

 

TinyPortal © 2005-2018