Class Type2CStringGenerator

  • All Implemented Interfaces:
    HintedOutlineConsumer, OutlineConsumer

    public final class Type2CStringGenerator
    extends java.lang.Object
    implements HintedOutlineConsumer
    Generate a type2 charstring index from hinted outlines. An instance of this class cannot be reused with multiple fonts. newGlyph must be called before each glyph that is played. After all glyphs have been played, calculateDefaultWidth and calculateNominalWidth may be used to calculate optimal values for the DefaultWidth and NominalWidth cff keys. If one of calculateDefaultWidth or calculateNominalWidth is called, the other must also be called and the returned values must be put in the cff dictionary associated with the call unless default values are returned. (Default values are Type2CStringGenerator.DEFAULT_NOMINAL_WIDTH and Type2CStringGenerator.DEFAULT_DEFAULT_WIDTH). Finally, getCharstringIndex can be called to fetch an index formatted for use as a cff charstring index.

    Synchronization

    This class is not synchronized. If a single instance is to be used in multiple threads, the client is responsible for its threadsafety. However, multiple instances of Type2CStringGenerator can be used concurrently in separate threads.
    • Constructor Summary

      Constructors 
      Constructor Description
      Type2CStringGenerator​(int numGlyphs, int numFDs)
      Creates an instance of a Type2CStringGenerator.
      Type2CStringGenerator​(int numGlyphs, int numFDs, boolean willSubrize)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      double calculateDefaultWidth​(int fontDictionary)
      All of the charstrings have been run.
      double calculateNominalWidth​(int fontDictionary)
      All of the charstrings have been run.
      void closepath()
      A closepath command was seen.
      void curveto​(double x1, double y1, double x2, double y2)
      Called for a quadratic curve.
      void curveto​(double x1, double y1, double x2, double y2, double x3, double y3)
      Called for a cubic curve.
      void endchar()
      Called to signal the end of a glyph's outline.
      void flex​(double depth, double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4, double x5, double y5, double x6, double y6)
      A flex command was seen
      CharStrings getCharstringIndex()
      All of the charstrings have been run.
      void globalColorOn()
      A command was seen that says that global coloring applies to this glyph.
      void lineto​(double x, double y)
      Called for a line.
      void moveto​(double x, double y)
      Called to set a new currentpoint.
      void newGlyph​(int glyphID, int fontDictionary, double defaultWidth, double nominalWidth)
      Called before playing the outlines for a new glyph.
      void noCounters()
      A command was seen that says that the glyph has no counters.
      void noHints()
      A command was seen that says that no hints should be applied to the next part of the glyph.
      void setMatrix​(Matrix m)
      Tells the OutlineConsumer the matrix to be applied to subsequent points in order to get to a 1 ppem size.
      void stem​(double edge1, double edge2, boolean doHintSubstitution, boolean vertical, boolean isCounter)
      A stem command was seen.
      void stem3​(double edge1, double edge2, double edge3, double edge4, double edge5, double edge6, boolean doHintSubstitution, boolean isVertical)
      A hstem3 or vstem3 command was seen.
      boolean width​(double wx)
      The advance width of the glyph in the x direction
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Type2CStringGenerator

        public Type2CStringGenerator​(int numGlyphs,
                                     int numFDs)
        Creates an instance of a Type2CStringGenerator.
        Parameters:
        numGlyphs - The number of charstrings that will be generated.
        numFDs - The number of font dictionaries that will be associated with those charstrings. numFDs must be at least 1.
      • Type2CStringGenerator

        public Type2CStringGenerator​(int numGlyphs,
                                     int numFDs,
                                     boolean willSubrize)
    • Method Detail

      • newGlyph

        public void newGlyph​(int glyphID,
                             int fontDictionary,
                             double defaultWidth,
                             double nominalWidth)
        Called before playing the outlines for a new glyph. This function must be called exactly one time for each glyph that is to be played.
        Parameters:
        glyphID - The glyphID for the new glyph. glyphID must be less than the numGlyphs value passed to the constructor.
        fontDictionary - The font dictionary to which the glyph belongs. fontDictionary must be at least 0 and must be less than the numFDs value passed to the constructor.
        defaultWidth - The default width associated with this glyph. DEFAULT_DEFAULT_WIDTH should be passed if there isn't one.
      • setMatrix

        public void setMatrix​(Matrix m)
        Description copied from interface: OutlineConsumer
        Tells the OutlineConsumer the matrix to be applied to subsequent points in order to get to a 1 ppem size. It is possible for setMatrix to be called multiple times for a single glyph. Each call replaces the previous matrix. It is guaranteed that setMatrix will be called prior to any other methods.
        Specified by:
        setMatrix in interface OutlineConsumer
      • stem

        public void stem​(double edge1,
                         double edge2,
                         boolean doHintSubstitution,
                         boolean vertical,
                         boolean isCounter)
        Description copied from interface: HintedOutlineConsumer
        A stem command was seen.
        Specified by:
        stem in interface HintedOutlineConsumer
        Parameters:
        edge1 - The bottom/left edge.
        edge2 - The top/right edge. If isCounter is false and the stem is a topmost, rightmost, bottommost, or leftmost edge, the order of the edges is reversed (ie edge1 > edge2). If isCounter is true and the stem is the last counter in the current counter group, the order of the edges is reversed (ie edge1 > edge2).
        doHintSubstitution - If isCounter is false, hint substitution must occur at this point iff doHintSubstitution is true. Else iff doHintSubstitution is true and isCounter is true, a new counter group must be started at this point.
        vertical - true iff the command was a vertical stem/counter.
        isCounter - true iff the stem should be added to the current counter group.
      • stem3

        public void stem3​(double edge1,
                          double edge2,
                          double edge3,
                          double edge4,
                          double edge5,
                          double edge6,
                          boolean doHintSubstitution,
                          boolean isVertical)
        Description copied from interface: HintedOutlineConsumer
        A hstem3 or vstem3 command was seen. The relevant edges are returned
        Specified by:
        stem3 in interface HintedOutlineConsumer
        doHintSubstitution - If true, hint substitution must occur at this point.
        isVertical - true iff this command is a vstem3
      • width

        public boolean width​(double wx)
        Description copied from interface: HintedOutlineConsumer
        The advance width of the glyph in the x direction
        Specified by:
        width in interface HintedOutlineConsumer
        Parameters:
        wx - the advance width
        Returns:
        true if charstring processing should continue. false otherwise.
      • globalColorOn

        public void globalColorOn()
        Description copied from interface: HintedOutlineConsumer
        A command was seen that says that global coloring applies to this glyph. One pass global coloring should be used if <@link HintedOutlineConsumer#noCounters()> is called or if a counter hint is associated with this glyph. Otherwise, two pass global coloring should be used.
        Specified by:
        globalColorOn in interface HintedOutlineConsumer
      • lineto

        public void lineto​(double x,
                           double y)
        Description copied from interface: OutlineConsumer
        Called for a line. The line goes from the current point to (x, y). After this call, the currentpoint should be x,y
        Specified by:
        lineto in interface OutlineConsumer
      • curveto

        public void curveto​(double x1,
                            double y1,
                            double x2,
                            double y2)
        Description copied from interface: OutlineConsumer
        Called for a quadratic curve. The control points are the current point, (x2, y2), (x3, y3). After this call, the currentpoint should be x3, y3.
        Specified by:
        curveto in interface OutlineConsumer
      • curveto

        public void curveto​(double x1,
                            double y1,
                            double x2,
                            double y2,
                            double x3,
                            double y3)
        Description copied from interface: OutlineConsumer
        Called for a cubic curve. The control points are the current point, (x2, y2), (x3, y3), (x4, y4). After this call, the currentpoint should be x4, y4.
        Specified by:
        curveto in interface OutlineConsumer
      • moveto

        public void moveto​(double x,
                           double y)
        Description copied from interface: OutlineConsumer
        Called to set a new currentpoint. If lineto or curveto was previously been called and was the most recent function called, an implied lineto should precede this move and should close the previous segment by connecting the last point in the most recent line/curve with the point that started the last segment.
        Specified by:
        moveto in interface OutlineConsumer
        Parameters:
        x - the x coordinate of the new currentpoint
        y - the y coordinate of the new currentpoint
      • flex

        public void flex​(double depth,
                         double x1,
                         double y1,
                         double x2,
                         double y2,
                         double x3,
                         double y3,
                         double x4,
                         double y4,
                         double x5,
                         double y5,
                         double x6,
                         double y6)
        Description copied from interface: HintedOutlineConsumer
        A flex command was seen
        Specified by:
        flex in interface HintedOutlineConsumer
      • endchar

        public void endchar()
        Description copied from interface: OutlineConsumer
        Called to signal the end of a glyph's outline. The last path will already be closed by the time this is called.
        Specified by:
        endchar in interface OutlineConsumer
      • calculateNominalWidth

        public double calculateNominalWidth​(int fontDictionary)
        All of the charstrings have been run. Calculate and return the optimal nominal width
      • calculateDefaultWidth

        public double calculateDefaultWidth​(int fontDictionary)
        All of the charstrings have been run. Calculate and return the optimal default width