Ejemplo n.º 1
0
 /**
  * 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();
   }
 }
Ejemplo n.º 2
0
 public void pathDone() {
   if (firstSegidx > 0) {
     out.moveTo(sx, sy);
     emitFirstSegments();
   }
   out.pathDone();
 }
Ejemplo n.º 3
0
 public void strokeTo(
     Shape src,
     AffineTransform at,
     BasicStroke bs,
     boolean thin,
     boolean normalize,
     boolean antialias,
     PathConsumer2D consumer) {
   System.out.println(
       name
           + ".strokeTo("
           + src.getClass().getName()
           + ", "
           + at
           + ", "
           + bs
           + ", "
           + (thin ? "thin" : "wide")
           + ", "
           + (normalize ? "normalized" : "pure")
           + ", "
           + (antialias ? "AA" : "non-AA")
           + ", "
           + consumer.getClass().getName()
           + ")");
   target.strokeTo(src, at, bs, thin, normalize, antialias, consumer);
 }
Ejemplo n.º 4
0
 private void emitSeg(float[] buf, int off, int type) {
   switch (type) {
     case 8:
       out.curveTo(
           buf[off + 0], buf[off + 1],
           buf[off + 2], buf[off + 3],
           buf[off + 4], buf[off + 5]);
       break;
     case 6:
       out.quadTo(
           buf[off + 0], buf[off + 1],
           buf[off + 2], buf[off + 3]);
       break;
     case 4:
       out.lineTo(buf[off], buf[off + 1]);
   }
 }
Ejemplo n.º 5
0
 public void closePath() {
   lineTo(sx, sy);
   if (firstSegidx > 0) {
     if (!dashOn || needsMoveTo) {
       out.moveTo(sx, sy);
     }
     emitFirstSegments();
   }
   moveTo(sx, sy);
 }
Ejemplo n.º 6
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;
 }
Ejemplo n.º 7
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;
 }