-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTtfCharReader.java
More file actions
54 lines (45 loc) · 1.9 KB
/
TtfCharReader.java
File metadata and controls
54 lines (45 loc) · 1.9 KB
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
import java.awt.Font;
import java.awt.FontFormatException;
import java.awt.GraphicsEnvironment;
import java.io.File;
import java.io.IOException;
public class TtfCharReader {
public static void readCharactersFromTtf(String ttfFilePath) {
try {
// Resolve the file path
File ttfFile = new File(ttfFilePath);
if (!ttfFile.exists()) {
System.err.println("Error: File not found at " + ttfFile.getAbsolutePath());
return;
}
// Load the TTF file
Font font = Font.createFont(Font.TRUETYPE_FONT, ttfFile);
// Register the font with the graphics environment
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
ge.registerFont(font);
// Set the font size to a readable size
font = font.deriveFont(24f);
// Print basic information about the font
System.out.println("Font Name: " + font.getFontName());
System.out.println("Font Family: " + font.getFamily());
// Print all supported characters
System.out.println("Supported Characters:");
for (char c = 32; c < 256; c++) { // ASCII range for demonstration
if (font.canDisplay(c)) {
System.out.print(c + " ");
}
break;
}
System.out.println();
} catch (FontFormatException e) {
System.err.println("The file is not a valid TTF font: " + e.getMessage());
} catch (IOException e) {
System.err.println("Error reading the TTF file: " + e.getMessage());
}
}
public static void main(String[] args) {
// Use a relative path to the .ttf file
String ttfFilePath = "src/PonnalaRegular1.ttf"; // Adjust the file name if necessary
readCharactersFromTtf(ttfFilePath);
}
}