Class CFFParser


  • public class CFFParser
    extends java.lang.Object
    This class represents a parser for a CFF font.
    • Field Detail

      • LOG

        private static final org.apache.commons.logging.Log LOG
        Log instance.
      • stringIndex

        private java.lang.String[] stringIndex
      • debugFontName

        private java.lang.String debugFontName
    • Constructor Detail

      • CFFParser

        public CFFParser()
    • Method Detail

      • parse

        public java.util.List<CFFFont> parse​(byte[] bytes,
                                             CFFParser.ByteSource source)
                                      throws java.io.IOException
        Parse CFF font using byte array, also passing in a byte source for future use.
        Parameters:
        bytes - source bytes
        source - source to re-read bytes from in the future
        Returns:
        the parsed CFF fonts
        Throws:
        java.io.IOException - If there is an error reading from the stream
      • parse

        public java.util.List<CFFFont> parse​(byte[] bytes)
                                      throws java.io.IOException
        Parse CFF font using a byte array as input.
        Parameters:
        bytes - the given byte array
        Returns:
        the parsed CFF fonts
        Throws:
        java.io.IOException - If there is an error reading from the stream
      • createTaggedCFFDataInput

        private CFFDataInput createTaggedCFFDataInput​(CFFDataInput input,
                                                      byte[] bytes)
                                               throws java.io.IOException
        Throws:
        java.io.IOException
      • readTagName

        private static java.lang.String readTagName​(CFFDataInput input)
                                             throws java.io.IOException
        Throws:
        java.io.IOException
      • readLong

        private static long readLong​(CFFDataInput input)
                              throws java.io.IOException
        Throws:
        java.io.IOException
      • readIndexDataOffsets

        private static int[] readIndexDataOffsets​(CFFDataInput input)
                                           throws java.io.IOException
        Throws:
        java.io.IOException
      • readIndexData

        private static byte[][] readIndexData​(CFFDataInput input)
                                       throws java.io.IOException
        Throws:
        java.io.IOException
      • readStringIndexData

        private static java.lang.String[] readStringIndexData​(CFFDataInput input)
                                                       throws java.io.IOException
        Throws:
        java.io.IOException
      • readDictData

        private static CFFParser.DictData readDictData​(CFFDataInput input,
                                                       int dictSize)
                                                throws java.io.IOException
        Throws:
        java.io.IOException
      • readOperator

        private static CFFOperator readOperator​(CFFDataInput input,
                                                int b0)
                                         throws java.io.IOException
        Throws:
        java.io.IOException
      • readOperatorKey

        private static CFFOperator.Key readOperatorKey​(CFFDataInput input,
                                                       int b0)
                                                throws java.io.IOException
        Throws:
        java.io.IOException
      • readIntegerNumber

        private static java.lang.Integer readIntegerNumber​(CFFDataInput input,
                                                           int b0)
                                                    throws java.io.IOException
        Throws:
        java.io.IOException
      • readRealNumber

        private static java.lang.Double readRealNumber​(CFFDataInput input,
                                                       int b0)
                                                throws java.io.IOException
        Parameters:
        b0 -
        Throws:
        java.io.IOException
      • parseFont

        private CFFFont parseFont​(CFFDataInput input,
                                  java.lang.String name,
                                  byte[] topDictIndex)
                           throws java.io.IOException
        Throws:
        java.io.IOException
      • concatenateMatrix

        private void concatenateMatrix​(java.util.List<java.lang.Number> matrixDest,
                                       java.util.List<java.lang.Number> matrixConcat)
      • parseCIDFontDicts

        private void parseCIDFontDicts​(CFFDataInput input,
                                       CFFParser.DictData topDict,
                                       CFFCIDFont font,
                                       int nrOfcharStrings)
                                throws java.io.IOException
        Parse dictionaries specific to a CIDFont.
        Throws:
        java.io.IOException
      • readPrivateDict

        private java.util.Map<java.lang.String,​java.lang.Object> readPrivateDict​(CFFParser.DictData privateDict)
      • readString

        private java.lang.String readString​(int index)
      • getString

        private java.lang.String getString​(CFFParser.DictData dict,
                                           java.lang.String name)
      • readFDSelect

        private static FDSelect readFDSelect​(CFFDataInput dataInput,
                                             int nGlyphs,
                                             CFFCIDFont ros)
                                      throws java.io.IOException
        Read the FDSelect Data according to the format.
        Parameters:
        dataInput -
        nGlyphs -
        ros -
        Returns:
        the FDSelect data
        Throws:
        java.io.IOException
      • readFormat0FDSelect

        private static CFFParser.Format0FDSelect readFormat0FDSelect​(CFFDataInput dataInput,
                                                                     int format,
                                                                     int nGlyphs,
                                                                     CFFCIDFont ros)
                                                              throws java.io.IOException
        Read the Format 0 of the FDSelect data structure.
        Parameters:
        dataInput -
        format -
        nGlyphs -
        ros -
        Returns:
        the Format 0 of the FDSelect data
        Throws:
        java.io.IOException
      • readFormat3FDSelect

        private static CFFParser.Format3FDSelect readFormat3FDSelect​(CFFDataInput dataInput,
                                                                     int format,
                                                                     int nGlyphs,
                                                                     CFFCIDFont ros)
                                                              throws java.io.IOException
        Read the Format 3 of the FDSelect data structure.
        Parameters:
        dataInput -
        format -
        nGlyphs -
        ros -
        Returns:
        the Format 3 of the FDSelect data
        Throws:
        java.io.IOException
      • readCharset

        private CFFCharset readCharset​(CFFDataInput dataInput,
                                       int nGlyphs,
                                       boolean isCIDFont)
                                throws java.io.IOException
        Throws:
        java.io.IOException
      • readFormat0Charset

        private CFFParser.Format0Charset readFormat0Charset​(CFFDataInput dataInput,
                                                            int format,
                                                            int nGlyphs,
                                                            boolean isCIDFont)
                                                     throws java.io.IOException
        Throws:
        java.io.IOException
      • readFormat1Charset

        private CFFParser.Format1Charset readFormat1Charset​(CFFDataInput dataInput,
                                                            int format,
                                                            int nGlyphs,
                                                            boolean isCIDFont)
                                                     throws java.io.IOException
        Throws:
        java.io.IOException
      • readFormat2Charset

        private CFFParser.Format2Charset readFormat2Charset​(CFFDataInput dataInput,
                                                            int format,
                                                            int nGlyphs,
                                                            boolean isCIDFont)
                                                     throws java.io.IOException
        Throws:
        java.io.IOException
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object