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

The following examples show how to use java.awt.geom.PathIterator#next() . 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: CommandLayer.java    From rcrs-server with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void drawArea(Area area) {
	PathIterator iter = area.getPathIterator(null);
	Path2D.Float poly = new Path2D.Float();
	double[] firstPoint = null;
	while (!iter.isDone()) {
		double point[] = new double[2]; // x, y
		int type = iter.currentSegment(point);
        point[0] = t.xToScreen(point[0]);
        point[1] = t.yToScreen(point[1]);
		if (type == PathIterator.SEG_MOVETO) {
			firstPoint = point;
			poly.moveTo(point[0], point[1]);
		} else if (type == PathIterator.SEG_CLOSE) {
			poly.lineTo(firstPoint[0], firstPoint[1]);
			g.draw(poly);
			poly.reset();
		} else {
			poly.lineTo(point[0], point[1]);
		}
		iter.next();
	}
}
 
Example 2
Source File: LayoutPathImpl.java    From dragonwell8_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 3
Source File: GeoPath.java    From audiveris with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Report the last defining point of the path.
 *
 * @return the last path point
 */
public Point2D getLastPoint ()
{
    final double[] buffer = new double[6];
    final PathIterator it = getPathIterator(null);

    if (it.isDone()) {
        return null;
    }

    double x = 0;
    double y = 0;

    while (!it.isDone()) {
        final int segmentKind = it.currentSegment(buffer);
        final int count = countOf(segmentKind);
        x = buffer[count - 2];
        y = buffer[count - 1];
        it.next();
    }

    return new Point2D.Double(x, y);
}
 
Example 4
Source File: LayoutPathImpl.java    From jdk8u-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 5
Source File: ShapeSpanIterator.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void appendPath(PathIterator pi) {
    float coords[] = new float[6];

    setRule(pi.getWindingRule());
    while (!pi.isDone()) {
        addSegment(pi.currentSegment(coords), coords);
        pi.next();
    }
    pathDone();
}
 
Example 6
Source File: Path2DCopyConstructor.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
static void testEqual(Path2D pathA, Path2D pathB) {
    final PathIterator itA = pathA.getPathIterator(null);
    final PathIterator itB = pathB.getPathIterator(null);

    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 + "] !");
        }
        if (!equalsArray(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("testEqual: " + n + " segments.");
}
 
Example 7
Source File: Path2DCopyConstructor.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
static void testEqual(Path2D pathA, Path2D pathB) {
    final PathIterator itA = pathA.getPathIterator(null);
    final PathIterator itB = pathB.getPathIterator(null);

    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 + "] !");
        }
        if (!equalsArray(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("testEqual: " + n + " segments.");
}
 
Example 8
Source File: Path2DCopyConstructor.java    From jdk8u60 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: Shapes.java    From Pixelitor with GNU General Public License v3.0 5 votes vote down vote up
public static void debugPathIterator(Shape shape) {
    PathIterator it = shape.getPathIterator(null);
    double[] coords = new double[6];
    while (!it.isDone()) {
        int type = it.currentSegment(coords);

        switch (type) {
            case SEG_MOVETO:
                System.out.println("MOVE TO " + Arrays.toString(coords));
                break;
            case SEG_LINETO:
                System.out.println("LINE TO " + Arrays.toString(coords));
                break;
            case SEG_QUADTO:
                System.out.println("QUAD TO " + Arrays.toString(coords));
                break;
            case SEG_CUBICTO:
                System.out.println("CUBIC TO " + Arrays.toString(coords));
                break;
            case SEG_CLOSE:
                System.out.println("CLOSE " + Arrays.toString(coords));
                break;
            default:
                throw new IllegalArgumentException("type = " + type);
        }

        it.next();
    }
}
 
Example 10
Source File: RenderingEngine.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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();
    }
}
 
Example 11
Source File: RenderingEngine.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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();
    }
}
 
Example 12
Source File: FXGraphics2D.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Maps a shape to a path in the graphics context. 
 * 
 * @param s  the shape ({@code null} not permitted).
 */
private void shapeToPath(Shape s) {
    double[] coords = new double[6];
    this.gc.beginPath();
    PathIterator iterator = s.getPathIterator(null);
    while (!iterator.isDone()) {
        int segType = iterator.currentSegment(coords);
        switch (segType) {
            case PathIterator.SEG_MOVETO:
                this.gc.moveTo(coords[0], coords[1]);
                break;
            case PathIterator.SEG_LINETO:
                this.gc.lineTo(coords[0], coords[1]);
                break;
            case PathIterator.SEG_QUADTO:
                this.gc.quadraticCurveTo(coords[0], coords[1], coords[2], 
                        coords[3]);
                break;
            case PathIterator.SEG_CUBICTO:
                this.gc.bezierCurveTo(coords[0], coords[1], coords[2], 
                        coords[3], coords[4], coords[5]);
                break;
            case PathIterator.SEG_CLOSE:
                this.gc.closePath();
                break;
            default:
                throw new RuntimeException("Unrecognised segment type " 
                        + segType);
        }
        iterator.next();
    }
}
 
Example 13
Source File: DuctusRenderingEngine.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
private void feedConsumer(PathConsumer consumer, PathIterator pi) {
    try {
        consumer.beginPath();
        boolean pathClosed = false;
        float mx = 0.0f;
        float my = 0.0f;
        float point[]  = new float[6];

        while (!pi.isDone()) {
            int type = pi.currentSegment(point);
            if (pathClosed == true) {
                pathClosed = false;
                if (type != PathIterator.SEG_MOVETO) {
                    // Force current point back to last moveto point
                    consumer.beginSubpath(mx, my);
                }
            }
            switch (type) {
            case PathIterator.SEG_MOVETO:
                mx = point[0];
                my = point[1];
                consumer.beginSubpath(point[0], point[1]);
                break;
            case PathIterator.SEG_LINETO:
                consumer.appendLine(point[0], point[1]);
                break;
            case PathIterator.SEG_QUADTO:
                consumer.appendQuadratic(point[0], point[1],
                                         point[2], point[3]);
                break;
            case PathIterator.SEG_CUBICTO:
                consumer.appendCubic(point[0], point[1],
                                     point[2], point[3],
                                     point[4], point[5]);
                break;
            case PathIterator.SEG_CLOSE:
                consumer.closedSubpath();
                pathClosed = true;
                break;
            }
            pi.next();
        }

        consumer.endPath();
    } catch (PathException e) {
        throw new InternalError("Unable to Stroke shape ("+
                                e.getMessage()+")", e);
    }
}
 
Example 14
Source File: WPathGraphics.java    From openjdk-jdk8u-backup 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 15
Source File: SamplingXYLineRenderer.java    From openstock with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draws the visual representation of a single data item.
 *
 * @param g2  the graphics device.
 * @param state  the renderer state.
 * @param dataArea  the area within which the data is being drawn.
 * @param info  collects information about the drawing.
 * @param plot  the plot (can be used to obtain standard color
 *              information etc).
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param dataset  the dataset.
 * @param series  the series index (zero-based).
 * @param item  the item index (zero-based).
 * @param crosshairState  crosshair information for the plot
 *                        (<code>null</code> permitted).
 * @param pass  the pass index.
 */
@Override
public void drawItem(Graphics2D g2, XYItemRendererState state, 
        Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot,
        ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset,
        int series, int item, CrosshairState crosshairState, int pass) {

    // do nothing if item is not visible
    if (!getItemVisible(series, item)) {
        return;
    }
    RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    RectangleEdge yAxisLocation = plot.getRangeAxisEdge();

    // get the data point...
    double x1 = dataset.getXValue(series, item);
    double y1 = dataset.getYValue(series, item);
    double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);
    double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation);

    State s = (State) state;
    // update path to reflect latest point
    if (!Double.isNaN(transX1) && !Double.isNaN(transY1)) {
        float x = (float) transX1;
        float y = (float) transY1;
        PlotOrientation orientation = plot.getOrientation();
        if (orientation == PlotOrientation.HORIZONTAL) {
            x = (float) transY1;
            y = (float) transX1;
        }
        if (s.lastPointGood) {
            if ((Math.abs(x - s.lastX) > s.dX)) {
                s.seriesPath.lineTo(x, y);
                if (s.lowY < s.highY) {
                    s.intervalPath.moveTo((float) s.lastX, (float) s.lowY);
                    s.intervalPath.lineTo((float) s.lastX, (float) s.highY);
                }
                s.lastX = x;
                s.openY = y;
                s.highY = y;
                s.lowY = y;
                s.closeY = y;
            }
            else {
                s.highY = Math.max(s.highY, y);
                s.lowY = Math.min(s.lowY, y);
                s.closeY = y;
            }
        }
        else {
            s.seriesPath.moveTo(x, y);
            s.lastX = x;
            s.openY = y;
            s.highY = y;
            s.lowY = y;
            s.closeY = y;
        }
        s.lastPointGood = true;
    }
    else {
        s.lastPointGood = false;
    }
    // if this is the last item, draw the path ...
    if (item == s.getLastItemIndex()) {
        // draw path
        PathIterator pi = s.seriesPath.getPathIterator(null);
        int count = 0;
        while (!pi.isDone()) {
            count++;
            pi.next();
        }
        g2.setStroke(getItemStroke(series, item));
        g2.setPaint(getItemPaint(series, item));
        g2.draw(s.seriesPath);
        g2.draw(s.intervalPath);
    }
}
 
Example 16
Source File: PSPrinterJob.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
* Given a Java2D {@code PathIterator} 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 17
Source File: PdfGraphics2D.java    From itext2 with GNU Lesser General Public License v3.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();
    }
}
 
Example 18
Source File: WPathGraphics.java    From jdk8u-dev-jdk 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 19
Source File: PSPrinterJob.java    From jdk8u-jdk 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 20
Source File: Crossings.java    From openjdk-jdk9 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() == PathIterator.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;
}