tags:

views:

406

answers:

2

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.

+1  A: 

Try Font.createFont() and bundling the fonts you want to use.

Bombe
Well, that helped a bit, but apparently I'm still stuck with having to get the resultant font into the getAllFonts() call somehow, for the third-party library we're using.
skiphoppy
+1  A: 

Use GraphicsEnvironment.registerFont. (For JDK 1.6)

asalamon74
Awesome. That's the right answer to this problem. Except I'm stuck on Java 1.5, and we can't upgrade till next year when we fix a few issues our software has with 1.6! But thank you!
skiphoppy