Quite simply. Fonts look terrible when using openjdk6 on FreeBSD. I’ve been spending quite a bit of time researching and fixing this issue.

This is a simple test program I put together for comparing fonts.

    import java.awt.*;
    import javax.swing.*;

    public class BasicDraw {
        public static void main(String[] args) {
            new BasicDraw();
        }
        BasicDraw() {
            // Create a frame
            JFrame frame = new JFrame();

            // Add a component with a custom paint method
            frame.getContentPane().add(new MyComponent());

            // Display the frame
            int frameWidth = 300;
            int frameHeight = 300;
            frame.setSize(frameWidth, frameHeight);
            frame.setVisible(true);
        }

        class MyComponent extends JComponent {
            // This method is called whenever the contents needs to be painted
            public void paint(Graphics g) {
                // Retrieve the graphics context; this object is used to paint shapes
                Graphics2D g2d = (Graphics2D)g;

                // Draw an oval that fills the window
                int x = 0;
                int y = 0;
                int width = getSize().width-1;
                int height = getSize().height-1;
                g2d.drawOval(x, y, width, height);

                // Set the desired font if different from default font

                String family = "Serif";
                int style = Font.PLAIN;
                int size = 12;
                Font font = new Font(family, style, size);
                g.setFont(font);

                // Draw a string such that its base line is at x, y
                x = 10;
                y = 10;
                g.drawString("aString", x, y);

                // Draw a string such that the top-left corner is at x, y
                x = 10;
                y = 30;
                FontMetrics fontMetrics = g.getFontMetrics();
                g.drawString("bString", x, y+fontMetrics.getAscent());
            }
        }

    }

When comparing the results of Openjdk6-b17 vs diablo-jdk-1.6.0.07.02_6, you’ll see a noticeable difference in the fonts being used. Openjdk6 looks terrible.

Here is another executable class that lists all available fonts on a machine:

import java.awt.GraphicsEnvironment;

public class AvailableFonts
{

	/**
	 * @param args
	 */
	public static void main(String[] args) {
	    GraphicsEnvironment gEnv = GraphicsEnvironment
        	.getLocalGraphicsEnvironment();
		String envfonts[] = gEnv.getAvailableFontFamilyNames();

		for (String font: envfonts) {
			System.err.println(font);
		}
	}

}

When comparing the output between openjdk and diablo-jdk, the only difference were these three lines in the diablo-jdk output:

Lucida Bright
Lucida Sans
Lucida Sans Typewriter

These fonts turned out to be .ttf font files located at /usr/local/diablo-jdk16/jre/lib/fonts/.

I performed the following command to link them inside openjdk6

ln -s /usr/local/diablo-jdk16/jre/lib/fonts/ /usr/local/openjdk6/jre/lib/fonts/

Now the AvailableFonts class returns identical results, however BasicDraw, doesn’t appear to render the text all together. Trying to run netbeans or eclipse, or any GUI/swing app for that matter causes even more unusual results. It looks as if the fonts are being drawn with a width of 0, and height 10 times their normal size.

I imported a couple of patches for bugs 6761856 and 6817112 from the jdk7 branch, to try and resolve this unusual behavior with no luck. I then started playing with fontconfig.properties, in hopes of resolving the font issues there. It looked like it wanted to use DejaVU LGC fonts as the primary for latin-1. I used the port x11-fonts/dejavu which contains the non LGC fonts since there DejaVU LGC fonts don’t appear to have a port yet. After installing the fonts and updating fontconfig.properties I re-ran my BasicDraw test class… and SUCCESS! Font’s looked equivalent to those in diablo-jdk and the best part is I don’t have to worry about licensing issues with Sun’s Lucida fonts.

I’ve added the following to the ports/java/openjdk6 Makefile:

RUN_DEPENDS+=	dejavu:${PORTSDIR}/x11-fonts/dejavu

I’d like to offer a better out-of-the-box installation to our japanese,chinese, and korean audience, but I’m not sure what the best way to do this is. So far this is what I’ve come up with as the ideal fonts for each locality:

korean = korean/unfonts-ttf
chinese = chinese/mingunittf
japanese = japanese/font-sazanami

I’ve updated the fontconfig.properties to reflect these fonts and their installed locations, however I’m not sure I’ve chosen the right fonts. Furthermore I’d like out-of-box font dependencies to be resolved based on the LOCALE of the machine. I haven’t found any examples of doing this, and I can only assume their is a reason for it. Perhaps the right thing to do is require all fonts for all languages regardless of the LOCALE?

My work so far has been included in pre release 2 and, you can grab the latest preliminary port from this blog:
http://www.getsnappy.com/tech-blog/freebsd-tips-tricks/upgrading-freebsd-port-java-openjdk6-from-b16-to-b17/

Any feedback good or bad, is appreciated.