Class CMapParser

java.lang.Object
org.apache.fontbox.cmap.CMapParser

public class CMapParser extends Object
Parses a CMap stream.
  • Field Details

    • MARK_END_OF_DICTIONARY

      private static final String MARK_END_OF_DICTIONARY
      See Also:
    • MARK_END_OF_ARRAY

      private static final String MARK_END_OF_ARRAY
      See Also:
    • tokenParserByteBuffer

      private final byte[] tokenParserByteBuffer
    • strictMode

      private boolean strictMode
  • Constructor Details

    • CMapParser

      public CMapParser()
      Creates a new instance of CMapParser.
    • CMapParser

      public CMapParser(boolean strictMode)
      Creates a new instance of CMapParser.
      Parameters:
      strictMode - activates the strict mode used for inline CMaps
  • Method Details

    • parse

      public CMap parse(File file) throws IOException
      Parse a CMAP file on the file system.
      Parameters:
      file - The file to parse.
      Returns:
      A parsed CMAP file.
      Throws:
      IOException - If there is an issue while parsing the CMAP.
    • parsePredefined

      public CMap parsePredefined(String name) throws IOException
      Parses a predefined CMap.
      Parameters:
      name - CMap name.
      Returns:
      The parsed predefined CMap as a java object, never null.
      Throws:
      IOException - If the CMap could not be parsed.
    • parse

      public CMap parse(InputStream input) throws IOException
      This will parse the stream and create a cmap object.
      Parameters:
      input - The CMAP stream to parse.
      Returns:
      The parsed stream as a java object, never null.
      Throws:
      IOException - If there is an error parsing the stream.
    • parseUsecmap

      private void parseUsecmap(CMapParser.LiteralName useCmapName, CMap result) throws IOException
      Throws:
      IOException
    • parseLiteralName

      private void parseLiteralName(CMapParser.LiteralName literal, PushbackInputStream cmapStream, CMap result) throws IOException
      Throws:
      IOException
    • checkExpectedOperator

      private void checkExpectedOperator(CMapParser.Operator operator, String expectedOperatorName, String rangeName) throws IOException
      Throws an IOException if expectedOperatorName not equals operator.op
      Parameters:
      operator - Instance of operator
      expectedOperatorName - Expected name of operator
      rangeName - The name of the range in which the operator is expected (without a tilde character), to be used in the exception message.
      Throws:
      IOException - if expectedOperatorName not equals operator.op
    • parseBegincodespacerange

      private void parseBegincodespacerange(Number cosCount, PushbackInputStream cmapStream, CMap result) throws IOException
      Throws:
      IOException
    • parseBeginbfchar

      private void parseBeginbfchar(Number cosCount, PushbackInputStream cmapStream, CMap result) throws IOException
      Throws:
      IOException
    • parseBegincidrange

      private void parseBegincidrange(int numberOfLines, PushbackInputStream cmapStream, CMap result) throws IOException
      Throws:
      IOException
    • parseBegincidchar

      private void parseBegincidchar(Number cosCount, PushbackInputStream cmapStream, CMap result) throws IOException
      Throws:
      IOException
    • parseBeginbfrange

      private void parseBeginbfrange(Number cosCount, PushbackInputStream cmapStream, CMap result) throws IOException
      Throws:
      IOException
    • addMappingFrombfrange

      private void addMappingFrombfrange(CMap cmap, byte[] startCode, List<byte[]> tokenBytesList)
    • addMappingFrombfrange

      private void addMappingFrombfrange(CMap cmap, byte[] startCode, int values, byte[] tokenBytes)
    • getExternalCMap

      protected InputStream getExternalCMap(String name) throws IOException
      Returns an input stream containing the given "use" CMap.
      Parameters:
      name - Name of the given "use" CMap resource.
      Throws:
      IOException - if the CMap resource doesn't exist or if there is an error opening its stream.
    • parseNextToken

      private Object parseNextToken(PushbackInputStream is) throws IOException
      Throws:
      IOException
    • readUntilEndOfLine

      private void readUntilEndOfLine(InputStream is, StringBuilder buf) throws IOException
      Throws:
      IOException
    • isWhitespaceOrEOF

      private boolean isWhitespaceOrEOF(int aByte)
    • isDelimiter

      private boolean isDelimiter(int aByte)
      Is this a standard PDF delimiter character?
    • increment

      private boolean increment(byte[] data, int position, boolean useStrictMode)
    • createIntFromBytes

      private int createIntFromBytes(byte[] bytes)
    • createStringFromBytes

      private String createStringFromBytes(byte[] bytes)