Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6761856

OpenJDK: vertical text metrics may be significanly different from those returned by Sun JDK

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 7
    • 7
    • client-libs
    • None
    • 2d
    • b43
    • generic
    • generic

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

        }

              igor Igor Nekrestyanov (Inactive)
              igor Igor Nekrestyanov (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: