[OpenJDK 2D-Dev] openjdk incompatibility

Hiroshi Yamauchi yamauchi at google.com
Wed Oct 15 18:01:15 UTC 2008


Here's a test that indicates an incompatibility between OpenJDK6/7 and
Sun JDK. It passes on Sun JDK but not on OpenJDK. So, I believe this
is due to the difference between the two font rasterizer
implementations. The incompatibility causes a vertical position gap.

Is this a new bug, a known bug, or an implementation difference? Is
there a fix available?

If this isn't a bug, how would you suggest changing existing
applications that rely on the Sun JDK's behavior?


import java.awt.*;
import java.awt.font.*;
import java.awt.geom.*;
import java.text.*;
import java.io.File;

public class OpenJDKFontTest {

  // Copy this ttf file from the Sun JDK
  public static final String PATH_TO_FONT = "./LucidaSansRegular.ttf";
  public static final String TEST_CONTENT = "Beds, carriers, bowls,
leashes, snacks, and more.";

  public static void testLineMeasurerBounds() throws Exception {
    Font font = Font.createFont(Font.TRUETYPE_FONT, new

    AttributedString attributedString = new AttributedString(TEST_CONTENT);

    attributedString.addAttribute(TextAttribute.FONT, font);

    AttributedCharacterIterator paragraph = attributedString.getIterator();
    int paragraphEnd = paragraph.getEndIndex();

    FontRenderContext frc = new FontRenderContext(null, true, true);

    LineBreakMeasurer lineMeasurer = new LineBreakMeasurer(paragraph, frc);
    float desiredWidth = 882f;

    TextLayout layout = lineMeasurer.nextLayout(desiredWidth,
paragraphEnd, true);

    Rectangle2D textBox = layout.getBounds();

    Rectangle2D expected = new Rectangle2D.Float(5.78125f,
-47.796875f, 633.71484f, 57.515625f);

    if (!expected.equals(textBox)) {
      throw new RuntimeException("Not equal: <" + expected + "> <" +
textBox + ">");

  public static void main(String[] args) throws Exception {


More information about the 2d-dev mailing list