我必须使用字体路径吗?

Must I use path to fonts?

FT_New_Face 函数似乎是我要找的函数,但它需要字体文件的路径。我想在不提供路径的情况下打开 "Times New Roman," 之类的字体。我该怎么做?

大多数基于 unix 的系统使用 Fontconfig 来从一组搜索参数(家族名称、变体、重量等)中获得最匹配的字体文件

Fontconfig is a library for configuring and customizing font access.

Fontconfig can:

  • discover new fonts when installed automatically, removing a common source of configuration problems.
  • perform font name substitution, so that appropriate alternative fonts can be selected if fonts are missing.
  • identify the set of fonts required to completely cover a set of languages.
  • have GUI configuration tools built as it uses an XML-based configuration file (though with autodiscovery, we believe this need is minimized).
  • efficiently and quickly find the fonts you need among the set of fonts you have installed, even if you have installed thousands of fonts, while minimzing memory usage.
  • be used in concert with the X Render Extension and FreeType to implement high quality, anti-aliased and subpixel rendered text on a display.

Fontconfig does not:

  • render the fonts themselves (this is left to FreeType or other rendering mechanisms)
  • depend on the X Window System in any fashion, so that printer only applications do not have such dependencies

Fontconfig 相对便携,可用于各种系统,但是 OSX 具有 CoreText which has similar functionality and Windows has DirectWrite

有关如何使用 Fontconfig 的帮助,请参阅 this 问题。