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

Bounds of a shape generated from the outline of a GlyphSet not always correct

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P5 P5
    • 1.2.0
    • 1.2.0
    • client-libs
    • 2d
    • 1.2beta4
    • x86
    • windows_nt
    • Not verified



      Name: joT67522 Date: 01/14/98


      Below is code which indicates there may be a problem with
      the bounds returned for a shape that was generated
      from the Font.getOutline method for certain Glyphs.

      The code below gets the Bounds for two glyphs, the
      capital letter "A", and the square root symbol,
      Unicode 221A. It then draws a rectangle around the
      glyph by using the Shape.getBounds2D method to obtain
      the bounding rectangle.

      Running the sample program shows that the bounding
      box for "A" is correct, but for \u221A it is not, as the
      glyph protrudes outside of its bounds.

      This program was compiled and run on Window NT Server
      4.0 with JDK1.2beta2. The same effect has been observed
      with the Serif font as well as the SansSerif font.

      import java.awt.*;
      import java.awt.swing.*;
      import java.awt.geom.*;
      import java.awt.font.*;

      public class TestProgram extends JFrame{
      TestProgram(){
      getContentPane().add(new TestCanvas1());

      pack();
      setSize(600, 600);
      show();
      }

      public static void main(String argv[]){
      new TestProgram();
      }

      class TestCanvas1 extends Canvas{
      public void paint(Graphics g){
      GlyphSet gs;
      Shape glyph;
      Rectangle2D.Float glyphBounds;

      g.setColor(Color.white);
      g.fillRect(0, 0, getSize().width, getSize().height);

      Graphics2D g2=(Graphics2D)g;

      g2.setColor(Color.black);

      g2.transform(AffineTransform.getTranslateInstance(10, 60));
      Font f=new Font("SansSerif", Font.PLAIN, 20);
      g2.setFont(f);

      gs=f.getGlyphSet("A");
      glyph=f.getOutline(gs, AffineTransform.getScaleInstance(1, 1), 50, 0);
      glyphBounds=(Rectangle2D.Float)glyph.getBounds2D();
      g2.drawString("A", 50f, 0f);
      g2.draw(glyphBounds);

      String RootSymbol=new String("\u221A");
      gs=f.getGlyphSet(RootSymbol);
      glyph=f.getOutline(gs, AffineTransform.getScaleInstance(1, 1), 0, 0);
      glyphBounds=(Rectangle2D.Float)glyph.getBounds2D();
      g2.drawString(RootSymbol, 0f, 0f);
      g2.draw(glyphBounds);
      }
      }
      }
      (Review ID: 23173)
      ======================================================================

            jkaulorcl Jeet Kaul (Inactive)
            johsunw Joon Oh (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: