Package com.formdev.flatlaf.util
Class FontUtils
- java.lang.Object
-
- com.formdev.flatlaf.util.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 viaregisterFontFamilyLoader(String, Runnable)
.static void
registerFontFamilyLoader(java.lang.String family, java.lang.Runnable loader)
Registers a font family for lazy loading vialoadFontFamily(String)
.
-
-
-
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 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(java.lang.String family, java.lang.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(java.lang.String family)
Loads a font family previously registered viaregisterFontFamilyLoader(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. UsesFont.createFont(int, InputStream)
andGraphicsEnvironment.registerFont(Font)
.
-
getAvailableFontFamilyNames
public static java.lang.String[] getAvailableFontFamilyNames()
Returns all font family 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 java.awt.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()
.
-
hasLoaders
private static boolean hasLoaders()
-
-