Java Code Examples for java.awt.geom.PathIterator#WIND_EVEN_ODD

The following examples show how to use java.awt.geom.PathIterator#WIND_EVEN_ODD . 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: CurvedPolyline.java    From pumpernickel with MIT License 6 votes vote down vote up
/**
 * 
 * @param array
 *            an array of points to create this shape from.
 * @param windingRule
 *            one of the winding constants (PathIterator.WIND_NONZERO or
 *            PathIterator.WIND_EVEN_ODD)
 * @param tx
 *            an optional AffineTransform to transform this data (may be
 *            null).
 */
public CurvedPolylineIterator(Point2D[] array, int windingRule,
		AffineTransform tx) {
	points = new Point2D[array.length];
	for (int a = 0; a < array.length; a++) {
		if (a == 0 || a == array.length - 1) {
			points[a] = new Point2D.Double(array[a].getX(),
					array[a].getY());
		} else {
			Point2D prev = array[a - 1];
			Point2D next = array[a + 1];
			double theta = Math.atan2(next.getY() - prev.getY(),
					next.getX() - prev.getX());
			points[a] = new SplinePoint2D(array[a].getX(),
					array[a].getY(), theta);
		}
	}
	this.tx = tx;
	this.windingRule = windingRule;
	if (!(windingRule == PathIterator.WIND_NON_ZERO || windingRule == PathIterator.WIND_EVEN_ODD))
		throw new IllegalArgumentException("windingRule = "
				+ windingRule);
}
 
Example 2
Source File: GeneralPathObjectDescription.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Translates the winding rule parameter into a predefined PathIterator constant.
 *
 * @return the translated winding rule or -1 if the rule was invalid.
 */
private int parseWindingRule() {
  final String windingRule = (String) getParameter( GeneralPathObjectDescription.WINDING_RULE_NAME );
  int wRule = -1;
  if ( windingRule == null ) {
    return wRule;
  }
  if ( windingRule.equals( GeneralPathObjectDescription.WINDING_RULE_EVEN_ODD ) ) {
    wRule = PathIterator.WIND_EVEN_ODD;
  } else if ( windingRule.equals( GeneralPathObjectDescription.WINDING_RULE_NON_ZERO ) ) {
    wRule = PathIterator.WIND_NON_ZERO;
  }
  return wRule;
}
 
Example 3
Source File: PSPrinterJob.java    From openjdk-jdk8u 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 4
Source File: Crossings.java    From Bytecoder with Apache License 2.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;
}
 
Example 5
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 6
Source File: PiscesRenderingEngine.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public AATileGenerator getAATileGenerator(double x, double y,
                                          double dx1, double dy1,
                                          double dx2, double dy2,
                                          double lw1, double lw2,
                                          Region clip,
                                          int bbox[])
{
    // REMIND: Deal with large coordinates!
    double ldx1, ldy1, ldx2, ldy2;
    boolean innerpgram = (lw1 > 0 && lw2 > 0);

    if (innerpgram) {
        ldx1 = dx1 * lw1;
        ldy1 = dy1 * lw1;
        ldx2 = dx2 * lw2;
        ldy2 = dy2 * lw2;
        x -= (ldx1 + ldx2) / 2.0;
        y -= (ldy1 + ldy2) / 2.0;
        dx1 += ldx1;
        dy1 += ldy1;
        dx2 += ldx2;
        dy2 += ldy2;
        if (lw1 > 1 && lw2 > 1) {
            // Inner parallelogram was entirely consumed by stroke...
            innerpgram = false;
        }
    } else {
        ldx1 = ldy1 = ldx2 = ldy2 = 0;
    }

    Renderer r = new Renderer(3, 3,
            clip.getLoX(), clip.getLoY(),
            clip.getWidth(), clip.getHeight(),
            PathIterator.WIND_EVEN_ODD);

    r.moveTo((float) x, (float) y);
    r.lineTo((float) (x+dx1), (float) (y+dy1));
    r.lineTo((float) (x+dx1+dx2), (float) (y+dy1+dy2));
    r.lineTo((float) (x+dx2), (float) (y+dy2));
    r.closePath();

    if (innerpgram) {
        x += ldx1 + ldx2;
        y += ldy1 + ldy2;
        dx1 -= 2.0 * ldx1;
        dy1 -= 2.0 * ldy1;
        dx2 -= 2.0 * ldx2;
        dy2 -= 2.0 * ldy2;
        r.moveTo((float) x, (float) y);
        r.lineTo((float) (x+dx1), (float) (y+dy1));
        r.lineTo((float) (x+dx1+dx2), (float) (y+dy1+dy2));
        r.lineTo((float) (x+dx2), (float) (y+dy2));
        r.closePath();
    }

    r.pathDone();

    r.endRendering();
    PiscesTileGenerator ptg = new PiscesTileGenerator(r, r.MAX_AA_ALPHA);
    ptg.getBbox(bbox);
    return ptg;
}
 
Example 7
Source File: PSPrinterJob.java    From hottub 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 8
Source File: PiscesRenderingEngine.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public AATileGenerator getAATileGenerator(double x, double y,
                                          double dx1, double dy1,
                                          double dx2, double dy2,
                                          double lw1, double lw2,
                                          Region clip,
                                          int bbox[])
{
    // REMIND: Deal with large coordinates!
    double ldx1, ldy1, ldx2, ldy2;
    boolean innerpgram = (lw1 > 0 && lw2 > 0);

    if (innerpgram) {
        ldx1 = dx1 * lw1;
        ldy1 = dy1 * lw1;
        ldx2 = dx2 * lw2;
        ldy2 = dy2 * lw2;
        x -= (ldx1 + ldx2) / 2.0;
        y -= (ldy1 + ldy2) / 2.0;
        dx1 += ldx1;
        dy1 += ldy1;
        dx2 += ldx2;
        dy2 += ldy2;
        if (lw1 > 1 && lw2 > 1) {
            // Inner parallelogram was entirely consumed by stroke...
            innerpgram = false;
        }
    } else {
        ldx1 = ldy1 = ldx2 = ldy2 = 0;
    }

    Renderer r = new Renderer(3, 3,
            clip.getLoX(), clip.getLoY(),
            clip.getWidth(), clip.getHeight(),
            PathIterator.WIND_EVEN_ODD);

    r.moveTo((float) x, (float) y);
    r.lineTo((float) (x+dx1), (float) (y+dy1));
    r.lineTo((float) (x+dx1+dx2), (float) (y+dy1+dy2));
    r.lineTo((float) (x+dx2), (float) (y+dy2));
    r.closePath();

    if (innerpgram) {
        x += ldx1 + ldx2;
        y += ldy1 + ldy2;
        dx1 -= 2.0 * ldx1;
        dy1 -= 2.0 * ldy1;
        dx2 -= 2.0 * ldx2;
        dy2 -= 2.0 * ldy2;
        r.moveTo((float) x, (float) y);
        r.lineTo((float) (x+dx1), (float) (y+dy1));
        r.lineTo((float) (x+dx1+dx2), (float) (y+dy1+dy2));
        r.lineTo((float) (x+dx2), (float) (y+dy2));
        r.closePath();
    }

    r.pathDone();

    r.endRendering();
    PiscesTileGenerator ptg = new PiscesTileGenerator(r, r.MAX_AA_ALPHA);
    ptg.getBbox(bbox);
    return ptg;
}
 
Example 9
Source File: VdPath.java    From SVG-Android with Apache License 2.0 4 votes vote down vote up
private static int parseFillType(String value) {
    if (FILL_TYPE_EVEN_ODD.equalsIgnoreCase(value)) {
        return PathIterator.WIND_EVEN_ODD;
    }
    return PathIterator.WIND_NON_ZERO;
}
 
Example 10
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 11
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 12
Source File: PiscesRenderingEngine.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public AATileGenerator getAATileGenerator(double x, double y,
                                          double dx1, double dy1,
                                          double dx2, double dy2,
                                          double lw1, double lw2,
                                          Region clip,
                                          int bbox[])
{
    // REMIND: Deal with large coordinates!
    double ldx1, ldy1, ldx2, ldy2;
    boolean innerpgram = (lw1 > 0 && lw2 > 0);

    if (innerpgram) {
        ldx1 = dx1 * lw1;
        ldy1 = dy1 * lw1;
        ldx2 = dx2 * lw2;
        ldy2 = dy2 * lw2;
        x -= (ldx1 + ldx2) / 2.0;
        y -= (ldy1 + ldy2) / 2.0;
        dx1 += ldx1;
        dy1 += ldy1;
        dx2 += ldx2;
        dy2 += ldy2;
        if (lw1 > 1 && lw2 > 1) {
            // Inner parallelogram was entirely consumed by stroke...
            innerpgram = false;
        }
    } else {
        ldx1 = ldy1 = ldx2 = ldy2 = 0;
    }

    Renderer r = new Renderer(3, 3,
            clip.getLoX(), clip.getLoY(),
            clip.getWidth(), clip.getHeight(),
            PathIterator.WIND_EVEN_ODD);

    r.moveTo((float) x, (float) y);
    r.lineTo((float) (x+dx1), (float) (y+dy1));
    r.lineTo((float) (x+dx1+dx2), (float) (y+dy1+dy2));
    r.lineTo((float) (x+dx2), (float) (y+dy2));
    r.closePath();

    if (innerpgram) {
        x += ldx1 + ldx2;
        y += ldy1 + ldy2;
        dx1 -= 2.0 * ldx1;
        dy1 -= 2.0 * ldy1;
        dx2 -= 2.0 * ldx2;
        dy2 -= 2.0 * ldy2;
        r.moveTo((float) x, (float) y);
        r.lineTo((float) (x+dx1), (float) (y+dy1));
        r.lineTo((float) (x+dx1+dx2), (float) (y+dy1+dy2));
        r.lineTo((float) (x+dx2), (float) (y+dy2));
        r.closePath();
    }

    r.pathDone();

    r.endRendering();
    PiscesTileGenerator ptg = new PiscesTileGenerator(r, r.MAX_AA_ALPHA);
    ptg.getBbox(bbox);
    return ptg;
}
 
Example 13
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 14
Source File: WPathGraphics.java    From jdk8u60 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: PSPrinterJob.java    From jdk8u60 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: 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 17
Source File: EpsGraphics2D.java    From osp with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Appends the commands required to draw a shape on the EPS document.
 */
private void draw(Shape s, String action) {
  if(s!=null) {
    if(!_transform.isIdentity()) {
      s = _transform.createTransformedShape(s);
    }
    // Update the bounds.
    if(!action.equals("clip")) {                                  //$NON-NLS-1$
      Rectangle2D shapeBounds = s.getBounds2D();
      Rectangle2D visibleBounds = shapeBounds;
      if(_clip!=null) {
        Rectangle2D clipBounds = _clip.getBounds2D();
        visibleBounds = shapeBounds.createIntersection(clipBounds);
      }
      float lineRadius = _stroke.getLineWidth()/2;
      float minX = (float) visibleBounds.getMinX()-lineRadius;
      float minY = (float) visibleBounds.getMinY()-lineRadius;
      float maxX = (float) visibleBounds.getMaxX()+lineRadius;
      float maxY = (float) visibleBounds.getMaxY()+lineRadius;
      _document.updateBounds(minX, -minY);
      _document.updateBounds(maxX, -maxY);
    }
    append("newpath");                                            //$NON-NLS-1$
    int type = 0;
    float[] coords = new float[6];
    PathIterator it = s.getPathIterator(null);
    float x0 = 0;
    float y0 = 0;
    while(!it.isDone()) {
      type = it.currentSegment(coords);
      float x1 = coords[0];
      float y1 = -coords[1];
      float x2 = coords[2];
      float y2 = -coords[3];
      float x3 = coords[4];
      float y3 = -coords[5];
      if(type==PathIterator.SEG_CLOSE) {
        append("closepath");                                      //$NON-NLS-1$
      } else if(type==PathIterator.SEG_CUBICTO) {
        append(x1+" "+y1+" "+x2+" "+y2+" "+x3+" "+y3+" curveto"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
        x0 = x3;
        y0 = y3;
      } else if(type==PathIterator.SEG_LINETO) {
        append(x1+" "+y1+" lineto");                                    //$NON-NLS-1$ //$NON-NLS-2$
        x0 = x1;
        y0 = y1;
      } else if(type==PathIterator.SEG_MOVETO) {
        append(x1+" "+y1+" moveto");                                    //$NON-NLS-1$ //$NON-NLS-2$
        x0 = x1;
        y0 = y1;
      } else if(type==PathIterator.SEG_QUADTO) {
        // Convert the quad curve into a cubic.
        float _x1 = x0+2/3f*(x1-x0);
        float _y1 = y0+2/3f*(y1-y0);
        float _x2 = x1+1/3f*(x2-x1);
        float _y2 = y1+1/3f*(y2-y1);
        float _x3 = x2;
        float _y3 = y2;
        append(_x1+" "+_y1+" "+_x2+" "+_y2+" "+_x3+" "+_y3+" curveto"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
        x0 = _x3;
        y0 = _y3;
      } else if(type==PathIterator.WIND_EVEN_ODD) {
        // Ignore.
      } else if(type==PathIterator.WIND_NON_ZERO) {
        // Ignore.
      }
      it.next();
    }
    append(action);
    append("newpath"); //$NON-NLS-1$
  }
}
 
Example 18
Source File: PiscesRenderingEngine.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public AATileGenerator getAATileGenerator(double x, double y,
                                          double dx1, double dy1,
                                          double dx2, double dy2,
                                          double lw1, double lw2,
                                          Region clip,
                                          int bbox[])
{
    // REMIND: Deal with large coordinates!
    double ldx1, ldy1, ldx2, ldy2;
    boolean innerpgram = (lw1 > 0 && lw2 > 0);

    if (innerpgram) {
        ldx1 = dx1 * lw1;
        ldy1 = dy1 * lw1;
        ldx2 = dx2 * lw2;
        ldy2 = dy2 * lw2;
        x -= (ldx1 + ldx2) / 2.0;
        y -= (ldy1 + ldy2) / 2.0;
        dx1 += ldx1;
        dy1 += ldy1;
        dx2 += ldx2;
        dy2 += ldy2;
        if (lw1 > 1 && lw2 > 1) {
            // Inner parallelogram was entirely consumed by stroke...
            innerpgram = false;
        }
    } else {
        ldx1 = ldy1 = ldx2 = ldy2 = 0;
    }

    Renderer r = new Renderer(3, 3,
            clip.getLoX(), clip.getLoY(),
            clip.getWidth(), clip.getHeight(),
            PathIterator.WIND_EVEN_ODD);

    r.moveTo((float) x, (float) y);
    r.lineTo((float) (x+dx1), (float) (y+dy1));
    r.lineTo((float) (x+dx1+dx2), (float) (y+dy1+dy2));
    r.lineTo((float) (x+dx2), (float) (y+dy2));
    r.closePath();

    if (innerpgram) {
        x += ldx1 + ldx2;
        y += ldy1 + ldy2;
        dx1 -= 2.0 * ldx1;
        dy1 -= 2.0 * ldy1;
        dx2 -= 2.0 * ldx2;
        dy2 -= 2.0 * ldy2;
        r.moveTo((float) x, (float) y);
        r.lineTo((float) (x+dx1), (float) (y+dy1));
        r.lineTo((float) (x+dx1+dx2), (float) (y+dy1+dy2));
        r.lineTo((float) (x+dx2), (float) (y+dy2));
        r.closePath();
    }

    r.pathDone();

    r.endRendering();
    PiscesTileGenerator ptg = new PiscesTileGenerator(r, r.MAX_AA_ALPHA);
    ptg.getBbox(bbox);
    return ptg;
}
 
Example 19
Source File: WPathGraphics.java    From dragonwell8_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 20
Source File: PSPrinterJob.java    From dragonwell8_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();
    }
}