Class AFMParser

java.lang.Object
org.apache.fontbox.afm.AFMParser

public class AFMParser extends Object
This class is used to parse AFM(Adobe Font Metrics) documents.
See Also:
  • Field Details

  • Constructor Details

    • AFMParser

      public AFMParser(InputStream in)
      Constructor.
      Parameters:
      in - The input stream to read the AFM document from.
  • Method Details

    • parse

      public FontMetrics parse() throws IOException
      This will parse the AFM document. The input stream is closed when the parsing is finished.
      Returns:
      the parsed FontMetric
      Throws:
      IOException - If there is an IO error reading the document.
    • parse

      public FontMetrics parse(boolean reducedDataset) throws IOException
      This will parse the AFM document. The input stream is closed when the parsing is finished.
      Parameters:
      reducedDataset - parse a reduced subset of data if set to true
      Returns:
      the parsed FontMetric
      Throws:
      IOException - If there is an IO error reading the document.
    • parseFontMetric

      private FontMetrics parseFontMetric(boolean reducedDataset) throws IOException
      This will parse a font metrics item.
      Returns:
      The parse font metrics item.
      Throws:
      IOException - If there is an error reading the AFM file.
    • parseKernData

      private void parseKernData(FontMetrics fontMetrics) throws IOException
      This will parse the kern data.
      Parameters:
      fontMetrics - The metrics class to put the parsed data into.
      Throws:
      IOException - If there is an error parsing the data.
    • parseKernPair

      private KernPair parseKernPair() throws IOException
      This will parse a kern pair from the data stream.
      Returns:
      The kern pair that was parsed from the stream.
      Throws:
      IOException - If there is an error reading from the stream.
    • hexToString

      private String hexToString(String hexString) throws IOException
      This will convert and angle bracket hex string to a string.
      Parameters:
      hexString - An angle bracket string.
      Returns:
      The bytes of the hex string.
      Throws:
      IOException - If the string is in an invalid format.
    • parseComposite

      private Composite parseComposite() throws IOException
      This will parse a composite part from the stream.
      Returns:
      The composite.
      Throws:
      IOException - If there is an error parsing the composite.
    • parseCharMetric

      private CharMetric parseCharMetric() throws IOException
      This will parse a single CharMetric object from the stream.
      Returns:
      The next char metric in the stream.
      Throws:
      IOException - If there is an error reading from the stream.
    • verifySemicolon

      private void verifySemicolon(StringTokenizer tokenizer) throws IOException
      This is used to verify that a semicolon is the next token in the stream.
      Parameters:
      tokenizer - The tokenizer to read from.
      Throws:
      IOException - If the semicolon is missing.
    • readBoolean

      private boolean readBoolean() throws IOException
      This will read a boolean from the stream.
      Returns:
      The boolean in the stream.
      Throws:
      IOException
    • readInt

      private int readInt() throws IOException
      This will read an integer from the stream.
      Returns:
      The integer in the stream.
      Throws:
      IOException
    • readFloat

      private float readFloat() throws IOException
      This will read a float from the stream.
      Returns:
      The float in the stream.
      Throws:
      IOException
    • readLine

      private String readLine() throws IOException
      This will read until the end of a line.
      Returns:
      The string that is read.
      Throws:
      IOException
    • readString

      private String readString() throws IOException
      This will read a string from the input stream and stop at any whitespace.
      Returns:
      The string read from the stream.
      Throws:
      IOException - If an IO error occurs when reading from the stream.
    • isEOL

      private boolean isEOL(int character)
      This will determine if the byte is a whitespace character or not.
      Parameters:
      character - The character to test for whitespace.
      Returns:
      true If the character is whitespace as defined by the AFM spec.
    • isWhitespace

      private boolean isWhitespace(int character)
      This will determine if the byte is a whitespace character or not.
      Parameters:
      character - The character to test for whitespace.
      Returns:
      true If the character is whitespace as defined by the AFM spec.