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

javafx.scene.text.Font broken for families with more weights than Regular & Bold; especially on Mac

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 8u11
    • javafx
    • Oracle Java & JavaFX version 8.0.11.
      Mac OS X Mavericks (10.9.4) and Yosemite Public Beta 1
      Ubuntu Linux x86_64 14.04.1

      If a font family only has fonts Regular, Italic, Bold, Bold Italic, or fewer, everything seems to work as you'd expect.

      Some font families have more weights than this. This seems to be expected in the javafx.scene.text.FontWeight enum. However, with such families, strange things happen, and different things on OSX and Linux.

      Linux behaviour seems broken as well, but at least in such a way that all the fonts are ultimately selectable. On Mac, you just can't get at most of the font weights, including the regular one, for such font families.

      Example: Install Adobe's "Source Code Pro" font family into a Linux and a Mac system. A user install is fine (ie: on Linux, just dropping them into ~/.fonts, on Mac, by using Font Book)

      This font family has the weights: Regular, ExtraLight, Light, Medium, Black, Bold, Semibold. Worth remembering in relation to the FontWeight enum. (There are no italics in this family.)

      On Mac, Font.getFamilies() (|grep "Source Code Pro") returns:

       * Source Code Pro

      On Linux, the same call returns:

       * Source Code Pro
       * Source Code Pro Black
       * Source Code Pro ExtraLight
       * Source Code Pro Light
       * Source Code Pro Medium
       * Source Code Pro Semibold

      On Mac, Font.getFontNames("SourceCodePro") returns:

       * Source Code Pro Black
       * Source Code Pro ExtraLight
       * Source Code Pro Semibold
       * Source Code Pro Light
       * Source Code Pro Medium
       * Source Code Pro Bold
       * Source Code Pro

      On Linux, the same call returns:

       * Source Code Pro
       * Source Code Pro Bold

      It looks like the Mac is doing the more logical thing, presenting one family with all the weights in it; whereas on Linux only Bold is recognised as a Weight, and all the others are interpreted as font families in their own right.

      Now try to just select the base font. On the Mac:

      Font.font("Source Code Pro")
       * Font[name=Source Code Pro Black, family=Source Code Pro Black, style=Regular, size=13.0]

      And on Linux:

      Font.font("Source Code Pro")
       * Font[name=Source Code Pro, family=Source Code Pro, style=Regular, size=13.0]

      However, while on Linux, an automatically generated font picker dialogue, or code that understand that this is happening, can ultimately use this to pick the desired weight, eg:

      Font.font("Source Code Pro Light")
       * Font[name=Source Code Pro Light, family=Source Code Pro Light, style=Regular, size=13.0]

      the same call would fail on the Mac, because "Source Code Pro Light" is not a family name, and you end up with the system font:

      Font.font("Source Code Pro Light")
       * Font[name=System Regular, family=System, style=Regular, size=13.0]

      Meanwhile, actually iterating through the FontWeight enum on the Mac gets you:

       THIN
         = Font.font("Source Code Pro", FontWeight.THIN, 13))
         * Font[name=Source Code Pro Black, family=Source Code Pro Black, style=Regular, size=13.0]
       EXTRA_LIGHT
         = Font.font("Source Code Pro", FontWeight.EXTRA_LIGHT, 13))
         * Font[name=Source Code Pro Black, family=Source Code Pro Black, style=Regular, size=13.0]
       LIGHT
         = Font.font("Source Code Pro", FontWeight.LIGHT, 13))
         * Font[name=Source Code Pro Black, family=Source Code Pro Black, style=Regular, size=13.0]
       NORMAL
         = Font.font("Source Code Pro", FontWeight.NORMAL, 13))
         * Font[name=Source Code Pro Black, family=Source Code Pro Black, style=Regular, size=13.0]
       MEDIUM
         = Font.font("Source Code Pro", FontWeight.MEDIUM, 13))
         * Font[name=Source Code Pro Black, family=Source Code Pro Black, style=Regular, size=13.0]
       SEMI_BOLD
         = Font.font("Source Code Pro", FontWeight.SEMI_BOLD, 13))
         * Font[name=Source Code Pro Black, family=Source Code Pro Black, style=Regular, size=13.0]
       BOLD
         = Font.font("Source Code Pro", FontWeight.BOLD, 13))
         * Font[name=Source Code Pro Bold, family=Source Code Pro, style=Bold, size=13.0]
       EXTRA_BOLD
         = Font.font("Source Code Pro", FontWeight.EXTRA_BOLD, 13))
         * Font[name=Source Code Pro Bold, family=Source Code Pro, style=Bold, size=13.0]
       BLACK
         = Font.font("Source Code Pro", FontWeight.BLACK, 13))
         * Font[name=Source Code Pro Bold, family=Source Code Pro, style=Bold, size=13.0]

      That is, only BOLD, EXTRA_BOLD and BLACK are matched to the Bold face; and *everything* else ends up - defaulting rather than matching I think - to Black. It's particularly ironic that FontWeight.BLACK is one of the few weights that *don't* get matched to Black...

      Meanwhile the same iteration on Linux also fails, although rather more explicably as we already know it's interpreted all the non-regular non-bold weights as separate families. In this case everything gets matced to Regular except, again, BOLD, EXTRA_BOLD and BLACK, which get matched to Bold:

       THIN
         = Font.font("Source Code Pro", FontWeight.THIN, 13))
         * Font[name=Source Code Pro, family=Source Code Pro, style=Regular, size=13.0]
       EXTRA_LIGHT
         = Font.font("Source Code Pro", FontWeight.EXTRA_LIGHT, 13))
         * Font[name=Source Code Pro, family=Source Code Pro, style=Regular, size=13.0]
       LIGHT
         = Font.font("Source Code Pro", FontWeight.LIGHT, 13))
         * Font[name=Source Code Pro, family=Source Code Pro, style=Regular, size=13.0]
       NORMAL
         = Font.font("Source Code Pro", FontWeight.NORMAL, 13))
         * Font[name=Source Code Pro, family=Source Code Pro, style=Regular, size=13.0]
       MEDIUM
         = Font.font("Source Code Pro", FontWeight.MEDIUM, 13))
         * Font[name=Source Code Pro, family=Source Code Pro, style=Regular, size=13.0]
       SEMI_BOLD
         = Font.font("Source Code Pro", FontWeight.SEMI_BOLD, 13))
         * Font[name=Source Code Pro, family=Source Code Pro, style=Regular, size=13.0]
       BOLD
         = Font.font("Source Code Pro", FontWeight.BOLD, 13))
         * Font[name=Source Code Pro Bold, family=Source Code Pro, style=Bold, size=13.0]
       EXTRA_BOLD
         = Font.font("Source Code Pro", FontWeight.EXTRA_BOLD, 13))
         * Font[name=Source Code Pro Bold, family=Source Code Pro, style=Bold, size=13.0]
       BLACK
         = Font.font("Source Code Pro", FontWeight.BLACK, 13))
         * Font[name=Source Code Pro Bold, family=Source Code Pro, style=Bold, size=13.0]

      Also repeatable with other fonts with more than the basic weights, eg: Gill Sans and Baskerville on Mac.

            prr Philip Race
            rgreenhamjfx Rachel Greenham (Inactive)
            Votes:
            3 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Imported: