/**
  * Utility method to feed a {@link PathConsumer2D} object from a given {@link PathIterator}. This
  * method deals with the details of running the iterator and feeding the consumer a segment at a
  * time.
  */
 public static void feedConsumer(PathIterator pi, PathConsumer2D consumer) {
   float coords[] = new float[6];
   while (!pi.isDone()) {
     switch (pi.currentSegment(coords)) {
       case PathIterator.SEG_MOVETO:
         consumer.moveTo(coords[0], coords[1]);
         break;
       case PathIterator.SEG_LINETO:
         consumer.lineTo(coords[0], coords[1]);
         break;
       case PathIterator.SEG_QUADTO:
         consumer.quadTo(
             coords[0], coords[1],
             coords[2], coords[3]);
         break;
       case PathIterator.SEG_CUBICTO:
         consumer.curveTo(
             coords[0], coords[1],
             coords[2], coords[3],
             coords[4], coords[5]);
         break;
       case PathIterator.SEG_CLOSE:
         consumer.closePath();
         break;
     }
     pi.next();
   }
 }
Beispiel #2
0
 public void pathDone() {
   if (firstSegidx > 0) {
     out.moveTo(sx, sy);
     emitFirstSegments();
   }
   out.pathDone();
 }
Beispiel #3
0
 public void closePath() {
   lineTo(sx, sy);
   if (firstSegidx > 0) {
     if (!dashOn || needsMoveTo) {
       out.moveTo(sx, sy);
     }
     emitFirstSegments();
   }
   moveTo(sx, sy);
 }
Beispiel #4
0
 public void moveTo(float x0, float y0) {
   if (firstSegidx > 0) {
     out.moveTo(sx, sy);
     emitFirstSegments();
   }
   needsMoveTo = true;
   this.idx = startIdx;
   this.dashOn = this.startDashOn;
   this.phase = this.startPhase;
   this.sx = this.x0 = x0;
   this.sy = this.y0 = y0;
   this.starting = true;
 }
Beispiel #5
0
 // precondition: pts must be in relative coordinates (relative to x0,y0)
 // fullCurve is true iff the curve in pts has not been split.
 private void goTo(float[] pts, int off, final int type) {
   float x = pts[off + type - 4];
   float y = pts[off + type - 3];
   if (dashOn) {
     if (starting) {
       firstSegmentsBuffer = Helpers.widenArray(firstSegmentsBuffer, firstSegidx, type - 2);
       firstSegmentsBuffer[firstSegidx++] = type;
       System.arraycopy(pts, off, firstSegmentsBuffer, firstSegidx, type - 2);
       firstSegidx += type - 2;
     } else {
       if (needsMoveTo) {
         out.moveTo(x0, y0);
         needsMoveTo = false;
       }
       emitSeg(pts, off, type);
     }
   } else {
     starting = false;
     needsMoveTo = true;
   }
   this.x0 = x;
   this.y0 = y;
 }