Skip to content

Commit

Permalink
Merge pull request #3122 from Windchild292/dev_Windchild_FullFontDire…
Browse files Browse the repository at this point in the history
…ctory

BLOCKER: Read the font directory for MHQ instead of ignoring it.
  • Loading branch information
Windchild292 authored Feb 17, 2022
2 parents a2b2531 + 2d6ffc2 commit 8044725
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions MekHQ/src/mekhq/MekHQ.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.List;

/**
Expand Down Expand Up @@ -160,6 +162,9 @@ protected void startup() {
UIManager.installLookAndFeel("Flat Dark", "com.formdev.flatlaf.FlatDarkLaf");
UIManager.installLookAndFeel("Flat Darcula", "com.formdev.flatlaf.FlatDarculaLaf");

// Handle fonts
parseFontDirectory(new File("data/fonts/"));

// Setup user preferences
MegaMek.getMMPreferences().loadFromFile(MHQConstants.MM_PREFERENCES_FILE);
MegaMekLab.getMMLPreferences().loadFromFile(MHQConstants.MML_PREFERENCES_FILE);
Expand All @@ -173,6 +178,29 @@ protected void startup() {
new StartupScreenPanel(this).getFrame().setVisible(true);
}

private static void parseFontDirectory(final File directory) {
final String[] filenames = directory.list();
if (filenames == null) {
return;
}

for (final String filename : filenames) {
if (filename.toLowerCase().endsWith(".ttf")) {
try (InputStream fis = new FileInputStream(directory.getPath() + '/' + filename)) {
GraphicsEnvironment.getLocalGraphicsEnvironment().registerFont(
Font.createFont(Font.TRUETYPE_FONT, fis));
} catch (Exception ex) {
LogManager.getLogger().error("Failed to parse font", ex);
}
} else {
final File file = new File(directory, filename);
if (file.isDirectory()) {
parseFontDirectory(file);
}
}
}
}

@Deprecated // These need to be migrated to the Suite Constants / Suite Options Setup
private void setUserPreferences() {
PreferencesNode preferences = getMHQPreferences().forClass(MekHQ.class);
Expand Down

0 comments on commit 8044725

Please sign in to comment.