views:

1209

answers:

6

How can my app get a list of the True Type Fonts that are available on Linux.

Is there a standard directory where they are stored across different distributions? Or some other standard way to locate them?

+1  A: 

ask the X font server.

Tim Williscroft
I think in the most cases no font server is running.
Node
A: 

If you aren't writing proprietary software, or any other licensed software that's incompatible with GPL, you could try looking at the code to xlsfonts to see how to query the font server. (The font server could be X itself, but it won't matter.)

Tanktalus
+2  A: 

I think fontconfig is the right way to do it. Take a look on the wikipedia article or the fontconfig hompage.

quinmars
+1  A: 

try a function called 'XListFonts'

http://tronche.com/gui/x/xlib/graphics/font-metrics/XListFonts.html

A: 

If you're using a high-level toolkit like GTK+ or Qt, there's probably a better function to do it for you; if not, fontconfig is the de-facto way to do it.

Paul Betts
+1  A: 

I just did it using something called Pango which is used by GTK+. I found it by looking at the code for the linux 'Character Map' program (gucharmap). Here's the basic idea:

  PangoFontFamily **families;

  ...

  pango_context_list_families (
          gtk_widget_get_pango_context (GTK_WIDGET (notebook)),
          &families, &fontCount);

  printf("%d fonts found\n", fontCount);
  for(i=0; i<fontCount; i++)
  {
    printf("[%s]\n", pango_font_family_get_name (families[i]));
  }