Skip to content

Commit

Permalink
fix font path issues
Browse files Browse the repository at this point in the history
  • Loading branch information
chompa111 committed Oct 16, 2022
1 parent c4265ef commit 7aeaff4
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/main/java/graphical/basics/gobject/Fonts.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
package graphical.basics.gobject;

import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Paths;
import java.util.Objects;

public class Fonts {
public static Font COMPUTER_MODERN_I;
public static Font COMPUTER_MODERN_L;
public static Font JETBRAINS_MONO;

static {
COMPUTER_MODERN_I = pathToFont("/fonts/cmunbi.ttf");
COMPUTER_MODERN_L = pathToFont("/fonts/cmunbl.ttf");
JETBRAINS_MONO = pathToFont("/fonts/JetBrainsMono-Regular.ttf");
}

private static Font pathToFont(String s) {
try {
;
COMPUTER_MODERN_I = Font.createFont(Font.TRUETYPE_FONT, Paths.get(Fonts.class.getResource("/fonts/cmunbi.ttf").toURI()).toFile());
COMPUTER_MODERN_L = Font.createFont(Font.TRUETYPE_FONT, Paths.get(Fonts.class.getResource("/fonts/cmunbl.ttf").toURI()).toFile());
JETBRAINS_MONO = Font.createFont(Font.TRUETYPE_FONT, Paths.get(Fonts.class.getResource("/fonts/JetBrainsMono-Regular.ttf").toURI()).toFile());
} catch (FontFormatException | URISyntaxException | IOException e) {
return Font.createFonts(Objects.requireNonNull(Fonts.class.getResourceAsStream("/fonts/cmunbi.ttf")))[0];
} catch (FontFormatException | IOException e) {
e.printStackTrace();
}
return null;
}
}

0 comments on commit 7aeaff4

Please sign in to comment.