Package com.formdev.flatlaf.util
Class FontUtils
- java.lang.Object
-
- com.formdev.flatlaf.util.FontUtils
-
public class FontUtils extends Object
Utility methods for fonts.- Since:
- 3
-
-
Constructor Summary
Constructors Constructor Description FontUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Font[]
getAllFonts()
Returns all fonts available in the graphics environment.static String[]
getAvailableFontFamilyNames()
Returns all font familiy names available in the graphics environment.static Font
getCompositeFont(String family, int style, int size)
Gets a composite font for the given family, style and size.static boolean
installFont(URL url)
Loads a font file from the given url and registers it in the graphics environment.static void
loadFontFamily(String family)
Loads a font family previously registered viaregisterFontFamilyLoader(String, Runnable)
.static void
registerFontFamilyLoader(String family, Runnable loader)
Registers a font family for lazy loading vialoadFontFamily(String)
.
-
-
-
Method Detail
-
getCompositeFont
public static Font getCompositeFont(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 vialoadFontFamily(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(String family, Runnable loader)
Registers a font family for lazy loading vialoadFontFamily(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(String family)
Loads a font family previously registered viaregisterFontFamilyLoader(String, Runnable)
. If the family is already loaded or no londer is registered for that family, nothing happens.
-
installFont
public static boolean installFont(URL url)
Loads a font file from the given url and registers it in the graphics environment. UsesFont.createFont(int, InputStream)
andGraphicsEnvironment.registerFont(Font)
.
-
getAvailableFontFamilyNames
public static String[] getAvailableFontFamilyNames()
Returns all font familiy names available in the graphics environment. This invokesGraphicsEnvironment.getAvailableFontFamilyNames()
and appends families registered for lazy loading viaregisterFontFamilyLoader(String, Runnable)
to the result.
-
getAllFonts
public static Font[] getAllFonts()
Returns all fonts available in the graphics environment. This first loads all families registered for lazy loading viaregisterFontFamilyLoader(String, Runnable)
and then invokesGraphicsEnvironment.getAllFonts()
.
-
-