Skip to content

Instantly share code, notes, and snippets.

@samuelstein
Created October 23, 2018 09:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samuelstein/82e61f8e51c83bc2cfafc19808103da0 to your computer and use it in GitHub Desktop.
Save samuelstein/82e61f8e51c83bc2cfafc19808103da0 to your computer and use it in GitHub Desktop.
/**
* This is a wrapper class that registers the font awesome .ttf included in the package.
* ControlsFX loads this font dynamically at run time from a CDN. Thus, it works only if Internet
* connection is available
* .
* This class registers an included version of the font. The {@link #init()} method should be called
* during the initialization procedure of the application such that the font is available early.
*
* @author albrecht
*/
private static class FontAwesomeOffline {
private static final String fontLocation = "assets/fonts/fontawesome-webfont.ttf";
private static GlyphFont font;
private FontAwesomeOffline() {
// prevent instances
}
public static void init() {
InputStream input = FontAwesomeOffline.class.getClassLoader().getResourceAsStream(fontLocation);
if (input != null) {
font = new FontAwesome(input);
GlyphFontRegistry.register(font);
LOG.info("Using {} from local assets.", font.getName());
// Note: if we would close the input stream, icons would not be displayed anymore!
} else {
LOG.error("Could not initialize font awesome: " + fontLocation);
}
}
public static GlyphFont getGlyphFont() {
return font;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment