Java Code Examples for java.awt.geom.PathIterator#isDone()

The following examples show how to use java.awt.geom.PathIterator#isDone() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LayoutPathImpl.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
public Shape mapShape(Shape s) {
    if (LOGMAP) LOG.format("mapshape on path: %s\n", LayoutPathImpl.SegmentPath.this);
    PathIterator pi = s.getPathIterator(null, 1); // cheap way to handle curves.

    if (LOGMAP) LOG.format("start\n");
    init();

    final double[] coords = new double[2];
    while (!pi.isDone()) {
        switch (pi.currentSegment(coords)) {
        case SEG_CLOSE: close(); break;
        case SEG_MOVETO: moveTo(coords[0], coords[1]); break;
        case SEG_LINETO: lineTo(coords[0], coords[1]); break;
        default: break;
        }

        pi.next();
    }
    if (LOGMAP) LOG.format("finish\n\n");

    GeneralPath gp = new GeneralPath();
    for (Segment seg: segments) {
        gp.append(seg.gp, false);
    }
    return gp;
}
 
Example 2
Source File: ChartEntity.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns a string containing the coordinates for a given shape.  This
 * string is intended for use in an image map.
 *
 * @param shape  the shape (<code>null</code> not permitted).
 *
 * @return The coordinates for a given shape as string.
 */
private String getPolyCoords(Shape shape) {
    ParamChecks.nullNotPermitted(shape, "shape");
    StringBuilder result = new StringBuilder();
    boolean first = true;
    float[] coords = new float[6];
    PathIterator pi = shape.getPathIterator(null, 1.0);
    while (!pi.isDone()) {
        pi.currentSegment(coords);
        if (first) {
            first = false;
            result.append((int) coords[0]);
            result.append(",").append((int) coords[1]);
        }
        else {
            result.append(",");
            result.append((int) coords[0]);
            result.append(",");
            result.append((int) coords[1]);
        }
        pi.next();
    }
    return result.toString();
}
 
Example 3
Source File: MainPanel.java    From java-swing-tips with MIT License 6 votes vote down vote up
@Override public void paintIcon(Component c, Graphics g, int x, int y) {
  Graphics2D g2 = (Graphics2D) g.create();
  g2.translate(x, y);
  g2.setPaint(Color.BLACK);
  g2.draw(shape);
  g2.setPaint(Color.RED);

  PathIterator i = new FlatteningPathIterator(shape.getPathIterator(null), 1d);
  double[] coords = new double[6];
  while (!i.isDone()) {
    i.currentSegment(coords);
    g2.fillRect((int) (coords[0] - .5), (int) (coords[1] - .5), 2, 2);
    i.next();
  }
  g2.dispose();
}
 
Example 4
Source File: LayoutPathImpl.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
public Shape mapShape(Shape s) {
    if (LOGMAP) LOG.format("mapshape on path: %s\n", LayoutPathImpl.SegmentPath.this);
    PathIterator pi = s.getPathIterator(null, 1); // cheap way to handle curves.

    if (LOGMAP) LOG.format("start\n");
    init();

    final double[] coords = new double[2];
    while (!pi.isDone()) {
        switch (pi.currentSegment(coords)) {
        case SEG_CLOSE: close(); break;
        case SEG_MOVETO: moveTo(coords[0], coords[1]); break;
        case SEG_LINETO: lineTo(coords[0], coords[1]); break;
        default: break;
        }

        pi.next();
    }
    if (LOGMAP) LOG.format("finish\n\n");

    GeneralPath gp = new GeneralPath();
    for (Segment seg: segments) {
        gp.append(seg.gp, false);
    }
    return gp;
}
 
Example 5
Source File: Path2DCopyConstructor.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
static void testIterator(Path2D pathA, Path2D pathB) {
    final PathIterator itA = pathA.getPathIterator(at);
    final PathIterator itB = pathB.getPathIterator(at);

    float[] coordsA = new float[6];
    float[] coordsB = new float[6];

    int n = 0;
    for (; !itA.isDone() && !itB.isDone(); itA.next(), itB.next(), n++) {
        int typeA = itA.currentSegment(coordsA);
        int typeB = itB.currentSegment(coordsB);

        if (typeA != typeB) {
            throw new IllegalStateException("Path-segment[" + n + "] "
                + "type are not equals [" + typeA + "|" + typeB + "] !");
        }
        // Take care of floating-point precision:
        if (!equalsArrayEps(coordsA, coordsB, getLength(typeA))) {
            throw new IllegalStateException("Path-segment[" + n + "] coords"
                + " are not equals [" + Arrays.toString(coordsA) + "|"
                + Arrays.toString(coordsB) + "] !");
        }
    }
    if (!itA.isDone() || !itB.isDone()) {
        throw new IllegalStateException("Paths do not have same lengths !");
    }
    log("testIterator: " + n + " segments.");
}
 
Example 6
Source File: ShapeReader.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static Coordinate[] nextCoordinateArray(PathIterator pathIt)
{
  double[] pathPt = new double[6];
  CoordinateList coordList = null;
  boolean isDone = false;
  while (! pathIt.isDone()) {
    int segType = pathIt.currentSegment(pathPt);
    switch (segType) {
    case PathIterator.SEG_MOVETO:
      if (coordList != null) {
        // don't advance pathIt, to retain start of next path if any
        isDone = true;
      }
      else {
        coordList = new CoordinateList();
        coordList.add(new Coordinate(pathPt[0], pathPt[1]));
        pathIt.next();
      }
      break;
    case PathIterator.SEG_LINETO:
      coordList.add(new Coordinate(pathPt[0], pathPt[1]));
      pathIt.next();
      break;
    case PathIterator.SEG_CLOSE:  
      coordList.closeRing();
      pathIt.next();
      isDone = true;   
      break;
    default:
    	throw new IllegalArgumentException("unhandled (non-linear) segment type encountered");
    }
    if (isDone) 
      break;
  }
  return coordList.toCoordinateArray();
}
 
Example 7
Source File: SWTGraphics2D.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Converts an AWT <code>Shape</code> into a SWT <code>Path</code>.
 *
 * @param shape  the shape (<code>null</code> not permitted).
 *
 * @return The path.
 */
private Path toSwtPath(Shape shape) {
    int type;
    float[] coords = new float[6];
    Path path = new Path(this.gc.getDevice());
    PathIterator pit = shape.getPathIterator(null);
    while (!pit.isDone()) {
        type = pit.currentSegment(coords);
        switch (type) {
            case (PathIterator.SEG_MOVETO):
                path.moveTo(coords[0], coords[1]);
                break;
            case (PathIterator.SEG_LINETO):
                path.lineTo(coords[0], coords[1]);
                break;
            case (PathIterator.SEG_QUADTO):
                path.quadTo(coords[0], coords[1], coords[2], coords[3]);
                break;
            case (PathIterator.SEG_CUBICTO):
                path.cubicTo(coords[0], coords[1], coords[2],
                        coords[3], coords[4], coords[5]);
                break;
            case (PathIterator.SEG_CLOSE):
                path.close();
                break;
            default:
                break;
        }
        pit.next();
    }
    return path;
}
 
Example 8
Source File: Path2DCopyConstructor.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
static void testFlattening(Path2D pathA, Path2D pathB) {
    final PathIterator itA = pathA.getPathIterator(at, FLATNESS);
    final PathIterator itB = pathB.getPathIterator(at, FLATNESS);

    float[] coordsA = new float[6];
    float[] coordsB = new float[6];

    int n = 0;
    for (; !itA.isDone() && !itB.isDone(); itA.next(), itB.next(), n++) {
        int typeA = itA.currentSegment(coordsA);
        int typeB = itB.currentSegment(coordsB);

        if (typeA != typeB) {
            throw new IllegalStateException("Path-segment[" + n + "] "
                + "type are not equals [" + typeA + "|" + typeB + "] !");
        }
        // Take care of floating-point precision:
        if (!equalsArrayEps(coordsA, coordsB, getLength(typeA))) {
            throw new IllegalStateException("Path-segment[" + n + "] coords"
                + " are not equals [" + Arrays.toString(coordsA) + "|"
                + Arrays.toString(coordsB) + "] !");
        }
    }
    if (!itA.isDone() || !itB.isDone()) {
        throw new IllegalStateException("Paths do not have same lengths !");
    }
    log("testFlattening: " + n + " segments.");
}
 
Example 9
Source File: Chart_11_ShapeUtilities_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Tests two polygons for equality.  If both are <code>null</code> this
 * method returns <code>true</code>.
 *
 * @param p1  path 1 (<code>null</code> permitted).
 * @param p2  path 2 (<code>null</code> permitted).
 *
 * @return A boolean.
 */
public static boolean equal(GeneralPath p1, GeneralPath p2) {
    if (p1 == null) {
        return (p2 == null);
    }
    if (p2 == null) {
        return false;
    }
    if (p1.getWindingRule() != p2.getWindingRule()) {
        return false;
    }
    PathIterator iterator1 = p1.getPathIterator(null);
    PathIterator iterator2 = p1.getPathIterator(null);
    double[] d1 = new double[6];
    double[] d2 = new double[6];
    boolean done = iterator1.isDone() && iterator2.isDone();
    while (!done) {
        if (iterator1.isDone() != iterator2.isDone()) {
            return false;
        }
        int seg1 = iterator1.currentSegment(d1);
        int seg2 = iterator2.currentSegment(d2);
        if (seg1 != seg2) {
            return false;
        }
        if (!Arrays.equals(d1, d2)) {
            return false;
        }
        iterator1.next();
        iterator2.next();
        done = iterator1.isDone() && iterator2.isDone();
    }
    return true;
}
 
Example 10
Source File: ShapeUtilities.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Tests two polygons for equality.  If both are <code>null</code> this
 * method returns <code>true</code>.
 *
 * @param p1  path 1 (<code>null</code> permitted).
 * @param p2  path 2 (<code>null</code> permitted).
 *
 * @return A boolean.
 */
public static boolean equal(GeneralPath p1, GeneralPath p2) {
    if (p1 == null) {
        return (p2 == null);
    }
    if (p2 == null) {
        return false;
    }
    if (p1.getWindingRule() != p2.getWindingRule()) {
        return false;
    }
    PathIterator iterator1 = p1.getPathIterator(null);
    PathIterator iterator2 = p1.getPathIterator(null);
    double[] d1 = new double[6];
    double[] d2 = new double[6];
    boolean done = iterator1.isDone() && iterator2.isDone();
    while (!done) {
        if (iterator1.isDone() != iterator2.isDone()) {
            return false;
        }
        int seg1 = iterator1.currentSegment(d1);
        int seg2 = iterator2.currentSegment(d2);
        if (seg1 != seg2) {
            return false;
        }
        if (!Arrays.equals(d1, d2)) {
            return false;
        }
        iterator1.next();
        iterator2.next();
        done = iterator1.isDone() && iterator2.isDone();
    }
    return true;
}
 
Example 11
Source File: SWTGraphics2D.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Converts an AWT <code>Shape</code> into a SWT <code>Path</code>.
 *
 * @param shape  the shape (<code>null</code> not permitted).
 *
 * @return The path.
 */
private Path toSwtPath(Shape shape) {
    int type;
    float[] coords = new float[6];
    Path path = new Path(this.gc.getDevice());
    PathIterator pit = shape.getPathIterator(null);
    while (!pit.isDone()) {
        type = pit.currentSegment(coords);
        switch (type) {
            case (PathIterator.SEG_MOVETO):
                path.moveTo(coords[0], coords[1]);
                break;
            case (PathIterator.SEG_LINETO):
                path.lineTo(coords[0], coords[1]);
                break;
            case (PathIterator.SEG_QUADTO):
                path.quadTo(coords[0], coords[1], coords[2], coords[3]);
                break;
            case (PathIterator.SEG_CUBICTO):
                path.cubicTo(coords[0], coords[1], coords[2],
                        coords[3], coords[4], coords[5]);
                break;
            case (PathIterator.SEG_CLOSE):
                path.close();
                break;
            default:
                break;
        }
        pit.next();
    }
    return path;
}
 
Example 12
Source File: ShapeReader.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Extracts the points of the paths in a flat {@link PathIterator} into
 * a list of Coordinate arrays.
 * 
 * @param pathIt a path iterator
 * @return a List of Coordinate arrays
 * @throws IllegalArgumentException if a non-linear segment type is encountered
 */
public static List toCoordinates(PathIterator pathIt)
{
  List coordArrays = new ArrayList();
  while (! pathIt.isDone()) {
    Coordinate[] pts = nextCoordinateArray(pathIt);
    if (pts == null)
      break;
    coordArrays.add(pts);
  }
  return coordArrays;
}
 
Example 13
Source File: Cardumen_009_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Converts a path from Java2D space to data space.
 *
 * @param path  the path (<code>null</code> not permitted).
 * @param dataArea  the data area.
 * @param dataset  the dataset which can be used to find the appropriate
 *         axes.
 *
 * @return A path in data space.
 */
private GeneralPath convertToDataSpace(GeneralPath path,
        Rectangle2D dataArea, XYDataset dataset) {
    GeneralPath result = new GeneralPath(path.getWindingRule());
    int datasetIndex = indexOf(dataset);
    ValueAxis xAxis = getDomainAxisForDataset(datasetIndex);
    ValueAxis yAxis = getRangeAxisForDataset(datasetIndex);
    RectangleEdge xAxisEdge = getDomainAxisEdge();
    RectangleEdge yAxisEdge = getRangeAxisEdge();
    double[] coords = new double[6];
    PathIterator iterator = path.getPathIterator(null);
    while (!iterator.isDone()) {
        int segType = iterator.currentSegment(coords);
        double xx = xAxis.java2DToValue(coords[0], dataArea, xAxisEdge);
        double yy = yAxis.java2DToValue(coords[1], dataArea, yAxisEdge);
        if (segType == PathIterator.SEG_MOVETO) {
            result.moveTo((float) xx, (float) yy);
        }
        else if (segType == PathIterator.SEG_LINETO) {
            result.lineTo((float) xx, (float) yy);
        }
        else if (segType == PathIterator.SEG_CLOSE) {
            result.closePath();
        }
        iterator.next();
    }
    return result;
}
 
Example 14
Source File: Cardumen_009_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Converts a path from Java2D space to data space.
 *
 * @param path  the path (<code>null</code> not permitted).
 * @param dataArea  the data area.
 * @param dataset  the dataset which can be used to find the appropriate
 *         axes.
 *
 * @return A path in data space.
 */
private GeneralPath convertToDataSpace(GeneralPath path,
        Rectangle2D dataArea, XYDataset dataset) {
    GeneralPath result = new GeneralPath(path.getWindingRule());
    int datasetIndex = indexOf(dataset);
    ValueAxis xAxis = getDomainAxisForDataset(datasetIndex);
    ValueAxis yAxis = getRangeAxisForDataset(datasetIndex);
    RectangleEdge xAxisEdge = getDomainAxisEdge();
    RectangleEdge yAxisEdge = getRangeAxisEdge();
    double[] coords = new double[6];
    PathIterator iterator = path.getPathIterator(null);
    while (!iterator.isDone()) {
        int segType = iterator.currentSegment(coords);
        double xx = xAxis.java2DToValue(coords[0], dataArea, xAxisEdge);
        double yy = yAxis.java2DToValue(coords[1], dataArea, yAxisEdge);
        if (segType == PathIterator.SEG_MOVETO) {
            result.moveTo((float) xx, (float) yy);
        }
        else if (segType == PathIterator.SEG_LINETO) {
            result.lineTo((float) xx, (float) yy);
        }
        else if (segType == PathIterator.SEG_CLOSE) {
            result.closePath();
        }
        iterator.next();
    }
    return result;
}
 
Example 15
Source File: PSPrinterJob.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
* Given a Java2D <code>PathIterator</code> instance,
* this method translates that into a PostScript path..
*/
void convertToPSPath(PathIterator pathIter) {

    float[] segment = new float[6];
    int segmentType;

    /* Map the PathIterator's fill rule into the PostScript
     * fill rule.
     */
    int fillRule;
    if (pathIter.getWindingRule() == PathIterator.WIND_EVEN_ODD) {
        fillRule = FILL_EVEN_ODD;
    } else {
        fillRule = FILL_WINDING;
    }

    beginPath();

    setFillMode(fillRule);

    while (pathIter.isDone() == false) {
        segmentType = pathIter.currentSegment(segment);

        switch (segmentType) {
         case PathIterator.SEG_MOVETO:
            moveTo(segment[0], segment[1]);
            break;

         case PathIterator.SEG_LINETO:
            lineTo(segment[0], segment[1]);
            break;

        /* Convert the quad path to a bezier.
         */
         case PathIterator.SEG_QUADTO:
            float lastX = getPenX();
            float lastY = getPenY();
            float c1x = lastX + (segment[0] - lastX) * 2 / 3;
            float c1y = lastY + (segment[1] - lastY) * 2 / 3;
            float c2x = segment[2] - (segment[2] - segment[0]) * 2/ 3;
            float c2y = segment[3] - (segment[3] - segment[1]) * 2/ 3;
            bezierTo(c1x, c1y,
                     c2x, c2y,
                     segment[2], segment[3]);
            break;

         case PathIterator.SEG_CUBICTO:
            bezierTo(segment[0], segment[1],
                     segment[2], segment[3],
                     segment[4], segment[5]);
            break;

         case PathIterator.SEG_CLOSE:
            closeSubpath();
            break;
        }


        pathIter.next();
    }
}
 
Example 16
Source File: WPathGraphics.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Given a Java2D {@code PathIterator} instance,
 * this method translates that into a Window's path
 * in the printer device context.
 */
private void convertToWPath(PathIterator pathIter) {

    float[] segment = new float[6];
    int segmentType;

    WPrinterJob wPrinterJob = (WPrinterJob) getPrinterJob();

    /* Map the PathIterator's fill rule into the Window's
     * polygon fill rule.
     */
    int polyFillRule;
    if (pathIter.getWindingRule() == PathIterator.WIND_EVEN_ODD) {
        polyFillRule = WPrinterJob.POLYFILL_ALTERNATE;
    } else {
        polyFillRule = WPrinterJob.POLYFILL_WINDING;
    }
    wPrinterJob.setPolyFillMode(polyFillRule);

    wPrinterJob.beginPath();

    while (pathIter.isDone() == false) {
        segmentType = pathIter.currentSegment(segment);

        switch (segmentType) {
         case PathIterator.SEG_MOVETO:
            wPrinterJob.moveTo(segment[0], segment[1]);
            break;

         case PathIterator.SEG_LINETO:
            wPrinterJob.lineTo(segment[0], segment[1]);
            break;

        /* Convert the quad path to a bezier.
         */
         case PathIterator.SEG_QUADTO:
            int lastX = wPrinterJob.getPenX();
            int lastY = wPrinterJob.getPenY();
            float c1x = lastX + (segment[0] - lastX) * 2 / 3;
            float c1y = lastY + (segment[1] - lastY) * 2 / 3;
            float c2x = segment[2] - (segment[2] - segment[0]) * 2/ 3;
            float c2y = segment[3] - (segment[3] - segment[1]) * 2/ 3;
            wPrinterJob.polyBezierTo(c1x, c1y,
                                     c2x, c2y,
                                     segment[2], segment[3]);
            break;

         case PathIterator.SEG_CUBICTO:
            wPrinterJob.polyBezierTo(segment[0], segment[1],
                                     segment[2], segment[3],
                                     segment[4], segment[5]);
            break;

         case PathIterator.SEG_CLOSE:
            wPrinterJob.closeFigure();
            break;
        }


        pathIter.next();
    }

    wPrinterJob.endPath();

}
 
Example 17
Source File: Curve.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Calculates the number of times the given path
 * crosses the ray extending to the right from (px,py).
 * If the point lies on a part of the path,
 * then no crossings are counted for that intersection.
 * +1 is added for each crossing where the Y coordinate is increasing
 * -1 is added for each crossing where the Y coordinate is decreasing
 * The return value is the sum of all crossings for every segment in
 * the path.
 * The path must start with a SEG_MOVETO, otherwise an exception is
 * thrown.
 * The caller must check p[xy] for NaN values.
 * The caller may also reject infinite p[xy] values as well.
 */
public static int pointCrossingsForPath(PathIterator pi,
                                        double px, double py)
{
    if (pi.isDone()) {
        return 0;
    }
    double coords[] = new double[6];
    if (pi.currentSegment(coords) != PathIterator.SEG_MOVETO) {
        throw new IllegalPathStateException("missing initial moveto "+
                                            "in path definition");
    }
    pi.next();
    double movx = coords[0];
    double movy = coords[1];
    double curx = movx;
    double cury = movy;
    double endx, endy;
    int crossings = 0;
    while (!pi.isDone()) {
        switch (pi.currentSegment(coords)) {
        case PathIterator.SEG_MOVETO:
            if (cury != movy) {
                crossings += pointCrossingsForLine(px, py,
                                                   curx, cury,
                                                   movx, movy);
            }
            movx = curx = coords[0];
            movy = cury = coords[1];
            break;
        case PathIterator.SEG_LINETO:
            endx = coords[0];
            endy = coords[1];
            crossings += pointCrossingsForLine(px, py,
                                               curx, cury,
                                               endx, endy);
            curx = endx;
            cury = endy;
            break;
        case PathIterator.SEG_QUADTO:
            endx = coords[2];
            endy = coords[3];
            crossings += pointCrossingsForQuad(px, py,
                                               curx, cury,
                                               coords[0], coords[1],
                                               endx, endy, 0);
            curx = endx;
            cury = endy;
            break;
        case PathIterator.SEG_CUBICTO:
            endx = coords[4];
            endy = coords[5];
            crossings += pointCrossingsForCubic(px, py,
                                                curx, cury,
                                                coords[0], coords[1],
                                                coords[2], coords[3],
                                                endx, endy, 0);
            curx = endx;
            cury = endy;
            break;
        case PathIterator.SEG_CLOSE:
            if (cury != movy) {
                crossings += pointCrossingsForLine(px, py,
                                                   curx, cury,
                                                   movx, movy);
            }
            curx = movx;
            cury = movy;
            break;
        }
        pi.next();
    }
    if (cury != movy) {
        crossings += pointCrossingsForLine(px, py,
                                           curx, cury,
                                           movx, movy);
    }
    return crossings;
}
 
Example 18
Source File: Crossings.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
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;
}
 
Example 19
Source File: WPathGraphics.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Given a Java2D <code>PathIterator</code> instance,
 * this method translates that into a Window's path
 * in the printer device context.
 */
private void convertToWPath(PathIterator pathIter) {

    float[] segment = new float[6];
    int segmentType;

    WPrinterJob wPrinterJob = (WPrinterJob) getPrinterJob();

    /* Map the PathIterator's fill rule into the Window's
     * polygon fill rule.
     */
    int polyFillRule;
    if (pathIter.getWindingRule() == PathIterator.WIND_EVEN_ODD) {
        polyFillRule = WPrinterJob.POLYFILL_ALTERNATE;
    } else {
        polyFillRule = WPrinterJob.POLYFILL_WINDING;
    }
    wPrinterJob.setPolyFillMode(polyFillRule);

    wPrinterJob.beginPath();

    while (pathIter.isDone() == false) {
        segmentType = pathIter.currentSegment(segment);

        switch (segmentType) {
         case PathIterator.SEG_MOVETO:
            wPrinterJob.moveTo(segment[0], segment[1]);
            break;

         case PathIterator.SEG_LINETO:
            wPrinterJob.lineTo(segment[0], segment[1]);
            break;

        /* Convert the quad path to a bezier.
         */
         case PathIterator.SEG_QUADTO:
            int lastX = wPrinterJob.getPenX();
            int lastY = wPrinterJob.getPenY();
            float c1x = lastX + (segment[0] - lastX) * 2 / 3;
            float c1y = lastY + (segment[1] - lastY) * 2 / 3;
            float c2x = segment[2] - (segment[2] - segment[0]) * 2/ 3;
            float c2y = segment[3] - (segment[3] - segment[1]) * 2/ 3;
            wPrinterJob.polyBezierTo(c1x, c1y,
                                     c2x, c2y,
                                     segment[2], segment[3]);
            break;

         case PathIterator.SEG_CUBICTO:
            wPrinterJob.polyBezierTo(segment[0], segment[1],
                                     segment[2], segment[3],
                                     segment[4], segment[5]);
            break;

         case PathIterator.SEG_CLOSE:
            wPrinterJob.closeFigure();
            break;
        }


        pathIter.next();
    }

    wPrinterJob.endPath();

}
 
Example 20
Source File: PdfGraphics2D.java    From gcs with Mozilla Public License 2.0 4 votes vote down vote up
private void followPath(Shape s, int drawType) {
	if (s == null) {
		return;
	}
	if (drawType == STROKE) {
		if (!(stroke instanceof BasicStroke)) {
			s = stroke.createStrokedShape(s);
			followPath(s, FILL);
			return;
		}
	}
	if (drawType == STROKE) {
		setStrokeDiff(stroke, oldStroke);
		oldStroke = stroke;
		setStrokePaint();
	} else if (drawType == FILL) {
		setFillPaint();
	}
	PathIterator points;
	int traces = 0;
	if (drawType == CLIP) {
		points = s.getPathIterator(IDENTITY);
	} else {
		points = s.getPathIterator(transform);
	}
	float[] coords = new float[6];
	while (!points.isDone()) {
		++traces;
		int segtype = points.currentSegment(coords);
		normalizeY(coords);
		switch (segtype) {
			case PathIterator.SEG_CLOSE:
				cb.closePath();
				break;

			case PathIterator.SEG_CUBICTO:
				cb.curveTo(coords[0], coords[1], coords[2], coords[3], coords[4], coords[5]);
				break;

			case PathIterator.SEG_LINETO:
				cb.lineTo(coords[0], coords[1]);
				break;

			case PathIterator.SEG_MOVETO:
				cb.moveTo(coords[0], coords[1]);
				break;

			case PathIterator.SEG_QUADTO:
				cb.curveTo(coords[0], coords[1], coords[2], coords[3]);
				break;
		}
		points.next();
	}
	switch (drawType) {
		case FILL:
			if (traces > 0) {
				if (points.getWindingRule() == PathIterator.WIND_EVEN_ODD) {
					cb.eoFill();
				} else {
					cb.fill();
				}
			}
			break;
		case STROKE:
			if (traces > 0) {
				cb.stroke();
			}
			break;
		default: // drawType==CLIP
			if (traces == 0) {
				cb.rectangle(0, 0, 0, 0);
			}
			if (points.getWindingRule() == PathIterator.WIND_EVEN_ODD) {
				cb.eoClip();
			} else {
				cb.clip();
			}
			cb.newPath();
	}
}