-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathFontHandler.java
58 lines (48 loc) · 1.42 KB
/
FontHandler.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import fallk.logmaster.HLogger;
import java.awt.*;
import java.io.File;
import java.io.IOException;
/**
* Manages fonts
*
* @author Kaffeinated
*/
class FontHandler {
/**
* global replacement for ftm
*/
public static FontMetrics fMetrics;
/**
* path used to look for fonts
*/
private static final String fontPath = "data/fonts/";
public FontHandler() {
loadFonts();
HLogger.info("Done loading fonts!");
}
private void loadFonts() {
try {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, new File(fontPath + "OpenSans-Bold.ttf")));
/*
* how to do it
* 0. place ttf, otf, whatever, inside your data/fonts folder
* 1. place font name
* 2. done
*/
//ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, this.getClass().getResourceAsStream(fontPath + "font name")));
/*
* print out all the fonts that are usable by java in your environment
*/
/*Font[] fonts = ge.getAllFonts();
for (int i = 0; i < fonts.length; i++) {
HLogger.info(fonts[i].getFontName() + " : ");
HLogger.info(fonts[i].getFamily() + " : ");
HLogger.info(fonts[i].getName());
}*/
} catch (FontFormatException | IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}