Class CMapParser


  • public class CMapParser
    extends java.lang.Object
    Parses a CMap stream.
    • Field Detail

      • MARK_END_OF_DICTIONARY

        private static final java.lang.String MARK_END_OF_DICTIONARY
        See Also:
        Constant Field Values
      • MARK_END_OF_ARRAY

        private static final java.lang.String MARK_END_OF_ARRAY
        See Also:
        Constant Field Values
      • tokenParserByteBuffer

        private final byte[] tokenParserByteBuffer
      • strictMode

        private boolean strictMode
    • Constructor Detail

      • 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 Detail

      • parsePredefined

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

        public CMap parse​(RandomAccessRead randomAcccessRead)
                   throws java.io.IOException
        This will parse the stream and create a cmap object.
        Parameters:
        randomAcccessRead - the source of the CMap to be parsed.
        Returns:
        The parsed source as a java object, never null.
        Throws:
        java.io.IOException - If there is an error parsing the data.
      • parseUsecmap

        private void parseUsecmap​(CMapParser.LiteralName useCmapName,
                                  CMap result)
                           throws java.io.IOException
        Throws:
        java.io.IOException
      • checkExpectedOperator

        private void checkExpectedOperator​(CMapParser.Operator operator,
                                           java.lang.String expectedOperatorName,
                                           java.lang.String rangeName)
                                    throws java.io.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:
        java.io.IOException - if expectedOperatorName not equals operator.op
      • parseBegincodespacerange

        private void parseBegincodespacerange​(java.lang.Number cosCount,
                                              RandomAccessRead randomAcccessRead,
                                              CMap result)
                                       throws java.io.IOException
        Throws:
        java.io.IOException
      • parseBeginbfchar

        private void parseBeginbfchar​(java.lang.Number cosCount,
                                      RandomAccessRead randomAcccessRead,
                                      CMap result)
                               throws java.io.IOException
        Throws:
        java.io.IOException
      • parseBegincidrange

        private void parseBegincidrange​(int numberOfLines,
                                        RandomAccessRead randomAcccessRead,
                                        CMap result)
                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • parseBegincidchar

        private void parseBegincidchar​(java.lang.Number cosCount,
                                       RandomAccessRead randomAcccessRead,
                                       CMap result)
                                throws java.io.IOException
        Throws:
        java.io.IOException
      • parseBeginbfrange

        private void parseBeginbfrange​(java.lang.Number cosCount,
                                       RandomAccessRead randomAcccessRead,
                                       CMap result)
                                throws java.io.IOException
        Throws:
        java.io.IOException
      • addMappingFrombfrange

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

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

        private RandomAccessRead getExternalCMap​(java.lang.String name)
                                          throws java.io.IOException
        Returns a RandomAccessRead containing the given "use" CMap.
        Parameters:
        name - Name of the given "use" CMap resource.
        Throws:
        java.io.IOException - if the CMap resource doesn't exist or if there is an error opening it.
      • parseNextToken

        private java.lang.Object parseNextToken​(RandomAccessRead randomAcccessRead)
                                         throws java.io.IOException
        Throws:
        java.io.IOException
      • parseInteger

        private java.lang.Integer parseInteger​(RandomAccessRead randomAcccessRead)
                                        throws java.io.IOException
        Throws:
        java.io.IOException
      • parseByteArray

        private byte[] parseByteArray​(RandomAccessRead randomAcccessRead)
                               throws java.io.IOException
        Throws:
        java.io.IOException
      • readArray

        private java.util.List<java.lang.Object> readArray​(RandomAccessRead randomAcccessRead)
                                                    throws java.io.IOException
        Throws:
        java.io.IOException
      • readString

        private java.lang.String readString​(RandomAccessRead randomAcccessRead)
                                     throws java.io.IOException
        Throws:
        java.io.IOException
      • readLine

        private java.lang.String readLine​(RandomAccessRead randomAcccessRead,
                                          int firstByte)
                                   throws java.io.IOException
        Throws:
        java.io.IOException
      • readNumber

        private java.lang.Number readNumber​(RandomAccessRead randomAcccessRead,
                                            int firstByte)
                                     throws java.io.IOException
        Throws:
        java.io.IOException
      • readDictionary

        private java.lang.Object readDictionary​(RandomAccessRead randomAcccessRead)
                                         throws java.io.IOException
        Throws:
        java.io.IOException
      • readUntilEndOfLine

        private void readUntilEndOfLine​(RandomAccessRead randomAcccessRead,
                                        java.lang.StringBuilder buf)
                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • isWhitespaceOrEOF

        private static boolean isWhitespaceOrEOF​(int aByte)
      • isDelimiter

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

        private static boolean increment​(byte[] data,
                                         int position,
                                         boolean useStrictMode)
      • createStringFromBytes

        private static java.lang.String createStringFromBytes​(byte[] bytes)