Search in sources :

Example 1 with CmapSubtable

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

Example 2 with CmapSubtable

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]);
}
Also used : TrueTypeFont(org.apache.fontbox.ttf.TrueTypeFont) PostScriptTable(org.apache.fontbox.ttf.PostScriptTable) CmapTable(org.apache.fontbox.ttf.CmapTable) InputStream(java.io.InputStream) TTFParser(org.apache.fontbox.ttf.TTFParser) CmapSubtable(org.apache.fontbox.ttf.CmapSubtable) Test(org.junit.Test)

Aggregations

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