Class TTFParser


  • public class TTFParser
    extends java.lang.Object
    A true type font file parser.
    Author:
    Ben Litchfield (ben@benlitchfield.com)
    • Constructor Summary

      Constructors 
      Constructor Description
      TTFParser()
      Constructor.
      TTFParser​(boolean isEmbedded)
      Constructor.
      TTFParser​(boolean isEmbedded, boolean parseOnDemand)
      Constructor.
    • Field Detail

      • isEmbedded

        protected boolean isEmbedded
      • parseOnDemandOnly

        protected boolean parseOnDemandOnly
    • Constructor Detail

      • TTFParser

        public TTFParser()
        Constructor.
      • TTFParser

        public TTFParser​(boolean isEmbedded)
        Constructor.
        Parameters:
        isEmbedded - indicates whether the font is embedded or not.
      • TTFParser

        public TTFParser​(boolean isEmbedded,
                         boolean parseOnDemand)
        Constructor.
        Parameters:
        isEmbedded - indicates whether the font is embedded or not.
        parseOnDemand - indicates whether the tables of the font should be parsed on demand only or not.
    • Method Detail

      • main

        public static void main​(java.lang.String[] args)
                         throws java.io.IOException
        A simple command line program to test parsing of a TTF file.
        usage: java org.pdfbox.ttf.TTFParser <ttf-file>
        Parameters:
        args - The command line arguments.
        Throws:
        java.io.IOException - If there is an error while parsing the font file.
      • parseTables

        protected void parseTables​(TrueTypeFont font,
                                   TTFDataStream raf)
                            throws java.io.IOException
        Parse all tables and check if all needed tables are present.
        Parameters:
        font - the TrueTypeFont instance holding the parsed data.
        raf - the data stream of the to be parsed ttf font
        Throws:
        java.io.IOException - If there is an error parsing the TrueType font.
      • parseTTF

        public TrueTypeFont parseTTF​(java.lang.String ttfFile)
                              throws java.io.IOException
        Parse a file and get a TrueType font.
        Parameters:
        ttfFile - The TrueType file name.
        Returns:
        A TrueType font.
        Throws:
        java.io.IOException - If there is an error parsing the TrueType font.
      • parseTTF

        public TrueTypeFont parseTTF​(java.io.File ttfFile)
                              throws java.io.IOException
        Parse a file and get a TrueType font.
        Parameters:
        ttfFile - The TrueType file.
        Returns:
        A TrueType font.
        Throws:
        java.io.IOException - If there is an error parsing the TrueType font.
      • parseTTF

        public TrueTypeFont parseTTF​(java.io.InputStream inputStream)
                              throws java.io.IOException
        Parse an input stream and return a TrueType font.
        Parameters:
        inputStream - The TTF data stream to parse from. It will be closed before returning.
        Returns:
        A TrueType font.
        Throws:
        java.io.IOException - If there is an error parsing the TrueType font.
      • parseTTF

        public TrueTypeFont parseTTF​(TTFDataStream raf)
                              throws java.io.IOException
        Parse a TrueType data stream and get a TrueType font.
        Parameters:
        raf - The TrueType file.
        Returns:
        A TrueType font.
        Throws:
        java.io.IOException - If there is an error parsing the TrueType font.