Skip to content

Commit

Permalink
Re-added OpenSans font for compatible languages
Browse files Browse the repository at this point in the history
  • Loading branch information
Ninjabrain1 committed Dec 27, 2021
1 parent db25e74 commit 0eeb34d
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 7 deletions.
3 changes: 0 additions & 3 deletions src/ninjabrainbot/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
import ninjabrainbot.util.I18n;
import ninjabrainbot.util.Profiler;

import java.util.Arrays;
import java.util.Locale;

public class Main {

public static final String VERSION = "1.1.0";
Expand Down
26 changes: 23 additions & 3 deletions src/ninjabrainbot/gui/GUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import ninjabrainbot.gui.components.NinjabrainBotFrame;
import ninjabrainbot.gui.components.ThemedComponent;
import ninjabrainbot.io.VersionURL;
import ninjabrainbot.util.I18n;
import ninjabrainbot.util.Profiler;

/**
Expand Down Expand Up @@ -56,7 +57,8 @@ public class GUI {
private ArrayList<Throw> eyeThrows;
private ArrayList<Throw> eyeThrowsLast;

private final Font font;
private Font font;
private Font fontLight;

public GUI() {
theme = Theme.get(Main.preferences.theme.get());
Expand All @@ -71,7 +73,25 @@ public GUI() {
Profiler.start("Create frame");
frame = new NinjabrainBotFrame(this);
notificationsFrame = frame.getNotificationsFrame();


// Load fonts
Profiler.stopAndStart("Load fonts");
try {
font = Font.createFont(Font.TRUETYPE_FONT, Main.class.getResourceAsStream("/resources/OpenSans-Regular.ttf"));
if (font.canDisplayUpTo(I18n.get("lang")) != -1) {
font = new Font(null);
}
fontLight = Font.createFont(Font.TRUETYPE_FONT, Main.class.getResourceAsStream("/resources/OpenSans-Light.ttf"));
if (fontLight.canDisplayUpTo(I18n.get("lang")) != -1) {
fontLight = new Font(null);
}
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
ge.registerFont(font);
ge.registerFont(fontLight);
} catch (Exception e) {
e.printStackTrace();
}

// Set application icon
Profiler.stopAndStart("Set app icon");
URL iconURL = Main.class.getResource("/resources/icon.png");
Expand Down Expand Up @@ -161,7 +181,7 @@ public void setAngleErrorsEnabled(boolean b) {
}

public Font fontSize(float size, boolean light) {
return font.deriveFont(Font.BOLD, size);
return light ? fontLight.deriveFont(Font.BOLD, size) : font.deriveFont(Font.BOLD, size);
}

public void registerThemedComponent(ThemedComponent c) {
Expand Down
1 change: 0 additions & 1 deletion src/ninjabrainbot/util/I18n.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.StandardCharsets;
Expand Down
Binary file added src/resources/OpenSans-Light.ttf
Binary file not shown.
Binary file added src/resources/OpenSans-Regular.ttf
Binary file not shown.

0 comments on commit 0eeb34d

Please sign in to comment.