org.apache.fontbox.ttf.CmapSubtable Java Examples

The following examples show how to use org.apache.fontbox.ttf.CmapSubtable. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PDTrueTypeFont.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #2
Source File: PDTrueTypeFont.java    From sambox with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #3
Source File: TestTTFParser.java    From sambox with Apache License 2.0 4 votes vote down vote up
/**
 * Test the post table parser.
 * 
 * @throws IOException if an error occurs.
 */
@Test
public void testPostTable() throws IOException
{
    InputStream input = PDFont.class
            .getResourceAsStream("/org/sejda/sambox/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
    int gid = cmap.getGlyphId(0x2122); // TRADE MARK SIGN
    Assert.assertEquals("trademark", glyphNames[gid]);

    // test an additional name
    gid = cmap.getGlyphId(0x20AC); // EURO SIGN
    Assert.assertEquals("Euro", glyphNames[gid]);
}