United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6761856 OpenJDK: vertical text metrics may be significanly different from those returned by Sun JDK
JDK-6761856 : OpenJDK: vertical text metrics may be significanly different from those returned by Sun JDK

Details
Type:
Bug
Submit Date:
2008-10-21
Status:
Resolved
Updated Date:
2010-04-04
Project Name:
JDK
Resolved Date:
2009-01-09
Component:
client-libs
OS:
generic
Sub-Component:
2d
CPU:
generic
Priority:
P4
Resolution:
Fixed
Affected Versions:
7
Fixed Versions:

Related Reports
Backport:

Sub Tasks

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

}

                                    

Comments
SUGGESTED FIX

http://hg.openjdk.java.net/jdk7/jdk7/rev/9cdababf6179
                                     
2008-10-28
EVALUATION

Freetype and java uses different orientation of Y axis. 
Y coordinate was not correctly converted before returning text bounds.
                                     
2008-10-28



Hardware and Software, Engineered to Work Together