Class NativeFont


  • public class NativeFont
    extends OutlineFont
    a font object derived from a true type font.
    • Field Detail

      • controlChars

        protected static final char[] controlChars
        Control characters to filter out of the underlying font
      • mapIDs

        protected static final short[] mapIDs
        the ids of our favorite CMaps
      • f

        private java.awt.Font f
        the actual font in use
      • basecontext

        private java.awt.font.FontRenderContext basecontext
        the font render context
      • cmapTable

        private CmapTable cmapTable
        the cmap table from a TrueType font
      • postTable

        private PostTable postTable
        the post table from a TrueType font
      • unitsPerEm

        private int unitsPerEm
        the number of font units in one em
      • hmtxTable

        private HmtxTable hmtxTable
        the hmtx table from the TrueType font
    • Constructor Detail

      • NativeFont

        public NativeFont​(java.lang.String baseFont,
                          PDFObject fontObj,
                          PDFFontDescriptor descriptor)
                   throws java.io.IOException
        create a new NativeFont object based on a description of the font from the PDF file. If the description happens to contain an in-line true-type font file (under key "FontFile2"), use the true type font. Otherwise, parse the description for key information and use that to generate an appropriate font.
        Throws:
        java.io.IOException
    • Method Detail

      • getOutline

        protected java.awt.geom.GeneralPath getOutline​(java.lang.String name,
                                                       float width)
        Get a glyph outline by name
        Specified by:
        getOutline in class OutlineFont
        Parameters:
        name - the name of the desired glyph
        Returns:
        the glyph outline, or null if unavailable
      • getOutline

        protected java.awt.geom.GeneralPath getOutline​(char src,
                                                       float width)
        Get a glyph outline by character code Note this method must always return an outline
        Specified by:
        getOutline in class OutlineFont
        Parameters:
        src - the character code of the desired glyph
        Returns:
        the glyph outline
      • setFont

        protected void setFont​(java.awt.Font f)
        Set the font
        Parameters:
        f - the font to use
      • setFont

        protected void setFont​(byte[] fontdata)
                        throws java.awt.FontFormatException,
                               java.io.IOException
        Set the font
        Parameters:
        fontdata - the font data as a byte array
        Throws:
        java.awt.FontFormatException
        java.io.IOException
      • fixNameTable

        private boolean fixNameTable​(TrueTypeFont ttf,
                                     NameTable name)
        Fix a broken font name table for a TrueType font. Some fonts do not have Microsoft-specific name information, but Java won't work without it (grrr.). This method takes a font and adds the Microsoft data into it.
        Parameters:
        ttf - the font
        name - the font's name table
        Returns:
        true if the table was fixed, or false if it was left as is
      • fixCMapTable

        private boolean fixCMapTable​(TrueTypeFont ttf,
                                     CmapTable cmap)
        Fix the CMap table. This can be necessary if characters are mapped to control characters (0x9, 0xa, 0xd) Java will not render them, even though they are valid. Also, Java tends to not like it when there is only a Format 0 CMap, which happens frequently when included Format 4 CMaps are broken. Since PDF prefers the Format 0 map, while Java prefers the Format 4 map, it is generally necessary to re-write the Format 0 map as a Format 4 map to make most PDFs work.
        Parameters:
        ttf - the font
        cmap - the CMap table
        Returns:
        true if the font was changed, or false if it was left as-is