Class FontUtils


  • public class FontUtils
    extends java.lang.Object
    Utility methods for fonts.
    Since:
    3
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.util.Map<java.lang.String,​java.lang.Runnable> loadersMap  
    • Constructor Summary

      Constructors 
      Constructor Description
      FontUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.awt.Font[] getAllFonts()
      Returns all fonts available in the graphics environment.
      static java.lang.String[] getAvailableFontFamilyNames()
      Returns all font family names available in the graphics environment.
      static java.awt.Font getCompositeFont​(java.lang.String family, int style, int size)
      Gets a composite font for the given family, style and size.
      private static boolean hasLoaders()  
      static boolean installFont​(java.net.URL url)
      Loads a font file from the given url and registers it in the graphics environment.
      static void loadFontFamily​(java.lang.String family)
      Loads a font family previously registered via registerFontFamilyLoader(String, Runnable).
      static void registerFontFamilyLoader​(java.lang.String family, java.lang.Runnable loader)
      Registers a font family for lazy loading via loadFontFamily(String).
      • Methods inherited from class java.lang.Object

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

      • loadersMap

        private static java.util.Map<java.lang.String,​java.lang.Runnable> loadersMap
    • Constructor Detail

      • FontUtils

        public FontUtils()
    • Method Detail

      • getCompositeFont

        public static java.awt.Font getCompositeFont​(java.lang.String family,
                                                     int style,
                                                     int size)
        Gets a composite font for the given family, style and size. A composite font that is able to display all Unicode characters. The font family is loaded if necessary via loadFontFamily(String).

        To get fonts derived from returned fonts, it is recommended to use one of the Font.deriveFont(int, float) methods instead of invoking this method.

      • registerFontFamilyLoader

        public static void registerFontFamilyLoader​(java.lang.String family,
                                                    java.lang.Runnable loader)
        Registers a font family for lazy loading via loadFontFamily(String).

        The given runnable is invoked when the given font family should be loaded. The runnable should invoke installFont(URL) to load and register font(s) for the family. A family may consist of up to four font files for the supported font styles: regular (plain), italic, bold and bold-italic.

      • loadFontFamily

        public static void loadFontFamily​(java.lang.String family)
        Loads a font family previously registered via registerFontFamilyLoader(String, Runnable). If the family is already loaded or no loader is registered for that family, nothing happens.
      • installFont

        public static boolean installFont​(java.net.URL url)
        Loads a font file from the given url and registers it in the graphics environment. Uses Font.createFont(int, InputStream) and GraphicsEnvironment.registerFont(Font).
      • getAvailableFontFamilyNames

        public static java.lang.String[] getAvailableFontFamilyNames()
        Returns all font family names available in the graphics environment. This invokes GraphicsEnvironment.getAvailableFontFamilyNames() and appends families registered for lazy loading via registerFontFamilyLoader(String, Runnable) to the result.
      • getAllFonts

        public static java.awt.Font[] getAllFonts()
        Returns all fonts available in the graphics environment. This first loads all families registered for lazy loading via registerFontFamilyLoader(String, Runnable) and then invokes GraphicsEnvironment.getAllFonts().
      • hasLoaders

        private static boolean hasLoaders()