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

FontMetrics not being properly serialized/deserialized on same machine and OS

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.4.0
    • 1.3.0_01
    • client-libs
    • 2d
    • beta
    • generic
    • generic



      Name: rmT116609 Date: 02/05/2001


      java version "1.3.0_01"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0_01)
      Java HotSpot(TM) Client VM (build 1.3.0_01, mixed mode)



      First of all, I am serializing and deserializing FontMetrics on the same machine
      and therefore the same OS. So this cannot be a duplicate of bug 4082048.
      import java.awt.*;

      public class FontMetricsSerialization {

              public FontMetricsSerialization() {
              }

          public void writeFontMetrics() throws Exception {
                      FontMetrics fm = new Panel().getFontMetrics( new Font( "Lucida Console", Font.PLAIN, 10 ) );
              System.out.println( "Height: " + fm.getHeight() );
              System.out.println( "Ascent: " + fm.getAscent() );
              System.out.println( "Descent: " + fm.getDescent() );
              System.out.println( "Font: " + fm.getFont() );
              FileOutputStream fileOut = new FileOutputStream( "font.ser" );
              ObjectOutputStream out = new ObjectOutputStream( fileOut );
              out.writeObject( fm );
              out.flush();
              out.close();
          }

          public void readFontMetrics() throws Exception {
              FileInputStream fileIn = new FileInputStream( "font.ser" );
              ObjectInputStream in = new ObjectInputStream( fileIn );
              FontMetrics fm = ( FontMetrics ) in.readObject();
              in.close();

              System.out.println( "Height: " + fm.getHeight() );
              System.out.println( "Ascent: " + fm.getAscent() );
              System.out.println( "Descent: " + fm.getDescent() );
              System.out.println( "Font: " + fm.getFont() );
          }

          public static void main( String args[] ) throws Exception {
              FontMetricsSerialization test = new FontMetricsSerialization();
              test.writeFontMetrics();
              test.readFontMetrics();
              System.exit(0);
              }
      }


      Here is the output with Sun's JDK 1.3.0:


      [jmsalvo@jsalvo-desktop test]$ /usr/local/jdk1.3.0_01-sun/bin/java -classpath
      classes/ FontMetricsSer
      ialization
      Height: 11
      Ascent: 8
      Descent: 3
      Font: java.awt.Font[family=Lucida Sans,name=Lucida Console,style=plain,size=10]
      Height: 0
      Ascent: 8
      Descent: 3
      Font: java.awt.Font[family=Lucida Sans,name=Lucida Console,style=plain,size=10]


      Note that getHeight() returns 0 after reading back from the file.

      Also note that using Sun's JDK 1.2.2, getHeight() returns the original value:

      [jmsalvo@jsalvo-desktop test]$ /usr/local/jdk1.2.2-sun/bin/java -classpath
      classes/ FontMetricsSerialization
      Height: 11
      Ascent: 8
      Descent: 3
      Font: java.awt.Font[family=Lucida Sans,name=Lucida Console,style=plain,size=10]
      Height: 11
      Ascent: 8
      Descent: 3
      Font: java.awt.Font[family=Lucida Sans,name=Lucida Console,style=plain,size=10]


      Why did it work with JDK 1.2.2, but not anymore with JDK 1.3.0?
      (Review ID: 116245)
      ======================================================================

            dougfelt Doug Felt (Inactive)
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: