How to get a list of installed True Type Fonts on

2020-03-19 06:04发布

问题:

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:

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



回答2:

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]));
  }


回答3:

try a function called 'XListFonts'

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



回答4:

Not relevent but you can use fontmatrix shows all and there preview (yum -y install fontmatrix)



回答5:

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.)



回答6:

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.