From 7aeaff4e933c1443ff7d7c2ba44793596f7af554 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 16 Oct 2022 15:50:34 -0300 Subject: [PATCH] fix font path issues --- .../java/graphical/basics/gobject/Fonts.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/main/java/graphical/basics/gobject/Fonts.java b/src/main/java/graphical/basics/gobject/Fonts.java index 15ca194..f11c517 100644 --- a/src/main/java/graphical/basics/gobject/Fonts.java +++ b/src/main/java/graphical/basics/gobject/Fonts.java @@ -1,10 +1,8 @@ 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; @@ -12,13 +10,17 @@ public class Fonts { 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; } }