How to get a list of installed True Type Fonts on

2020-03-19 06:20发布

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?

6条回答
不美不萌又怎样
2楼-- · 2020-03-19 06:35

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

查看更多
仙女界的扛把子
3楼-- · 2020-03-19 06:37

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

enter image description here

查看更多
The star\"
4楼-- · 2020-03-19 06:43

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

查看更多
老娘就宠你
5楼-- · 2020-03-19 06:48

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]));
  }
查看更多
趁早两清
7楼-- · 2020-03-19 06:56

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.

查看更多
登录 后发表回答