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

getGlyphLogicalBounds now returns internal object reference

XMLWordPrintable

    • 2d
    • b26
    • x86
    • windows_xp



      Name: jk109818 Date: 09/03/2003


      FULL PRODUCT VERSION :
      java version "1.4.2"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-b28)
      Java HotSpot(TM) Client VM (build 1.4.2-b28, mixed mode)


      FULL OS VERSION :
      Microsoft Windows XP [Version 5.1.2600]
      SunOS 5.8 Generic_108528-15 sun4u sparc SUNW,Ultra-60



      A DESCRIPTION OF THE PROBLEM :
      GlyphVector's getGlyphLogicalBounds returns internal object reference. In the past a copy was returned.

      One can create a glyph vector, and then modify a specific glyph by calling setGlyphPosition. The call to setGlyphPosition appears to leave the glyph's internal cache in an invalid state.

      A call to getGlyphLogicalBounds returns a GeneralPath which can then be manipulated, for instance by calling GeneralPath's transform method.

      Subsequent calls to getGlyphLogicalBounds will return a different value than the first invocation, since the internal reference has been modified.

      I think it is okay if getGlyphLogicalBounds returns a reference rather than a copy. However, the method's intended behavior, whether it returns a copy or internal reference, should be clearly described in the method's javadocs.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Release last known to work is j2sdk1.4.0

      Run program included in this report.



      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Output from jdk1.4.0

      First object ref java.awt.geom.GeneralPath@9efb05
      Before transform java.awt.geom.Rectangle2D$Float[x=0.0,y=-11.05957,w=6.673828,h=
      13.013672]
      Second object ref java.awt.geom.GeneralPath@8814e9
      After transform java.awt.geom.Rectangle2D$Float[x=0.0,y=-11.05957,w=6.673828,h=1
      3.013672]
      ACTUAL -
      Output from jdk1.4.1 and 1.4.2

      First object ref java.awt.geom.GeneralPath@1d5550d
      Before transform java.awt.geom.Rectangle2D$Float[x=0.0,y=-11.05957,w=6.673828,h=
      13.013672]
      Second object ref java.awt.geom.GeneralPath@1d5550d
      After transform java.awt.geom.Rectangle2D$Float[x=-14.374511,y=213.62721,w=12.28
      6541,h=14.607086]


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.Font;
      import java.awt.Shape;
      import java.awt.font.FontRenderContext;
      import java.awt.font.GlyphVector;
      import java.awt.geom.AffineTransform;
      import java.awt.geom.GeneralPath;
      import java.awt.geom.Point2D;


      public class GlyphLogicalBoundsTester {


          public static final void main(String [] args)
          {
              Font f = new Font("Arial", Font.PLAIN, 12);
              FontRenderContext frc = new FontRenderContext(null, true, true);
              String text = "a";

              GlyphVector gv = f.createGlyphVector(frc, text);

              // first reset the position of the glyph
              // this is necessary to get the observed behavior
              gv.setGlyphPosition(0, new Point2D.Double(0, 0));

              Shape shape = gv.getGlyphLogicalBounds(0);
              System.out.println("First object ref " + gv.getGlyphLogicalBounds(0));
              System.out.println("Before transform " + gv.getGlyphLogicalBounds(0).getBounds2D());
              AffineTransform at = new AffineTransform();
              at.rotate(Math.PI/6);
              at.translate(100, 200);
              ((GeneralPath)shape).transform(at);
              System.out.println("Second object ref " + gv.getGlyphLogicalBounds(0));
              System.out.println("After transform " + gv.getGlyphLogicalBounds(0).getBounds2D());

          }

      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Do not modify the returned reference. For instance one can call GeneralPath's createTransformedShape rather than transform.

      Release Regression From : 1.4.0_00
      The above release value was the last known release where this
      bug was known to work. Since then there has been a regression.

      (Incident Review ID: 191602)
      ======================================================================

            dougfelt Doug Felt (Inactive)
            jkimsunw Jeffrey Kim (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: