Search in sources :

Example 1 with CmapSubtable

use of com.tom_roush.fontbox.ttf.CmapSubtable in project PdfBox-Android by TomRoush.

the class TestTTFParser method testPostTable.

/**
 * Test the post table parser.
 *
 * @throws IOException if an error occurs.
 */
@Test
public void testPostTable() throws IOException {
    InputStream input = PDFont.class.getResourceAsStream("/com/tom_roush/pdfbox/resources/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]);
}
Also used : TrueTypeFont(com.tom_roush.fontbox.ttf.TrueTypeFont) PostScriptTable(com.tom_roush.fontbox.ttf.PostScriptTable) CmapTable(com.tom_roush.fontbox.ttf.CmapTable) InputStream(java.io.InputStream) TTFParser(com.tom_roush.fontbox.ttf.TTFParser) CmapSubtable(com.tom_roush.fontbox.ttf.CmapSubtable) Test(org.junit.Test)

Example 2 with CmapSubtable

use of com.tom_roush.fontbox.ttf.CmapSubtable in project PdfBox-Android by TomRoush.

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;
}
Also used : CmapTable(com.tom_roush.fontbox.ttf.CmapTable) CmapSubtable(com.tom_roush.fontbox.ttf.CmapSubtable)

Aggregations

CmapSubtable (com.tom_roush.fontbox.ttf.CmapSubtable)2 CmapTable (com.tom_roush.fontbox.ttf.CmapTable)2 PostScriptTable (com.tom_roush.fontbox.ttf.PostScriptTable)1 TTFParser (com.tom_roush.fontbox.ttf.TTFParser)1 TrueTypeFont (com.tom_roush.fontbox.ttf.TrueTypeFont)1 InputStream (java.io.InputStream)1 Test (org.junit.Test)1