How can I make arbitrary font files available to Java?
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)
Try Font.createFont() and bundling the fonts you want to use.
精彩评论