Java Code Examples for java.awt.geom.PathIterator#getWindingRule()
The following examples show how to use
java.awt.geom.PathIterator#getWindingRule() .
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: ShapeUtils.java From pumpernickel with MIT License | 5 votes |
public static Shape clone(Shape shape) { if (shape == null) return null; if (shape instanceof RectangularShape) return (Shape) ((RectangularShape) shape).clone(); if (shape instanceof Line2D) return (Shape) ((Line2D) shape).clone(); PathIterator pi = shape.getPathIterator(null); Path2D p = new Path2D.Float(pi.getWindingRule()); p.append(pi, false); return p; }
Example 2
Source File: PSPrinterJob.java From hottub with GNU General Public License v2.0 | 4 votes |
/** * 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 3
Source File: PSPrinterJob.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
/** * 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: GeneralPathObjectDescription.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 4 votes |
/** * Sets the parameters of this description object to match the supplied object. * * @param o * the object (should be an instance of <code>FontDefinition</code>). * @throws ObjectFactoryException * if the object is not an instance of <code>Float</code>. */ public void setParameterFromObject( final Object o ) throws ObjectFactoryException { if ( getObjectClass().isAssignableFrom( o.getClass() ) == false ) { throw new ObjectFactoryException( "Class is not assignable" ); } final Shape s = (Shape) o; final PathIterator pi = s.getPathIterator( AffineTransform.getTranslateInstance( 0, 0 ) ); if ( pi.getWindingRule() == PathIterator.WIND_EVEN_ODD ) { setParameter( GeneralPathObjectDescription.WINDING_RULE_NAME, GeneralPathObjectDescription.WINDING_RULE_EVEN_ODD ); } else { setParameter( GeneralPathObjectDescription.WINDING_RULE_NAME, GeneralPathObjectDescription.WINDING_RULE_NON_ZERO ); } final float[] points = new float[GeneralPathObjectDescription.MAX_POINTS]; final ArrayList segments = new ArrayList(); while ( pi.isDone() == false ) { final int type = pi.currentSegment( points ); final PathIteratorSegment seg = new PathIteratorSegment(); switch ( type ) { case PathIterator.SEG_CLOSE: { seg.setSegmentType( PathIterator.SEG_CLOSE ); break; } case PathIterator.SEG_CUBICTO: { seg.setSegmentType( PathIterator.SEG_CUBICTO ); seg.setX1( points[0] ); seg.setY1( points[1] ); seg.setX2( points[2] ); seg.setY2( points[3] ); seg.setX3( points[4] ); seg.setY3( points[5] ); break; } case PathIterator.SEG_LINETO: { seg.setSegmentType( PathIterator.SEG_LINETO ); seg.setX1( points[0] ); seg.setY1( points[1] ); break; } case PathIterator.SEG_MOVETO: { seg.setSegmentType( PathIterator.SEG_MOVETO ); seg.setX1( points[0] ); seg.setY1( points[1] ); break; } case PathIterator.SEG_QUADTO: { seg.setSegmentType( PathIterator.SEG_QUADTO ); seg.setX1( points[0] ); seg.setY1( points[1] ); seg.setX2( points[2] ); seg.setY2( points[3] ); break; } default: throw new IllegalStateException( "Unexpected result from PathIterator." ); } segments.add( seg ); pi.next(); } setParameter( GeneralPathObjectDescription.SEGMENTS_NAME, segments .toArray( new PathIteratorSegment[segments.size()] ) ); }
Example 5
Source File: TessFont.java From jaamsim with Apache License 2.0 | 4 votes |
private TessOutput tesselateString(String s) { GlyphVector gv = _font.createGlyphVector(_frc, s); Shape shape = gv.getOutline(); // AffineTransform at = new AffineTransform(); at.scale(1, -1); PathIterator pIt = shape.getPathIterator(at, _font.getSize()/200.0); // Create a GLU tesselator GLUtessellator tess = GLU.gluNewTess(); CharTesselator tessAdapt = new CharTesselator(); GLU.gluTessCallback(tess, GLU.GLU_TESS_VERTEX, tessAdapt); GLU.gluTessCallback(tess, GLU.GLU_TESS_BEGIN, tessAdapt); GLU.gluTessCallback(tess, GLU.GLU_TESS_END, tessAdapt); GLU.gluTessCallback(tess, GLU.GLU_TESS_COMBINE, tessAdapt); GLU.gluTessCallback(tess, GLU.GLU_TESS_ERROR, tessAdapt); int winding = pIt.getWindingRule(); if (winding == PathIterator.WIND_EVEN_ODD) GLU.gluTessProperty(tess, GLU.GLU_TESS_WINDING_RULE, GLU.GLU_TESS_WINDING_ODD); else if (winding == PathIterator.WIND_NON_ZERO) GLU.gluTessProperty(tess, GLU.GLU_TESS_WINDING_RULE, GLU.GLU_TESS_WINDING_NONZERO); else assert(false); // PathIterator should only return these two winding rules GLU.gluBeginPolygon(tess); GLU.gluTessNormal(tess, 0, 0, 1); double[] first = null; double[] v; while (!pIt.isDone()) { v = new double[3]; int type = pIt.currentSegment(v); v[2] = 0.0; if (type == PathIterator.SEG_MOVETO) { first = v; GLU.gluNextContour(tess, GLU.GLU_UNKNOWN); GLU.gluTessVertex(tess, v, 0, v); } else if (type == PathIterator.SEG_LINETO) { GLU.gluTessVertex(tess, v, 0, v); } else if (type == PathIterator.SEG_CLOSE) { assert(first != null); // If this is true, there is an error in the AWT path iterator GLU.gluTessVertex(tess, first, 0, first); first = null; } else { assert(false); // The path itertor should not return other path types here } pIt.next(); } GLU.gluEndPolygon(tess); int numVerts = tessAdapt.getVerts().size(); double[] verts = new double[numVerts]; int count = 0; for (double d : tessAdapt.getVerts()) { verts[count++] = d; } TessOutput ret = new TessOutput(); ret.verts = verts; ret.bounds = gv.getVisualBounds(); ret.advances = new double[s.length()]; for (int i = 0; i < s.length(); ++i) { ret.advances[i] = gv.getGlyphMetrics(i).getAdvance(); } return ret; }
Example 6
Source File: PSPrinterJob.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
/** * 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 7
Source File: WPathGraphics.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
/** * 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 8
Source File: Crossings.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
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 9
Source File: Crossings.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
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 10
Source File: Crossings.java From Bytecoder with Apache License 2.0 | 4 votes |
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 11
Source File: PSPrinterJob.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
/** * 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: Crossings.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
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 13
Source File: Crossings.java From hottub with GNU General Public License v2.0 | 4 votes |
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 14
Source File: WPathGraphics.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
/** * 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: WPathGraphics.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
/** * 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 16
Source File: Crossings.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
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 17
Source File: PiscesRenderingEngine.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 3 votes |
/** * Construct an antialiased tile generator for the given shape with * the given rendering attributes and store the bounds of the tile * iteration in the bbox parameter. * The {@code at} parameter specifies a transform that should affect * both the shape and the {@code BasicStroke} attributes. * The {@code clip} parameter specifies the current clip in effect * in device coordinates and can be used to prune the data for the * operation, but the renderer is not required to perform any * clipping. * If the {@code BasicStroke} parameter is null then the shape * should be filled as is, otherwise the attributes of the * {@code BasicStroke} should be used to specify a draw operation. * The {@code thin} parameter indicates whether or not the * transformed {@code BasicStroke} represents coordinates smaller * than the minimum resolution of the antialiasing rasterizer as * specified by the {@code getMinimumAAPenWidth()} method. * <p> * Upon returning, this method will fill the {@code bbox} parameter * with 4 values indicating the bounds of the iteration of the * tile generator. * The iteration order of the tiles will be as specified by the * pseudo-code: * <pre> * for (y = bbox[1]; y < bbox[3]; y += tileheight) { * for (x = bbox[0]; x < bbox[2]; x += tilewidth) { * } * } * </pre> * If there is no output to be rendered, this method may return * null. * * @param s the shape to be rendered (fill or draw) * @param at the transform to be applied to the shape and the * stroke attributes * @param clip the current clip in effect in device coordinates * @param bs if non-null, a {@code BasicStroke} whose attributes * should be applied to this operation * @param thin true if the transformed stroke attributes are smaller * than the minimum dropout pen width * @param normalize true if the {@code VALUE_STROKE_NORMALIZE} * {@code RenderingHint} is in effect * @param bbox returns the bounds of the iteration * @return the {@code AATileGenerator} instance to be consulted * for tile coverages, or null if there is no output to render * @since 1.7 */ public AATileGenerator getAATileGenerator(Shape s, AffineTransform at, Region clip, BasicStroke bs, boolean thin, boolean normalize, int bbox[]) { Renderer r; NormMode norm = (normalize) ? NormMode.ON_WITH_AA : NormMode.OFF; if (bs == null) { PathIterator pi; if (normalize) { pi = new NormalizingPathIterator(s.getPathIterator(at), norm); } else { pi = s.getPathIterator(at); } r = new Renderer(3, 3, clip.getLoX(), clip.getLoY(), clip.getWidth(), clip.getHeight(), pi.getWindingRule()); pathTo(pi, r); } else { r = new Renderer(3, 3, clip.getLoX(), clip.getLoY(), clip.getWidth(), clip.getHeight(), PathIterator.WIND_NON_ZERO); strokeTo(s, at, bs, thin, norm, true, r); } r.endRendering(); PiscesTileGenerator ptg = new PiscesTileGenerator(r, r.MAX_AA_ALPHA); ptg.getBbox(bbox); return ptg; }
Example 18
Source File: PiscesRenderingEngine.java From openjdk-jdk9 with GNU General Public License v2.0 | 3 votes |
/** * Construct an antialiased tile generator for the given shape with * the given rendering attributes and store the bounds of the tile * iteration in the bbox parameter. * The {@code at} parameter specifies a transform that should affect * both the shape and the {@code BasicStroke} attributes. * The {@code clip} parameter specifies the current clip in effect * in device coordinates and can be used to prune the data for the * operation, but the renderer is not required to perform any * clipping. * If the {@code BasicStroke} parameter is null then the shape * should be filled as is, otherwise the attributes of the * {@code BasicStroke} should be used to specify a draw operation. * The {@code thin} parameter indicates whether or not the * transformed {@code BasicStroke} represents coordinates smaller * than the minimum resolution of the antialiasing rasterizer as * specified by the {@code getMinimumAAPenWidth()} method. * <p> * Upon returning, this method will fill the {@code bbox} parameter * with 4 values indicating the bounds of the iteration of the * tile generator. * The iteration order of the tiles will be as specified by the * pseudo-code: * <pre> * for (y = bbox[1]; y < bbox[3]; y += tileheight) { * for (x = bbox[0]; x < bbox[2]; x += tilewidth) { * } * } * </pre> * If there is no output to be rendered, this method may return * null. * * @param s the shape to be rendered (fill or draw) * @param at the transform to be applied to the shape and the * stroke attributes * @param clip the current clip in effect in device coordinates * @param bs if non-null, a {@code BasicStroke} whose attributes * should be applied to this operation * @param thin true if the transformed stroke attributes are smaller * than the minimum dropout pen width * @param normalize true if the {@code VALUE_STROKE_NORMALIZE} * {@code RenderingHint} is in effect * @param bbox returns the bounds of the iteration * @return the {@code AATileGenerator} instance to be consulted * for tile coverages, or null if there is no output to render * @since 1.7 */ public AATileGenerator getAATileGenerator(Shape s, AffineTransform at, Region clip, BasicStroke bs, boolean thin, boolean normalize, int bbox[]) { Renderer r; NormMode norm = (normalize) ? NormMode.ON_WITH_AA : NormMode.OFF; if (bs == null) { PathIterator pi; if (normalize) { pi = new NormalizingPathIterator(s.getPathIterator(at), norm); } else { pi = s.getPathIterator(at); } r = new Renderer(3, 3, clip.getLoX(), clip.getLoY(), clip.getWidth(), clip.getHeight(), pi.getWindingRule()); pathTo(pi, r); } else { r = new Renderer(3, 3, clip.getLoX(), clip.getLoY(), clip.getWidth(), clip.getHeight(), PathIterator.WIND_NON_ZERO); strokeTo(s, at, bs, thin, norm, true, r); } r.endRendering(); PiscesTileGenerator ptg = new PiscesTileGenerator(r, r.MAX_AA_ALPHA); ptg.getBbox(bbox); return ptg; }
Example 19
Source File: PiscesRenderingEngine.java From hottub with GNU General Public License v2.0 | 3 votes |
/** * Construct an antialiased tile generator for the given shape with * the given rendering attributes and store the bounds of the tile * iteration in the bbox parameter. * The {@code at} parameter specifies a transform that should affect * both the shape and the {@code BasicStroke} attributes. * The {@code clip} parameter specifies the current clip in effect * in device coordinates and can be used to prune the data for the * operation, but the renderer is not required to perform any * clipping. * If the {@code BasicStroke} parameter is null then the shape * should be filled as is, otherwise the attributes of the * {@code BasicStroke} should be used to specify a draw operation. * The {@code thin} parameter indicates whether or not the * transformed {@code BasicStroke} represents coordinates smaller * than the minimum resolution of the antialiasing rasterizer as * specified by the {@code getMinimumAAPenWidth()} method. * <p> * Upon returning, this method will fill the {@code bbox} parameter * with 4 values indicating the bounds of the iteration of the * tile generator. * The iteration order of the tiles will be as specified by the * pseudo-code: * <pre> * for (y = bbox[1]; y < bbox[3]; y += tileheight) { * for (x = bbox[0]; x < bbox[2]; x += tilewidth) { * } * } * </pre> * If there is no output to be rendered, this method may return * null. * * @param s the shape to be rendered (fill or draw) * @param at the transform to be applied to the shape and the * stroke attributes * @param clip the current clip in effect in device coordinates * @param bs if non-null, a {@code BasicStroke} whose attributes * should be applied to this operation * @param thin true if the transformed stroke attributes are smaller * than the minimum dropout pen width * @param normalize true if the {@code VALUE_STROKE_NORMALIZE} * {@code RenderingHint} is in effect * @param bbox returns the bounds of the iteration * @return the {@code AATileGenerator} instance to be consulted * for tile coverages, or null if there is no output to render * @since 1.7 */ public AATileGenerator getAATileGenerator(Shape s, AffineTransform at, Region clip, BasicStroke bs, boolean thin, boolean normalize, int bbox[]) { Renderer r; NormMode norm = (normalize) ? NormMode.ON_WITH_AA : NormMode.OFF; if (bs == null) { PathIterator pi; if (normalize) { pi = new NormalizingPathIterator(s.getPathIterator(at), norm); } else { pi = s.getPathIterator(at); } r = new Renderer(3, 3, clip.getLoX(), clip.getLoY(), clip.getWidth(), clip.getHeight(), pi.getWindingRule()); pathTo(pi, r); } else { r = new Renderer(3, 3, clip.getLoX(), clip.getLoY(), clip.getWidth(), clip.getHeight(), PathIterator.WIND_NON_ZERO); strokeTo(s, at, bs, thin, norm, true, r); } r.endRendering(); PiscesTileGenerator ptg = new PiscesTileGenerator(r, r.MAX_AA_ALPHA); ptg.getBbox(bbox); return ptg; }
Example 20
Source File: PiscesRenderingEngine.java From jdk8u-jdk with GNU General Public License v2.0 | 3 votes |
/** * Construct an antialiased tile generator for the given shape with * the given rendering attributes and store the bounds of the tile * iteration in the bbox parameter. * The {@code at} parameter specifies a transform that should affect * both the shape and the {@code BasicStroke} attributes. * The {@code clip} parameter specifies the current clip in effect * in device coordinates and can be used to prune the data for the * operation, but the renderer is not required to perform any * clipping. * If the {@code BasicStroke} parameter is null then the shape * should be filled as is, otherwise the attributes of the * {@code BasicStroke} should be used to specify a draw operation. * The {@code thin} parameter indicates whether or not the * transformed {@code BasicStroke} represents coordinates smaller * than the minimum resolution of the antialiasing rasterizer as * specified by the {@code getMinimumAAPenWidth()} method. * <p> * Upon returning, this method will fill the {@code bbox} parameter * with 4 values indicating the bounds of the iteration of the * tile generator. * The iteration order of the tiles will be as specified by the * pseudo-code: * <pre> * for (y = bbox[1]; y < bbox[3]; y += tileheight) { * for (x = bbox[0]; x < bbox[2]; x += tilewidth) { * } * } * </pre> * If there is no output to be rendered, this method may return * null. * * @param s the shape to be rendered (fill or draw) * @param at the transform to be applied to the shape and the * stroke attributes * @param clip the current clip in effect in device coordinates * @param bs if non-null, a {@code BasicStroke} whose attributes * should be applied to this operation * @param thin true if the transformed stroke attributes are smaller * than the minimum dropout pen width * @param normalize true if the {@code VALUE_STROKE_NORMALIZE} * {@code RenderingHint} is in effect * @param bbox returns the bounds of the iteration * @return the {@code AATileGenerator} instance to be consulted * for tile coverages, or null if there is no output to render * @since 1.7 */ public AATileGenerator getAATileGenerator(Shape s, AffineTransform at, Region clip, BasicStroke bs, boolean thin, boolean normalize, int bbox[]) { Renderer r; NormMode norm = (normalize) ? NormMode.ON_WITH_AA : NormMode.OFF; if (bs == null) { PathIterator pi; if (normalize) { pi = new NormalizingPathIterator(s.getPathIterator(at), norm); } else { pi = s.getPathIterator(at); } r = new Renderer(3, 3, clip.getLoX(), clip.getLoY(), clip.getWidth(), clip.getHeight(), pi.getWindingRule()); pathTo(pi, r); } else { r = new Renderer(3, 3, clip.getLoX(), clip.getLoY(), clip.getWidth(), clip.getHeight(), PathIterator.WIND_NON_ZERO); strokeTo(s, at, bs, thin, norm, true, r); } r.endRendering(); PiscesTileGenerator ptg = new PiscesTileGenerator(r, r.MAX_AA_ALPHA); ptg.getBbox(bbox); return ptg; }