Java Code Examples for org.apache.fontbox.ttf.GlyphData#getPath()

The following examples show how to use org.apache.fontbox.ttf.GlyphData#getPath() . 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 6 votes vote down vote up
@Override
public GeneralPath getPath(int code) throws IOException
{
    int gid = codeToGID(code);
    GlyphData glyph = ttf.getGlyph().getGlyph(gid);
    
    // some glyphs have no outlines (e.g. space, table, newline)
    if (glyph == null)
    {
        return new GeneralPath();
    }
    else
    {
        return glyph.getPath();
    }
}
 
Example 2
Source File: PDCIDFontType2.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
@Override
public GeneralPath getPath(int code) throws IOException
{
    if (ttf instanceof OpenTypeFont && ((OpenTypeFont)ttf).isPostScript())
    {
        // we're not supposed to have CFF fonts inside PDCIDFontType2, but if we do,
        // then we treat their CIDs as GIDs, see PDFBOX-3344
        int cid = codeToGID(code);
        Type2CharString charstring = ((OpenTypeFont)ttf).getCFF().getFont().getType2CharString(cid);
        return charstring.getPath();
    }
    else
    {
        int gid = codeToGID(code);
        GlyphData glyph = ttf.getGlyph().getGlyph(gid);
        if (glyph != null)
        {
            return glyph.getPath();
        }
        return new GeneralPath();
    }
}
 
Example 3
Source File: PDCIDFontType2.java    From sambox with Apache License 2.0 6 votes vote down vote up
@Override
public GeneralPath getPath(int code) throws IOException
{
    if (ttf instanceof OpenTypeFont && ((OpenTypeFont) ttf).isPostScript())
    {
        // we're not supposed to have CFF fonts inside PDCIDFontType2, but if we do,
        // then we treat their CIDs as GIDs, see PDFBOX-3344
        int cid = codeToGID(code);
        Type2CharString charstring = ((OpenTypeFont) ttf).getCFF().getFont()
                .getType2CharString(cid);
        return charstring.getPath();
    }
    int gid = codeToGID(code);
    GlyphData glyph = ttf.getGlyph().getGlyph(gid);
    if (glyph != null)
    {
        return glyph.getPath();
    }
    return new GeneralPath();
}
 
Example 4
Source File: PDTrueTypeFont.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public GeneralPath getPath(String name) throws IOException
{
    // handle glyph names and uniXXXX names
    int gid = ttf.nameToGID(name);
    if (gid == 0)
    {
        try
        {
            // handle GID pseudo-names
            gid = Integer.parseInt(name);
            if (gid > ttf.getNumberOfGlyphs())
            {
                gid = 0;
            }
        }
        catch (NumberFormatException e)
        {
            gid = 0;
        }
    }
    // I'm assuming .notdef paths are not drawn, as it PDFBOX-2421
    if (gid == 0)
    {
        return new GeneralPath();
    }
    
    GlyphData glyph = ttf.getGlyph().getGlyph(gid);
    if (glyph != null)
    {
        return glyph.getPath();
    }
    else
    {
        return new GeneralPath();
    }
}
 
Example 5
Source File: PDTrueTypeFont.java    From sambox with Apache License 2.0 5 votes vote down vote up
@Override
public GeneralPath getPath(int code) throws IOException
{
    int gid = codeToGID(code);
    GlyphData glyph = ttf.getGlyph().getGlyph(gid);

    // some glyphs have no outlines (e.g. space, table, newline)
    if (glyph == null)
    {
        return new GeneralPath();
    }
    return glyph.getPath();
}
 
Example 6
Source File: PDTrueTypeFont.java    From sambox with Apache License 2.0 5 votes vote down vote up
@Override
public GeneralPath getPath(String name) throws IOException
{
    // handle glyph names and uniXXXX names
    int gid = ttf.nameToGID(name);
    if (gid == 0)
    {
        try
        {
            // handle GID pseudo-names
            gid = Integer.parseInt(name);
            if (gid > ttf.getNumberOfGlyphs())
            {
                gid = 0;
            }
        }
        catch (NumberFormatException e)
        {
            gid = 0;
        }
    }
    // I'm assuming .notdef paths are not drawn, as it PDFBOX-2421
    if (gid == 0)
    {
        return new GeneralPath();
    }

    GlyphData glyph = ttf.getGlyph().getGlyph(gid);
    if (glyph != null)
    {
        return glyph.getPath();
    }
    return new GeneralPath();
}
 
Example 7
Source File: FontState.java    From ttt with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private String getGlyphPath(PathCacheKey pck, GlyphTable glyphs) {
    try {
        GlyphData gd = glyphs.getGlyph(pck.getGlyph());
        if (gd != null) {
            GeneralPath p = gd.getPath();
            if (p != null)
                return getGlyphPath(pck.getFontKey(), p, pck.getAdvance());
        }
    } catch (IOException e) {
    }
    return null;
}