我在系统上安装了一些 ttf 字体.
I have some ttf fonts installed on system.
我得到这个列表使用
GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames()
这不仅是 ttf 字体,而且是我猜的所有字体.最终,如果我使用:
This is not only ttf fonts but all fonts I guess. Eventually if I use:
Font.decode(fontName)
我可以得到 awt.Font 实例.
I can get awt.Font instance.
据我所知,Font 没有连接到实际的 PhysicalFont,所以如何从该列表或 awt.Font 中检索 ttf 字体文件或该 ttf 文件中的字体的字节数据?我正在尝试检索物理字体数据或类似的东西.该数据应该在正确的地方吗?
As far as I know Font is not connected to actual PhysicalFont, so how can I retrieve either ttf font file, or byte data from that ttf file for a font from that list or from awt.Font ? I am trying to retrieve a physical font data or anything similar. That data should be somewhere right?
我需要它的原因是最终与 libGDX 一起使用FreeTypeFontGenerator 以生成 BitmapFont
The reason I need it is to eventually use with libGDX FreeTypeFontGenerator in order to generate BitmapFont
这必须适用于 windows、osx 和 linux.
This has to work on windows, osx and linux.
正如@NateS 所指出的,看来我想要实现的目标并不完全可能.
As @NateS pointed out, it appears what I want to achieve is not exactly possible.
所以我现在只分享我在我的案例中使用的解决方案:
So I will just share the solution I used in my case for now:
这个类是什么:FontManager.java
这允许根据您的系统在已知系统位置预缓存现有的 ttf 文件,然后为 fontName->fontFile 类型的连接制作映射.然后进入首选项,并在下次运行时加载.
This allows to pre-cache existing ttf files in known system locations based on your system, and then make a Map for fontName->fontFile type of connection. this then goes to preferences, and is loaded on next run.
已知问题是
最好写一个原生库,但是时间很重要...
It would be ideal to write a native lib, but time is of an essence...
这篇关于如何从java中的系统字体中获取ttf字体数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!