Class NativeFont


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

    • 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 Font f
      the actual font in use
    • basecontext

      private 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 Details

    • NativeFont

      public NativeFont(String baseFont, PDFObject fontObj, PDFFontDescriptor descriptor) throws 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:
      IOException
  • Method Details

    • getOutline

      protected GeneralPath getOutline(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 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(Font f)
      Set the font
      Parameters:
      f - the font to use
    • setFont

      protected void setFont(byte[] fontdata) throws FontFormatException, IOException
      Set the font
      Parameters:
      fontdata - the font data as a byte array
      Throws:
      FontFormatException
      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