Class Type1Font

  • Direct Known Subclasses:
    BuiltinFont

    public class Type1Font
    extends OutlineFont
    A representation, with parser, of an Adobe Type 1 font.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      (package private) class  Type1Font.PSParser
      PostScript reader (not a parser, as the name would seem to indicate).
    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) java.awt.geom.AffineTransform at  
      (package private) int callcount  
      (package private) java.lang.String[] chr2name  
      (package private) int lenIV  
      (package private) java.util.Map<java.lang.String,​java.lang.Object> name2outline  
      (package private) java.util.Map<java.lang.String,​FlPoint> name2width  
      (package private) int password  
      (package private) int psLoc
      the current position in the postscript stack
      (package private) float[] psStack
      the stack of postscript commands (used by callothersubr)
      (package private) int sloc
      the current position in the Type1 stack
      (package private) float[] stack
      the Type1 stack of command values
      (package private) byte[][] subrs  
    • Constructor Summary

      Constructors 
      Constructor Description
      Type1Font​(java.lang.String baseName, PDFObject src, PDFFontDescriptor descriptor)
      create a new Type1Font based on a font data stream and an encoding.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void buildAccentChar​(float x, float y, char a, char b, java.awt.geom.GeneralPath gp)
      build an accented character out of two pre-defined glyphs.
      private byte[] decrypt​(byte[] d, int start, int end, int key, int skip)
      decrypt an array using the Adobe Type 1 Font decryption algorithm.
      private int findSlashName​(byte[] d, java.lang.String name)
      get the index into the byte array of a slashed name, like "/name".
      protected java.awt.geom.GeneralPath getOutline​(char src, float width)
      Get a glyph outline by character code Note this method must always return an outline
      protected java.awt.geom.GeneralPath getOutline​(java.lang.String name, float width)
      Get a glyph outline by name
      float getWidth​(char code, java.lang.String name)
      Get the width of a given character This method is overridden to work if the width array hasn't been populated (as for one of the 14 base fonts)
      private boolean isASCII​(byte[] data, int start)
      Determine if data is in ASCII or binary format.
      private void parse​(byte[] cs, java.awt.geom.GeneralPath gp, FlPoint pt, FlPoint wid)
      parse glyph data into a GeneralPath, and return the advance width.
      protected void parseFont​(byte[] font, int start, int len)
      Read a font from it's data, start position and length
      private java.awt.geom.GeneralPath parseGlyph​(byte[] cs, FlPoint advance, java.awt.geom.AffineTransform at)
      Decrypt a glyph stored in byte form
      private float pop()
      pop the next item off the stack
      private byte[][] readArray​(byte[] d, java.lang.String key, java.lang.String end)
      read a named array out of the font definition.
      private byte[] readASCII​(byte[] data, int start, int end)
      Read data formatted as ASCII strings as binary data
      private java.util.HashMap<java.lang.String,​byte[]> readChars​(byte[] d)
      get the character definitions of the font.
      private java.lang.String[] readEncoding​(byte[] d)
      parse the encoding portion of the font definition
      private byte[][] readSubrs​(byte[] d)
      read the subroutines out of the font definition
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • chr2name

        java.lang.String[] chr2name
      • password

        int password
      • subrs

        byte[][] subrs
      • lenIV

        int lenIV
      • name2outline

        java.util.Map<java.lang.String,​java.lang.Object> name2outline
      • name2width

        java.util.Map<java.lang.String,​FlPoint> name2width
      • at

        java.awt.geom.AffineTransform at
      • stack

        float[] stack
        the Type1 stack of command values
      • sloc

        int sloc
        the current position in the Type1 stack
      • psStack

        float[] psStack
        the stack of postscript commands (used by callothersubr)
      • psLoc

        int psLoc
        the current position in the postscript stack
      • callcount

        int callcount
    • Constructor Detail

      • Type1Font

        public Type1Font​(java.lang.String baseName,
                         PDFObject src,
                         PDFFontDescriptor descriptor)
                  throws java.io.IOException
        create a new Type1Font based on a font data stream and an encoding.
        Parameters:
        baseName - the postscript name of this font
        src - the Font object as a stream with a dictionary
        descriptor - the descriptor for this font
        Throws:
        java.io.IOException
    • Method Detail

      • parseFont

        protected void parseFont​(byte[] font,
                                 int start,
                                 int len)
        Read a font from it's data, start position and length
      • readEncoding

        private java.lang.String[] readEncoding​(byte[] d)
        parse the encoding portion of the font definition
        Parameters:
        d - the font definition stream
        Returns:
        an array of the glyphs corresponding to each byte
      • readSubrs

        private byte[][] readSubrs​(byte[] d)
        read the subroutines out of the font definition
        Parameters:
        d - the font definition stream
        Returns:
        an array of the subroutines, each as a byte array.
      • readArray

        private byte[][] readArray​(byte[] d,
                                   java.lang.String key,
                                   java.lang.String end)
        read a named array out of the font definition.

        this function attempts to parse an array out of a postscript definition without doing any postscript. It's actually looking for things that look like "dup id elt put", and placing the elt at the ith position in the array.

        Parameters:
        d - the font definition stream
        key - the name of the array
        end - a string that appears at the end of the array
        Returns:
        an array consisting of a byte array for each entry
      • decrypt

        private byte[] decrypt​(byte[] d,
                               int start,
                               int end,
                               int key,
                               int skip)
        decrypt an array using the Adobe Type 1 Font decryption algorithm.
        Parameters:
        d - the input array of bytes
        start - where in the array to start decoding
        end - where in the array to stop decoding
        key - the decryption key
        skip - how many bytes to skip initially
        Returns:
        the decrypted bytes. The length of this array will be (start-end-skip) bytes long
      • readASCII

        private byte[] readASCII​(byte[] data,
                                 int start,
                                 int end)
        Read data formatted as ASCII strings as binary data
        Parameters:
        data - the data, formatted as ASCII strings
        start - where in the array to start decrypting
        end - where in the array to stop decrypting
      • isASCII

        private boolean isASCII​(byte[] data,
                                int start)
        Determine if data is in ASCII or binary format. According to the spec, if any of the first 4 bytes are not character codes ('0' - '9' or 'A' - 'F' or 'a' - 'f'), then the data is binary. Otherwise it is ASCII
      • findSlashName

        private int findSlashName​(byte[] d,
                                  java.lang.String name)
        get the index into the byte array of a slashed name, like "/name".
        Parameters:
        d - the search array
        name - the name to look for, without the initial /
        Returns:
        the index of the first occurance of /name in the array.
      • readChars

        private java.util.HashMap<java.lang.String,​byte[]> readChars​(byte[] d)
        get the character definitions of the font.
        Parameters:
        d - the font data
        Returns:
        a HashMap that maps string glyph names to byte arrays of decoded font data.
      • pop

        private float pop()
        pop the next item off the stack
      • parse

        private void parse​(byte[] cs,
                           java.awt.geom.GeneralPath gp,
                           FlPoint pt,
                           FlPoint wid)
        parse glyph data into a GeneralPath, and return the advance width. The working point is passed in as a parameter in order to allow recursion.
        Parameters:
        cs - the decrypted glyph data
        gp - a GeneralPath into which the glyph shape will be stored
        pt - a FlPoint object that will be used to generate the path
        wid - a FlPoint into which the advance width will be placed.
      • buildAccentChar

        private void buildAccentChar​(float x,
                                     float y,
                                     char a,
                                     char b,
                                     java.awt.geom.GeneralPath gp)
        build an accented character out of two pre-defined glyphs.
        Parameters:
        x - the x offset of the accent
        y - the y offset of the accent
        a - the index of the accent glyph
        b - the index of the base glyph
        gp - the GeneralPath into which the combined glyph will be written.
      • getWidth

        public float getWidth​(char code,
                              java.lang.String name)
        Get the width of a given character This method is overridden to work if the width array hasn't been populated (as for one of the 14 base fonts)
        Overrides:
        getWidth in class OutlineFont
      • parseGlyph

        private java.awt.geom.GeneralPath parseGlyph​(byte[] cs,
                                                     FlPoint advance,
                                                     java.awt.geom.AffineTransform at)
        Decrypt a glyph stored in byte form
      • getOutline

        protected java.awt.geom.GeneralPath getOutline​(java.lang.String name,
                                                       float width)
        Get a glyph outline by name
        Specified by:
        getOutline in class OutlineFont
        Parameters:
        name - the name of the desired glyph
        Returns:
        the glyph outline, or null if unavailable
      • getOutline

        protected java.awt.geom.GeneralPath getOutline​(char src,
                                                       float width)
        Get a glyph outline by character code Note this method must always return an outline
        Specified by:
        getOutline in class OutlineFont
        Parameters:
        src - the character code of the desired glyph
        Returns:
        the glyph outline