Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 6761856
Votes 0
Synopsis OpenJDK: vertical text metrics may be significanly different from those returned by Sun JDK
Category java:classes_2d
Reported Against
Release Fixed 7(b43)
State 10-Fix Delivered, bug
Priority: 4-Low
Related Bugs
Submit Date 21-OCT-2008
Description
Following test returns:

Exception in thread "main" java.lang.RuntimeException: Not equal:
   <java.awt.geom.Rectangle2D$Float[x=5.78125,y=-47.796875,w=633.71484,h=57.515625]>
   <java.awt.geom.Rectangle2D$Float[x=5.78125,y=0.0,w=633.71484,h=96.34375]>
        at Test.testLineMeasurerBounds(Test.java:36)
        at Test.main(Test.java:41)


While some difference between OpenJDK and Sun JDK is expected due to different font rasterizers used
it should not be that large.

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();
  }

}
Posted Date : 2008-10-21 13:40:37.0
Work Around
N/A
Evaluation
Freetype and java uses different orientation of Y axis. 
Y coordinate was not correctly converted before returning text bounds.
Posted Date : 2008-10-28 23:01:55.0
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang