[OpenJDK 2D-Dev] openjdk incompatibility

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


Hi,

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?

Thanks,
Hiroshi


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
File(PATH_TO_FONT)).deriveFont(62f);

    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);
    lineMeasurer.setPosition(paragraph.getBeginIndex());
    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 {
    testLineMeasurerBounds();
  }

}



More information about the 2d-dev mailing list