コード例 #1
0
  private Path convertAwtPathToAndroid(PathIterator pi) {
    Path path = new Path();
    float[] coords = new float[6];
    while (!pi.isDone()) {
      int windingRule = pi.getWindingRule();

      if (windingRule == PathIterator.WIND_EVEN_ODD) {
        path.setFillType(Path.FillType.EVEN_ODD);
      } else {
        path.setFillType(Path.FillType.WINDING);
      }

      int pathType = pi.currentSegment(coords);

      switch (pathType) {
        case PathIterator.SEG_CLOSE:
          path.close();
          break;
        case PathIterator.SEG_CUBICTO:
          path.cubicTo(coords[0], coords[1], coords[2], coords[3], coords[4], coords[5]);
          break;
        case PathIterator.SEG_LINETO:
          path.lineTo(coords[0], coords[1]);
          break;
        case PathIterator.SEG_MOVETO:
          path.moveTo(coords[0], coords[1]);
          break;
        case PathIterator.SEG_QUADTO:
          path.quadTo(coords[0], coords[1], coords[2], coords[3]);
          break;
      }

      pi.next();
    }
    return path;
  }
コード例 #2
0
ファイル: Crossings.java プロジェクト: riyol/POI-Android
 public static Crossings findCrossings(
     PathIterator pi, double xlo, double ylo, double xhi, double yhi) {
   Crossings cross;
   if (pi.getWindingRule() == pi.WIND_EVEN_ODD) {
     cross = new EvenOdd(xlo, ylo, xhi, yhi);
   } else {
     cross = new NonZero(xlo, ylo, xhi, yhi);
   }
   // coords array is big enough for holding:
   //     coordinates returned from currentSegment (6)
   //     OR
   //         two subdivided quadratic curves (2+4+4=10)
   //         AND
   //             0-1 horizontal splitting parameters
   //             OR
   //             2 parametric equation derivative coefficients
   //     OR
   //         three subdivided cubic curves (2+6+6+6=20)
   //         AND
   //             0-2 horizontal splitting parameters
   //             OR
   //             3 parametric equation derivative coefficients
   double coords[] = new double[23];
   double movx = 0;
   double movy = 0;
   double curx = 0;
   double cury = 0;
   double newx, newy;
   while (!pi.isDone()) {
     int type = pi.currentSegment(coords);
     switch (type) {
       case PathIterator.SEG_MOVETO:
         if (movy != cury && cross.accumulateLine(curx, cury, movx, movy)) {
           return null;
         }
         movx = curx = coords[0];
         movy = cury = coords[1];
         break;
       case PathIterator.SEG_LINETO:
         newx = coords[0];
         newy = coords[1];
         if (cross.accumulateLine(curx, cury, newx, newy)) {
           return null;
         }
         curx = newx;
         cury = newy;
         break;
       case PathIterator.SEG_QUADTO:
         newx = coords[2];
         newy = coords[3];
         if (cross.accumulateQuad(curx, cury, coords)) {
           return null;
         }
         curx = newx;
         cury = newy;
         break;
       case PathIterator.SEG_CUBICTO:
         newx = coords[4];
         newy = coords[5];
         if (cross.accumulateCubic(curx, cury, coords)) {
           return null;
         }
         curx = newx;
         cury = newy;
         break;
       case PathIterator.SEG_CLOSE:
         if (movy != cury && cross.accumulateLine(curx, cury, movx, movy)) {
           return null;
         }
         curx = movx;
         cury = movy;
         break;
     }
     pi.next();
   }
   if (movy != cury) {
     if (cross.accumulateLine(curx, cury, movx, movy)) {
       return null;
     }
   }
   if (debug) {
     cross.print();
   }
   return cross;
 }