Created
November 23, 2021 10:38
-
-
Save ruimaranhao/fbadf0c1f687fed78751f09027c2ffac to your computer and use it in GitHub Desktop.
How to use another font in Laterna.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Application { | |
public static void main(String[] args) throws IOException, FontFormatException, URISyntaxException { | |
new Application().run(); | |
} | |
private void run() throws IOException, FontFormatException, URISyntaxException { | |
URL resource = getClass().getClassLoader().getResource("square.ttf"); | |
File fontFile = new File(resource.toURI()); | |
Font font = Font.createFont(Font.TRUETYPE_FONT, fontFile); | |
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); | |
ge.registerFont(font); | |
DefaultTerminalFactory factory = new DefaultTerminalFactory(); | |
Font loadedFont = font.deriveFont(Font.PLAIN, 25); | |
AWTTerminalFontConfiguration fontConfig = AWTTerminalFontConfiguration.newInstance(loadedFont); | |
factory.setTerminalEmulatorFontConfiguration(fontConfig); | |
factory.setForceAWTOverSwing(true); | |
factory.setInitialTerminalSize(new TerminalSize(40, 20)); | |
Terminal terminal = factory.createTerminal(); | |
((AWTTerminalFrame)terminal).addWindowListener(new WindowAdapter() { | |
@Override | |
public void windowClosing(WindowEvent e) { | |
e.getWindow().dispose(); | |
} | |
}); | |
Screen screen = new TerminalScreen(terminal); | |
screen.setCursorPosition(null); // we don't need a cursor | |
screen.startScreen(); // screens must be started | |
screen.doResizeIfNecessary(); // resize screen if necessary | |
screen.setCharacter(10, 10, TextCharacter.fromCharacter('C')[0]); | |
screen.refresh(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment