Examples of FlatteningPathIterator


Examples of java.awt.geom.FlatteningPathIterator

  /**
   * Flattens an empty path.
   */
  private void test_emptyPath(TestHarness h)
  {
    FlatteningPathIterator fpi;
    GeneralPath path;

    h.checkPoint("emptyPath");

    path = new GeneralPath();
    fpi = new FlatteningPathIterator(
     path.getPathIterator(null),
     /* closely follow the shape */ 1e-4,
     /* but without any recursion */ 0);
    h.check(fpi.isDone());
  }
View Full Code Here

Examples of java.awt.geom.FlatteningPathIterator

                              double cx, double cy,
                              double x2, double y2,
                              double[] data)
  {
    Shape curve;
    FlatteningPathIterator fpi;

    curve = new QuadCurve2D.Double(x1, y1, cx, cy, x2, y2);
    fpi = new FlatteningPathIterator(curve.getPathIterator(null),
                                     flatness, level);
    if (data == null)
      dump(fpi);
    else
      checkSegments(h, fpi, data);
View Full Code Here

Examples of java.awt.geom.FlatteningPathIterator

                               double cx2, double cy2,
                               double x2, double y2,
                               double[] data)
  {
    CubicCurve2D curve;
    FlatteningPathIterator fpi;

    curve = new CubicCurve2D.Double(x1, y1, cx1, cy1, cx2, cy2, x2, y2);
    fpi = new FlatteningPathIterator(curve.getPathIterator(null),
                                     flatness, level);
    if (data == null)
    {
      dump(fpi);
      /*
 
View Full Code Here

Examples of java.awt.geom.FlatteningPathIterator

public class getFlatness
  implements Testlet
{
  public void test(TestHarness harness)
  {
    FlatteningPathIterator fpi;

    // Check 1
    fpi = new FlatteningPathIterator(
      new Line2D.Float().getPathIterator(null),
      3.141);
    harness.check(fpi.getFlatness(), 3.141);
  }
View Full Code Here

Examples of java.awt.geom.FlatteningPathIterator

public class getWindingRule
  implements Testlet
{
  public void test(TestHarness harness)
  {
    FlatteningPathIterator fpi;

    // Check 1
    fpi = new FlatteningPathIterator(
      new TestPathIterator(PathIterator.WIND_EVEN_ODD), 2.0);
    harness.check(fpi.getWindingRule(), PathIterator.WIND_EVEN_ODD);

    // Check 2
    fpi = new FlatteningPathIterator(
      new TestPathIterator(PathIterator.WIND_NON_ZERO), 23.0);
    harness.check(fpi.getWindingRule(), PathIterator.WIND_NON_ZERO);
  }
View Full Code Here

Examples of java.awt.geom.FlatteningPathIterator

public class getRecursionLimit
  implements Testlet
{
  public void test(TestHarness harness)
  {
    FlatteningPathIterator fpi;

    // Check 1
    fpi = new FlatteningPathIterator(
      new Line2D.Float().getPathIterator(null),
      9.2, 17);
    harness.check(fpi.getRecursionLimit(), 17);

    // Check 2 (in case it always returned 17)
    fpi = new FlatteningPathIterator(
      new Line2D.Float().getPathIterator(null), 2.1, 4);
    harness.check(fpi.getRecursionLimit(), 4);
  }
View Full Code Here

Examples of java.awt.geom.FlatteningPathIterator

    /**
     * {@inheritDoc}
     */
    public PathIterator getPathIterator(AffineTransform at, double flatness) {
        return new FlatteningPathIterator(getPathIterator(at), flatness);
    }
View Full Code Here

Examples of java.awt.geom.FlatteningPathIterator

    }

    @Override
    public Shape createStrokedShape( Shape shape ) {
        GeneralPath result = new GeneralPath();
        PathIterator it = new FlatteningPathIterator( shape.getPathIterator( null ), FLATNESS );
        float points[] = new float[6];
        float moveX = 0, moveY = 0;
        float lastX = 0, lastY = 0;
        float thisX = 0, thisY = 0;
        int type = 0;
        float next = 0;
        int currentShape = 0;
        int length = shapes.length;

        while ( currentShape < length && !it.isDone() ) {
            type = it.currentSegment( points );
            switch( type ){
            case PathIterator.SEG_MOVETO:
                moveX = lastX = points[0];
                moveY = lastY = points[1];
                result.moveTo( moveX, moveY );
                next = 0;
                break;

            case PathIterator.SEG_CLOSE:
                points[0] = moveX;
                points[1] = moveY;
                // Fall into....

            //$FALL-THROUGH$
            case PathIterator.SEG_LINETO:
                thisX = points[0];
                thisY = points[1];
                float dx = thisX-lastX;
                float dy = thisY-lastY;
                float distance = (float)Math.sqrt( dx*dx + dy*dy );
                if ( distance >= next ) {
                    float r = 1.0f/distance;
                    float angle = (float)Math.atan2( dy, dx );
                    while ( currentShape < length && distance >= next ) {
                        float x = lastX + next*dx*r;
                        float y = lastY + next*dy*r;
                        t.setToTranslation( x, y );
                        t.rotate( angle );
                        result.append( t.createTransformedShape( shapes[currentShape] ), false );
                        next += advance;
                        currentShape++;
                        if ( repeat )
                            currentShape %= length;
                    }
                }
                next -= distance;
                lastX = thisX;
                lastY = thisY;
                break;
            }
            it.next();
        }

        return result;
    }
View Full Code Here

Examples of java.awt.geom.FlatteningPathIterator

    public Shape createStrokedShape( Shape shape ) {
        FontRenderContext frc = new FontRenderContext(null, true, true);
        GlyphVector glyphVector = font.createGlyphVector(frc, text);

        GeneralPath result = new GeneralPath();
        PathIterator it = new FlatteningPathIterator( shape.getPathIterator( null ), FLATNESS );
        float points[] = new float[6];
        float moveX = 0, moveY = 0;
        float lastX = 0, lastY = 0;
        float thisX = 0, thisY = 0;
        int type = 0;
        float next = 0;
        int currentChar = 0;
        int length = glyphVector.getNumGlyphs();

        if ( length == 0 )
            return result;

        float factor = stretchToFit ? measurePathLength( shape )/(float)glyphVector.getLogicalBounds().getWidth() : 1.0f;
        float nextAdvance = 0;

        while ( currentChar < length && !it.isDone() ) {
            type = it.currentSegment( points );
            switch( type ){
            case PathIterator.SEG_MOVETO:
                moveX = lastX = points[0];
                moveY = lastY = points[1];
                result.moveTo( moveX, moveY );
                nextAdvance = glyphVector.getGlyphMetrics( currentChar ).getAdvance() * 0.5f;
                next = nextAdvance;
                break;

            case PathIterator.SEG_CLOSE:
                points[0] = moveX;
                points[1] = moveY;
                // Fall into....

                //$FALL-THROUGH$
            case PathIterator.SEG_LINETO:
                thisX = points[0];
                thisY = points[1];
                float dx = thisX-lastX;
                float dy = thisY-lastY;
                float distance = (float)Math.sqrt( dx*dx + dy*dy );
                if ( distance >= next ) {
                    float r = 1.0f/distance;
                    float angle = (float)Math.atan2( dy, dx );
                    while ( currentChar < length && distance >= next ) {
                        Shape glyph = glyphVector.getGlyphOutline( currentChar );
                        Point2D p = glyphVector.getGlyphPosition(currentChar);
                        float px = (float)p.getX();
                        float py = (float)p.getY();
                        float x = lastX + next*dx*r;
                        float y = lastY + next*dy*r;
                        float advance = nextAdvance;
                        nextAdvance = currentChar < length-1 ? glyphVector.getGlyphMetrics(currentChar+1).getAdvance() * 0.5f : 0;
                        t.setToTranslation( x, y );
                        t.rotate( angle );
                        t.translate( -px-advance, -py );
                        result.append( t.createTransformedShape( glyph ), false );
                        next += (advance+nextAdvance) * factor;
                        currentChar++;
                        if ( repeat )
                            currentChar %= length;
                    }
                }
                next -= distance;
                lastX = thisX;
                lastY = thisY;
                break;
            }
            it.next();
        }

        return result;
    }
View Full Code Here

Examples of java.awt.geom.FlatteningPathIterator

        return result;
    }

    public float measurePathLength( Shape shape ) {
        PathIterator it = new FlatteningPathIterator( shape.getPathIterator( null ), FLATNESS );
        float points[] = new float[6];
        float moveX = 0, moveY = 0;
        float lastX = 0, lastY = 0;
        float thisX = 0, thisY = 0;
        int type = 0;
        float total = 0;

        while ( !it.isDone() ) {
            type = it.currentSegment( points );
            switch( type ){
            case PathIterator.SEG_MOVETO:
                moveX = lastX = points[0];
                moveY = lastY = points[1];
                break;

            case PathIterator.SEG_CLOSE:
                points[0] = moveX;
                points[1] = moveY;
                // Fall into....

                //$FALL-THROUGH$
            case PathIterator.SEG_LINETO:
                thisX = points[0];
                thisY = points[1];
                float dx = thisX-lastX;
                float dy = thisY-lastY;
                total += (float)Math.sqrt( dx*dx + dy*dy );
                lastX = thisX;
                lastY = thisY;
                break;
            }
            it.next();
        }

        return total;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.