Font.equals returns true for two Font.createFont() fonts from the same source

XMLWordPrintable

    • Type: Bug
    • Resolution: Unresolved
    • Priority: P4
    • 27
    • Affects Version/s: 7
    • Component/s: client-libs
    • 2d
    • generic
    • generic

      A bug in the method java.awt.Font.equals. Different fonts with a different font size with the same displayname are compare to equals. This is wrong.

          public static void main( String[] args ) throws Exception {
              Font font1 = Font.createFont( Font.TRUETYPE_FONT, new File( TestFontEquals.class.getResource( "font1.ttf" ).getPath() ) );
              Font font2 = Font.createFont( Font.TRUETYPE_FONT, new File( TestFontEquals.class.getResource( "font2.ttf" ).getPath() ) );
              // compare 2 different fonts with different size but same display name
              // expected is false but it is true
              System.out.println( font1.equals( font2 ) );
          }

      This bug produce some exception in font rendering if both fonts was used for rendering.

      Think the bug is in the class sun.font.PhysicalFont.equals. This method must also compare the field platName. This field contains the location of the font file.

      Not find any workaround. The problem occur with every Java version and every platform (Windows, Linux)

       

            Assignee:
            Philip Race
            Reporter:
            Ting-Yun Ingrid Yao (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: