- java.lang.Object
-
- org.controlsfx.glyphfont.GlyphFont
-
- Direct Known Subclasses:
FontAwesome
public class GlyphFont extends Object
Represents a glyph font, which can be loaded locally or from a specified URL.Glyph
s can be created easily using specified character defined in the font. For example, \uf013 in FontAwesome is used to represent a gear icon.To simplify glyph customization, methods can be chained, for example:
Glyph glyph = fontAwesome.create('\uf013').size(28).color(Color.RED); //GEAR
Here's a screenshot of two font packs being used to render images into JavaFX Button controls:
-
-
Constructor Summary
Constructors Constructor Description GlyphFont(String fontName, int defaultSize, InputStream in)
Loads glyph font from specifiedInputStream
GlyphFont(String fontName, int defaultSize, InputStream in, boolean lazyLoad)
Loads glyph font from specifiedInputStream
GlyphFont(String fontName, int defaultSize, String urlStr)
Load glyph font from specified URL.GlyphFont(String fontName, int defaultSize, String urlStr, boolean lazyLoad)
Load glyph font from specified URL.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Glyph
create(char character)
Creates an instance ofGlyph
using specified font characterGlyph
create(Enum<?> glyph)
Creates an instance ofGlyph
using a known Glyph enum valueGlyph
create(String glyphName)
Creates an instance ofGlyph
using glyph nameCharacter
getCharacter(String glyphName)
Returns the character code which is mapped to this Name.double
getDefaultSize()
Returns the default font sizeString
getName()
Returns font namevoid
register(String name, Character character)
Registers the given name-character mappingvoid
registerAll(Iterable<? extends INamedCharacter> namedCharacters)
Registers all given characters with their name.
-
-
-
Constructor Detail
-
GlyphFont
public GlyphFont(String fontName, int defaultSize, InputStream in)
Loads glyph font from specifiedInputStream
- Parameters:
fontName
- glyph font namedefaultSize
- default font sizein
- input stream to load the font from
-
GlyphFont
public GlyphFont(String fontName, int defaultSize, String urlStr)
Load glyph font from specified URL. Example for a local file: "file:///C:/Users/Bob/Fonts/icomoon.ttf" "file:///Users/Bob/Fonts/icomoon.ttf"- Parameters:
fontName
- glyph font namedefaultSize
- default font sizeurlStr
- A URL to load the font from
-
GlyphFont
public GlyphFont(String fontName, int defaultSize, InputStream in, boolean lazyLoad)
Loads glyph font from specifiedInputStream
- Parameters:
fontName
- glyph font namedefaultSize
- default font sizein
- input stream to load the font fromlazyLoad
- If true, the font will only be loaded when accessed
-
GlyphFont
public GlyphFont(String fontName, int defaultSize, String urlStr, boolean lazyLoad)
Load glyph font from specified URL. Example for a local file: "file:///C:/Users/Bob/Fonts/icomoon.ttf" "file:///Users/Bob/Fonts/icomoon.ttf"- Parameters:
fontName
- glyph font namedefaultSize
- default font sizeurlStr
- A URL to load the font fromlazyLoad
- If true, the font will only be loaded when accessed
-
-
Method Detail
-
getName
public String getName()
Returns font name- Returns:
- font name
-
getDefaultSize
public double getDefaultSize()
Returns the default font size- Returns:
- default font size
-
create
public Glyph create(char character)
Creates an instance ofGlyph
using specified font character- Parameters:
character
- font character- Returns:
- instance of
Glyph
-
create
public Glyph create(String glyphName)
Creates an instance ofGlyph
using glyph name- Parameters:
glyphName
- glyph name- Returns:
- glyph by its name or null if name is not found
-
create
public Glyph create(Enum<?> glyph)
Creates an instance ofGlyph
using a known Glyph enum value- Parameters:
glyph
-
-
getCharacter
public Character getCharacter(String glyphName)
Returns the character code which is mapped to this Name. If no match is found, NULL is returned.- Parameters:
glyphName
-
-
registerAll
public void registerAll(Iterable<? extends INamedCharacter> namedCharacters)
Registers all given characters with their name.- Parameters:
namedCharacters
-
-
-