Class BaseCharStringParser

  • Direct Known Subclasses:
    Type1CharStringParser

    public abstract class BaseCharStringParser
    extends Object
    This is base class for Type1CharStringParser and Type2CharStringParser.
    Author:
    Sergey Shemyakov
    • Constructor Detail

      • BaseCharStringParser

        protected BaseCharStringParser​(ASInputStream stream)
                                throws IOException
        Constructor that calls method parse(), so width is extracted right after object is created. Subroutines are ignored in this case.
        Parameters:
        stream - is stream with decoded CharString.
        Throws:
        IOException - if parsing fails.
      • BaseCharStringParser

        protected BaseCharStringParser​(ASInputStream stream,
                                       CFFIndex localSubrs,
                                       int bias,
                                       CFFIndex globalSubrs,
                                       int gBias)
                                throws IOException
        Constructor that calls method parse(), so width is extracted right after object is created.
        Parameters:
        stream - is stream with decoded CharString.
        localSubrs - is local subroutines for this CharString.
        bias - is bias value for local subroutines as it is described in The Compact Font Format specification.
        gBias - is bias value for global subroutines as it is described in The Compact Font Format specification.
        Throws:
        IOException - if parsing fails.
    • Method Detail

      • getWidth

        public CFFNumber getWidth()
        Returns:
        width of glyph or null if it can't be found in given CharString.
      • setWidth

        protected void setWidth​(CFFNumber width)
      • readStreams

        protected int readStreams​(byte[] buffer,
                                  int size)
                           throws IOException
        Throws:
        IOException
      • popStack

        protected void popStack​(int num)
        Pops several operands from Type 1 Build Char stack.
        Parameters:
        num - is amount of numbers to be popped.
        Throws:
        IOException - if stream reading error occurs.
      • processNextOperator

        protected abstract boolean processNextOperator​(int nextByte)
                                                throws IOException
        This method processes charstring-encoded operators. It should set width when it can be determined. Methods returns true if width is calculated.
        Parameters:
        nextByte - is first byte of operator. Note that this byte is already read.
        Returns:
        true if width was extracted from processed operator.
        Throws:
        IOException - if stream reading error occurs.
      • readNextNumber

        protected abstract CFFNumber readNextNumber​(int firstByte)
                                             throws IOException
        This method reads next bytes from stream and interprets them as one number. In Type 1 CharStrings and Type 2 CharStrings this is done a little differently.
        Returns:
        number that was read.
        Throws:
        IOException - if stream reading error occurs.