views:

450

answers:

2

I am trying to make IBM jre to use PCF fonts from default X11 installation on my linux box. In particular adobe-helvetica font. I have toyed to modify fontconfig.properties in jre/lib folder but no matter what I do Java seams to use some other fonts. I guess there is some algorithm how java VM tries to link java logical fonts to actual physical fonts in the system even in case when font specified in config could not be used. On Windows it is pretty straight forward, but on Linux I was unable to make it work with anything except TrueType fonts.
Anybody have experience with configuring fonts on IBM jre on Linux?

+1  A: 

I've spent all morning learning about Java fonts. There's a lot of limitations, some of which are removed in Java 1.6. I don't have any answers, but here is some information I have that might be helpful.

Java distinguishes internally between system fonts and created fonts. (News flash to Sun: it'd be nice to make that clear through subclassing!) The system fonts seem to be fonts installed in the JRE possibly plus some of the fonts installed on your system. But apparently not all of the fonts installed on your system; I, too, have adobe-helvetica on my Linux system but it doesn't seem to be accessible from Java under any name I can think of.

Meanwhile, you can create fonts from a font file with the Font.createFont() method. You have to specify the font file type. The only constants I found to specify these types in the Font class are TRUETYPE_FONT and TYPE1_FONT. So it looks like if PCF fonts are available, it isn't made explicit through providing a constant to specify them. Maybe somebody else knows more. I did see some information online about using bitmap fonts in Java ME, so it must somehow be possible to use other types of fonts.

Once you have a created font, you can add it to the JVM's concept of available fonts with the GraphicsEnvironment.registerFont() call, but that is only available on Java 1.6 and later.

skiphoppy
+1  A: 

The PCFFont package seems to provide the ability to use PCF fonts from Java. Unfortunately I think it does so with a custom PCFFont class which does not extend the java.awt.Font class, so I would say its usefulness is probably limited. However, it might give some pointers to implementation details for writing a custom subclass of Font which can handle PCF fonts. Finding the source code isn't immediately obvious; code for that exact class is here.

I would say the author seems a little confused, because he talks about converting TrueType fonts to PCF so you can use them with his library, and Java already supports TrueType fonts natively. But he appears to be an engineer from Sun, so maybe he knew more than I think; also, this could just be very out of date (was there ever a time when Java didn't support TrueType?).

skiphoppy
After All the research we made it seams like every version of JRE had dramatic under the hood changes for the font handling, and modern version does not support PCF fonts anymore. PCFFont project seams to be the only way to use PCF fonts, but it could not be easily injected into our project.
Ma99uS
In the end we decided to stick with the appropriate TTf font instead. So PCF fonts are out.
Ma99uS
Thanks for your comment though.
Ma99uS