Hi,
Im currently trying to develope a system which is required to be as portable as possible. In this system I would like to use different font styles, however I am not able to use native system fonts (as it needs to be portable). I know that there are a few true type fonts in java but I wanted something a little more interesting. Are there any fonts that are available in linux\ windows\ solaris and if not can I get custom fonts from anywhere and deploy them with the application (plus if so how)?
Any help with this would be grately appreciated, thanks in advance
Hi,
Im currently trying to develope a system which is
required to be as portable as possible. In this
system I would like to use different font styles,
however I am not able to use native system fonts (as
it needs to be portable).
True but also not true.
1. As you stated, there are the java generic fonts (ie sanserif, dialog, monospaced, etc) These you should be able to use fairly consistantly in your own code
2. You can provide users with a choice of any of their fonts using GraphicsEnvironment.getAllFontFaces() see http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Font.html
3. You could make fonts available to users, but automatically installing them is going to be a nightmare
Another thing you should know is that while the definition of point is 1/72nd of an inch (so a font that is 72 pt should be 1 inch tall) this is actually not true on most (all?) windows machines because of the resolution. If you really want something that looks the same on all platforms, you need to make a static font factory and modify font sizes according the the screen resolution (see Toolkit.getScreenResolution())
I'm not sure if there are any fonts that would be available across all platforms, however, you can allow the font type to be configured by the end user. The following link provides sample code to obtain a list of available fonts from the underlying system.
3. You could make fonts available to users, but automatically
installing them is going to be a nightmare
Not really.
Font f = Font.createFont(Font.TRUETYPE_FONT, new FileInputStream(new File("MyFont.ttf")));
or Class.getResourceAsStream() for font files packaged in your Jar files or otherwise in the classpath.
As long as you have TrueType fonts, you can ship then with your app. Keep in mind, that there are legal issues for font distribution... You'd have to check with whoever own the font copyright for that. But the technical issues are pretty minimal.
Thanks for all your advice, Im not too keen on allowing the users to select their font, but its a possiblity. I think ill have a go at bsampieri's suggestion,