-
Notifications
You must be signed in to change notification settings - Fork 1
/
TTFRenameTest.java
executable file
·73 lines (64 loc) · 2.27 KB
/
TTFRenameTest.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
* #%L
* Evaluation
* %%
* Copyright (C) 2016 Github jjYBdx4IL Projects
* %%
* #L%
*/
package fr.opensagres.xdocreport.sfntly;
import com.google.typography.font.sfntly.Font;
import com.google.typography.font.sfntly.FontFactory;
import com.google.typography.font.sfntly.Tag;
import com.google.typography.font.sfntly.table.Table;
import com.google.typography.font.sfntly.table.core.NameTable;
import com.google.typography.font.sfntly.table.core.NameTable.NameEntry;
import com.google.typography.font.sfntly.table.core.NameTable.NameId;
import java.awt.FontFormatException;
import java.io.IOException;
import java.io.InputStream;
import static org.junit.Assert.*;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* https://github.com/googlei18n/sfntly/blob/master/java/test/com/google/typography/font/sfntly/testutils/TestFontUtils.java
*
* @author Github jjYBdx4IL Projects
*/
public class TTFRenameTest {
private static final Logger LOG = LoggerFactory.getLogger(TTFRenameTest.class);
static final String testFontPath = "/net/sf/jasperreports/fonts/dejavu/DejaVuSansMono.ttf";
@Test
public void testLoadFontFromResource() throws IOException, FontFormatException {
final java.awt.Font unchangedFont;
try (InputStream is = getClass().getResourceAsStream(testFontPath)) {
unchangedFont = java.awt.Font.createFont(java.awt.Font.PLAIN, is);
}
assertEquals("DejaVu Sans Mono", unchangedFont.getFontName());
FontFactory fontFactory = FontFactory.getInstance();
final Font[] fonts;
try (InputStream is = getClass().getResourceAsStream(testFontPath)) {
fonts = fontFactory.loadFonts(is);
}
assertEquals(1, fonts.length);
LOG.info(fonts[0].toString());
for (Integer key : fonts[0].tableMap().keySet()) {
Table t = fonts[0].getTable(key);
assertNotNull(t);
LOG.info("" + t);
LOG.info(Tag.stringValue(t.header().tag()));
}
NameTable name = (NameTable) fonts[0].getTable(Tag.name);
for (NameEntry entry : name) {
LOG.info(entry.toString());
if (NameId.valueOf(entry.nameId()).equals(NameId.FontFamilyName)) {
LOG.info("font family name is: " + entry.name());
}
}
// see
// https://github.com/googlei18n/sfntly/blob/master/java/test/com/google/typography/font/sfntly/NameEditingTests.java
// for more
// ...
}
}