独立于平台的字体定位方式
我正在开发一个 C 语言的多平台应用程序,我需要从磁盘加载字体并使用 FreeType 渲染消息。但是,我目前使用完整路径来定位字体,并且向用户询问字体的完整路径有点尴尬,因为它们通常深埋在系统文件夹中。
有没有一种简单的、独立于平台的方法来定位字体?例如,我可以期望用户能够提供类似“Sans”的内容,并有一个库或其他东西为我找到该字体的完整路径。我知道 fontconfig 的存在,但我发现很难浏览它的文档。
澄清:这是一个 CLI 驱动的应用程序,通过配置文件进行配置。
I'm working on a multi-platform application in C where I need to load fonts from disk and render messages with FreeType. However, I currently use full paths for locating fonts, and it's somewhat awkward to ask users for the full path of fonts since they are generally buried deep into system folders.
Is there a simple, platform-idependent way of just locating fonts? E.g. I can expect users to be able to provide something like "Sans" and have a library or something locate the full path of this font for me. I'm aware of the existence of fontconfig, but I found it quite hard to go through the documentation for it.
Clarification: This is a CLI driven application, which is configured through a config file.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
据我所知,
fontconfig
就是这样。继续查看文档,并找到一些教程。 这个 pdf 虽然有点旧,但很好地概述了 fontconfig 如何进行完成其非常有用的工作。As far as I am aware,
fontconfig
is the way. Keep at the docs, and find some tutorials. This pdf, while a little old, gives a very nice overview of how fontconfig does its amazingly useful job.您能够以独立于平台的方式获取该信息的唯一方法是拥有一个跨平台包来隐藏差异。它将为您提供一个平台中立的界面,并且本身会处理每个平台的复杂性。
The only way you could get that information in a platform-independent way is to have a cross-platform package that conceals the differences from you. It would provide you with a platform-neutral interface and would itself deal with the complexities of each platform.