Class StemFinder

java.lang.Object
com.adobe.fontengine.font.StemFinder
All Implemented Interfaces:
OutlineConsumer

public final class StemFinder extends Object implements OutlineConsumer
Given unhinted cubic Beziers, derive a primary stem value. The returned stem is scaled to 1000 ppem. This class tries to find either horizontal or vertical primary stem values. The terminology in this description is geared toward finding vertical stems, but the algorithm also works for horizontal stems. Here is the algorithm: 1) Each curve is approximated as a series of 3 lines between the 4 control points. 2) For each line, the direction is examined to determine whether it is on the left or the right of the fill. They are then added to the list of "lefts" or "rights." 3) If 2 lines are continuations of each other, they are merged to form one longer line. 4) We walk the list of rights. If a right is too angled to be considered a stem, it is thrown out. 5) Repeat step 5 looking at the list of lefts. 6) The lists of lefts and rights are sorted left-to-right (based on their right most point) then top-to-bottom (based on their top-most point). 7) Not implemented: An attempt to deal "correctly" with shadow/outline fonts: if there is a small counter inside a fill and one side of the fill is small, throw out the lines that make up the counter, so the stem goes from the far left to the far right. This step is only taken if 'hintsForFauxing' is true. 8) If a left and right edge overlap enough and the width between them is a "reasonable" stem value, add the width to a running average. If no "good stems" are found, retry looking for any "stems".

Concurrency

Instances of this class are not threadsafe. If they are to be used in multiple threads, the client must ensure it is done safely.
  • Constructor Summary

    Constructors
    Constructor
    Description
    StemFinder(boolean findVerticalStem, boolean hintsForFauxing)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    curveto(double x1, double y1, double x2, double y2)
    Called for a quadratic curve.
    void
    curveto(double x2, double y2, double x3, double y3, double x4, double y4)
    Called for a cubic curve.
    void
    Called to signal the end of a glyph's outline.
    double
    getComputedStem(double advanceWidth, double italicAngle)
     
    void
    lineto(double x, double y)
    Called for a line.
    void
    moveto(double x, double y)
    Called to set a new currentpoint.
    void
    Reset this object so it can be used to compute another stem.
    void
    setMatrix(Matrix newMatrix)
    Tells the OutlineConsumer the matrix to be applied to subsequent points in order to get to a 1 ppem size.

    Methods inherited from class java.lang.Object

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

    • StemFinder

      public StemFinder(boolean findVerticalStem, boolean hintsForFauxing)
      Parameters:
      findVerticalStem - The stem finder should look for a vertical stem.
      hintsForFauxing - The stem being sought will be used in fauxing.
  • Method Details

    • reset

      public void reset()
      Reset this object so it can be used to compute another stem.
    • setMatrix

      public void setMatrix(Matrix newMatrix)
      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
      Parameters:
      newMatrix -
    • 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
    • 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 x2, double y2, double x3, double y3, double x4, double y4)
      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
    • getComputedStem

      public double getComputedStem(double advanceWidth, double italicAngle)
    • 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