Class Fonts


  • public final class Fonts
    extends java.lang.Object
    Provides static access to popular Windows fonts. The sizes of the font constants are specified in typographic points, approximately 1/72 of an inch.

    TODO: Consider changing the visibility of the package private methods to public. As an alternative we may provide a FontPolicy that can emulate the font choice on Windows XP/2000 and Windows Vista for different software resolutions (96dpi/120dpi) and desktop font size settings (Normal/Large/Extra Large).

    Since:
    2.0
    See Also:
    FontSet, FontSets, FontPolicy, FontPolicies
    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) static java.lang.String WINDOWS_DEFAULT_GUI_FONT_KEY
      The desktop property key used to lookup the DEFAULTGUI font.
      (package private) static java.lang.String WINDOWS_ICON_FONT_KEY
      The desktop property key used to lookup Windows' icon font.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private Fonts()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      private static boolean canDisplayLocalizedDisplayLanguage​(java.awt.Font font, java.util.Locale locale)
      Checks and answers if the given font can display the locale's localized display language, for example "English" for English, "Deutsch" for German, etc.
      static java.lang.Boolean canDisplayLocalizedText​(java.awt.Font font, java.util.Locale locale)
      Checks and answers whether the given font can display text that is localized for the specified locale.
      private static java.awt.Font getDefaultGUIFont()
      Looks up and returns the Windows defaultGUI font.
      private static java.awt.Font getDesktopFont​(java.lang.String fontName)
      Looks up and returns a font using the default toolkit's desktop properties.
      static java.awt.Font getWindowsControlFont()
      Looks up and returns the Windows control font.
      private static boolean localeHasLocalizedDisplayLanguage​(java.util.Locale locale)
      Checks and answers whether the locale's display language is available in a localized form, for example "Deutsch" for the German locale.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • WINDOWS_DEFAULT_GUI_FONT_KEY

        static final java.lang.String WINDOWS_DEFAULT_GUI_FONT_KEY
        The desktop property key used to lookup the DEFAULTGUI font. This font scales with the software resolution only but works in western and non-western Windows environments.
        See Also:
        getWindowsControlFont(), Constant Field Values
      • WINDOWS_ICON_FONT_KEY

        static final java.lang.String WINDOWS_ICON_FONT_KEY
        The desktop property key used to lookup Windows' icon font. This font scales with the software resolution and the desktop font size setting (Normal/Large/Extra Large). However, in some non-western Windows environments this font cannot display the locale's glyphs.

        Implementation Note: Windows uses the icon font to label icons in the Windows Explorer and other places. It seems to me that this works in non-western environments due to font chaining.

        See Also:
        getWindowsControlFont(), Constant Field Values
    • Constructor Detail

      • Fonts

        private Fonts()
    • Method Detail

      • getWindowsControlFont

        public static java.awt.Font getWindowsControlFont()
        Looks up and returns the Windows control font. Returns the Windows icon title font unless it is inappropriate for the Windows version, Java renderer, or locale.

        The icon title font scales with the resolution (96dpi, 101dpi, 120dpi, etc) and the desktop font size settings (normal, large, extra large). Older versions may return a poor font. Also, since Java 1.4 and Java 5 render the Windows Vista icon font Segoe UI poorly, we return the default GUI font in these environments.

        The last check is, if the icon font can display text in the default locale. Therefore we test if the locale's localized display name can be displayed by the icon font. For example, Tahoma can display "English", "Deutsch", but not the display name for "Chinese" in Chinese.

        Returns:
        the Windows control font
        Throws:
        java.lang.UnsupportedOperationException - on non-Windows platforms
      • getDefaultGUIFont

        private static java.awt.Font getDefaultGUIFont()
        Looks up and returns the Windows defaultGUI font. Works around a bug with Java 1.4.2_11, 1.5.0_07, and 1.6 b89 in the Vista Beta2, where the win.defaultGUI.font desktop property returns null. In this case a logical "Dialog" font is used as fallback.
        Returns:
        the Windows defaultGUI font, or a dialog font as fallback.
      • canDisplayLocalizedText

        public static java.lang.Boolean canDisplayLocalizedText​(java.awt.Font font,
                                                                java.util.Locale locale)
        Checks and answers whether the given font can display text that is localized for the specified locale. Returns null if we can't test it.

        First checks, if the locale's display language is available in localized form, for example "Deutsch" for the German locale. If so, we check if the given font can display the localized display language.

        Otherwise we check some known combinations of fonts and locales and return the associated results. For all other combinations, null is returned to indicate that we don't know whether the font can display text in the given locale.

        Parameters:
        font - the font to be tested
        locale - the locale to be used
        Returns:
        Boolean.TRUE if the font can display the locale's text, Boolean.FALSE if not, null if we don't know
        Since:
        2.0.4
      • canDisplayLocalizedDisplayLanguage

        private static boolean canDisplayLocalizedDisplayLanguage​(java.awt.Font font,
                                                                  java.util.Locale locale)
        Checks and answers if the given font can display the locale's localized display language, for example "English" for English, "Deutsch" for German, etc. The test invokes Font#canDisplayUpTo on the localized display language. In a Chinese locale this test will check if the font can display Chinese glyphs.
        Parameters:
        font - the font to be tested
        locale - the locale to be used
        Returns:
        true if the font can display the locale's localized display language, false otherwise
      • localeHasLocalizedDisplayLanguage

        private static boolean localeHasLocalizedDisplayLanguage​(java.util.Locale locale)
        Checks and answers whether the locale's display language is available in a localized form, for example "Deutsch" for the German locale.
        Parameters:
        locale - the Locale to test
        Returns:
        true if the display language is localized, false if not
      • getDesktopFont

        private static java.awt.Font getDesktopFont​(java.lang.String fontName)
        Looks up and returns a font using the default toolkit's desktop properties.
        Parameters:
        fontName - the name of the font to return
        Returns:
        the font