use of org.apache.fontbox.ttf.CmapSubtable in project pdfbox by apache.
the class PDTrueTypeFont method extractCmapTable.
/**
* extract all useful "cmap" subtables.
*/
private void extractCmapTable() throws IOException {
if (cmapInitialized) {
return;
}
CmapTable cmapTable = ttf.getCmap();
if (cmapTable != null) {
// get all relevant "cmap" subtables
CmapSubtable[] cmaps = cmapTable.getCmaps();
for (CmapSubtable cmap : cmaps) {
if (CmapTable.PLATFORM_WINDOWS == cmap.getPlatformId()) {
if (CmapTable.ENCODING_WIN_UNICODE_BMP == cmap.getPlatformEncodingId()) {
cmapWinUnicode = cmap;
} else if (CmapTable.ENCODING_WIN_SYMBOL == cmap.getPlatformEncodingId()) {
cmapWinSymbol = cmap;
}
} else if (CmapTable.PLATFORM_MACINTOSH == cmap.getPlatformId() && CmapTable.ENCODING_MAC_ROMAN == cmap.getPlatformEncodingId()) {
cmapMacRoman = cmap;
}
}
}
cmapInitialized = true;
}
use of org.apache.fontbox.ttf.CmapSubtable in project pdfbox by apache.
the class TestTTFParser method testPostTable.
/**
* Test the post table parser.
*
* @throws IOException if an error occurs.
*/
@Test
public void testPostTable() throws IOException {
InputStream input = TestTTFParser.class.getClassLoader().getResourceAsStream("org/apache/pdfbox/ttf/LiberationSans-Regular.ttf");
Assert.assertNotNull(input);
TTFParser parser = new TTFParser();
TrueTypeFont font = parser.parse(input);
CmapTable cmapTable = font.getCmap();
Assert.assertNotNull(cmapTable);
CmapSubtable[] cmaps = cmapTable.getCmaps();
Assert.assertNotNull(cmaps);
CmapSubtable cmap = null;
for (CmapSubtable e : cmaps) {
if (e.getPlatformId() == NameRecord.PLATFORM_WINDOWS && e.getPlatformEncodingId() == NameRecord.ENCODING_WINDOWS_UNICODE_BMP) {
cmap = e;
break;
}
}
Assert.assertNotNull(cmap);
PostScriptTable post = font.getPostScript();
Assert.assertNotNull(post);
String[] glyphNames = font.getPostScript().getGlyphNames();
Assert.assertNotNull(glyphNames);
// test a WGL4 (Macintosh standard) name
// TRADE MARK SIGN
int gid = cmap.getGlyphId(0x2122);
Assert.assertEquals("trademark", glyphNames[gid]);
// test an additional name
// EURO SIGN
gid = cmap.getGlyphId(0x20AC);
Assert.assertEquals("Euro", glyphNames[gid]);
}
Aggregations