我怎样才能让任意字体文件可用于Java? [英] How can I make arbitrary font files available to Java?

查看:149
本文介绍了我怎样才能让任意字体文件可用于Java?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用通过GraphicsEnvironment:getAllFonts()调用来访问字体的第三方库。这包括属于JRE和操作系统的字体注册表中的字体。

但是在连接到我们服务器的客户端机器上,我可能无法将字体安装到这些地点之一。那么我怎样才能让其他字体可供JRE使用,以便这个调用可以接收它们呢?有没有办法扩大其搜索路径?

我可以从Font.createFont()调用任意文件访问字体。但是,它仍然不会显示在GraphicsEnvironment.getAllFonts()中。有没有一种方法,我可以通过该字体,将其添加到可用的字体列表?我正在阅读有来自系统属性访问字体的调用,但我仍然不明白,而且我认为只是将我设置的字体属性从可用列表中转换为字体名称。






asalamon提供了正确的答案,但我坚持不支持Java的早期版本,至少直到明年。所以更多的答案仍然非常受欢迎!我可能会尝试使用反射来破解我们正在使用的库,并将字体直接插入到缓存中。

使用 GraphicsEnvironment。 registerFont 。 (对于JDK 1.6)


I'm using a third-party library which accesses fonts through the GraphicsEnvironment: getAllFonts() call. This includes fonts in font registries belonging to both the JRE and the operating system.

But on client machines that connect to our server I will likely not be able to install fonts into either of these locations. So how can I make other fonts available to the JRE so that this call will pick them up? Is there a way to expand its search path?

I can access a font from an arbitrary file with the Font.createFont() call. But then it still doesn't show up in GraphicsEnvironment.getAllFonts(). Is there a method I can pass that Font to that will add it to the list of fonts available? I'm reading that there are calls that access fonts from a system property, but I'm still not understanding, yet, and I think that just translates a font property I set up into a font name from the available list.


asalamon has provided the correct answer, but I'm stuck on an earlier version of Java that doesn't support it, at least until next year. So more answers are still very welcome! I'm probably going to try to use reflection to hack the library we are using and insert fonts directly into its cache.

解决方案

Use GraphicsEnvironment.registerFont. (For JDK 1.6)

这篇关于我怎样才能让任意字体文件可用于Java?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆