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

java.awt.Font.decode: incorrectly determines family name

    XMLWordPrintable

    Details

    • Subcomponent:
      2d
    • Resolved In Build:
      b38
    • CPU:
      generic, sparc
    • OS:
      solaris_2.6, solaris_8
    • Verification:
      Verified

      Description



      Name: sdR10048 Date: 12/20/2003


      Filed By : SPB JCK team (###@###.###)
      JDK : java full version "1.5.0-beta-b31"
      JCK : 1.5
      Platform[s] : Solaris
      switch/Mode :
      JCK test owner : http://javaweb.eng/jct/sqe/JCK-tck/usr/owners.jto
      Failing Test [s] :
      api/java_awt/Font/descriptions.html#Decode[Font1002]
      api/java_awt/Font/descriptions.html#GetFont[Font1003]
      (Updated version of these testcases will be in master ws soon)

      Specification excerpt:
      ======================
      --------- J2SE API spec v.1.5 ---------
      ...
      public static Font decode(String str)

      Returns the Font that the str argument describes. To ensure that this method returns
      the desired Font, format the str parameter in one of two ways:

      "fontfamilyname-style-pointsize" or
      "fontfamilyname style pointsize"

      in which style is one of the three case-insensitive strings: "BOLD", "BOLDITALIC",
      or "ITALIC", and pointsize is a decimal representation of the point size.
      For example, if you want a font that is Arial, bold, and a point size of 18, you would
      call this method with: "Arial-BOLD-18".

      The default size is 12 and the default style is PLAIN. If you don't specify a valid size,
      the returned Font has a size of 12. If you don't specify a valid style, the returned Font
      has a style of PLAIN. If you do not provide a valid font family name in the str argument,
      this method still returns a valid font with a family name of "dialog". To determine what
      font family names are available on your system, use the GraphicsEnvironment.
      getAvailableFontFamilyNames() method. If str is null, a new Font is returned with
      the family name "dialog", a size of 12 and a PLAIN style. If str is null, a new Font is
      returned with the name "dialog", a size of 12 and a PLAIN style.

      Parameters:
          str - the name of the font, or null

      Returns:
          the Font object that str describes, or a new default Font if str is null.

      ...
      ---------- end-of-excerpt ---------------

      Problem description
      ===================
      The designated method incorrectly determines font family name
      in case this family name (specified in str parameter) does contain
      separator chars (" " or "-") and no style and no size is specified.
      See demo.

      In demo output you can see that only case #3 gets the correct result.
      All other cases show wrong decode(String) behaviour.

      In case this is an expected behaviour then that should be specified in javadoc
      explicitly. Please refer to "Requirements for Writing Java API Specifications"
      (http://java.sun.com/j2se/javadoc/writingapispecs/index.html#method)

          
      Minimized test:
      ===============
      ------- J.java -------
      import java.awt.*;

      public class J {
          public static void main(String[] args) {

              String minusFamily = null;
              String spaceFamily = null;

              // get all available font family names
              String familyNames[] =
                  GraphicsEnvironment.getLocalGraphicsEnvironment()
                  .getAvailableFontFamilyNames();

              // find font family names with "-" and " " in its names
              for (int i=0; i<familyNames.length; i++) {
                  if ( familyNames[i].contains("-") ) {
                      minusFamily = familyNames[i];
                  }
                  if ( familyNames[i].contains(" ") ) {
                      spaceFamily = familyNames[i];
                  }
              }

              String str = null;

              if ( minusFamily != null ) {
                  str = minusFamily+"--";
                  System.out.println( " -1- ");
                  System.out.println( "string: [" + str + "]");
                  System.out.println( Font.decode(str) );

                  str = minusFamily+" ";
                  System.out.println( " -2- ");
                  System.out.println( "string: [" + str + "]");
                  System.out.println( Font.decode(str) );
              }

              if ( spaceFamily != null ) {
                  str = spaceFamily+"--";
                  System.out.println( " -3- ");
                  System.out.println( "string: [" + str + "]");
                  System.out.println( Font.decode(str) );

                  str = spaceFamily+" ";
                  System.out.println( " -4- ");
                  System.out.println( "string: [" + str + "]");
                  System.out.println( Font.decode(str) );
              }
          }
      }

      ------- end-of-J.java -------

      Minimized test output:
      ======================
      ] java -showversion J
      java version "1.5.0-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b31)
      Java HotSpot(TM) Server VM (build 1.5.0-beta-b31, mixed mode)

       -1-
      string: [HG-GothicB-Sun--]
      java.awt.Font[family=Dialog,name=HG,style=plain,size=12]
       -2-
      string: [HG-GothicB-Sun ]
      java.awt.Font[family=Dialog,name=HG,style=plain,size=12]
       -3-
      string: [Times NR Latin Eight--]
      java.awt.Font[family=Times NR Latin Eight,name=Times NR Latin Eight,style=plain,size=12]
       -4-
      string: [Times NR Latin Eight ]
      java.awt.Font[family=Times,name=Times,style=plain,size=12]


      JCK test source location:
      ==========================
      /java/re/jck/1.5/promoted/latest/JCK-runtime-15/tests

      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              prr Philip Race
              Reporter:
              dsvsunw Dsv Dsv (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: