NormalizingPathIterator(PathIterator src, NormMode mode) { this.src = src; switch (mode) { case ON_NO_AA: // round to nearest (0.25, 0.25) pixel lval = rval = 0.25f; break; case ON_WITH_AA: // round to nearest pixel center lval = 0f; rval = 0.5f; break; case OFF: throw new InternalError("A NormalizingPathIterator should " + "not be created if no normalization is being done"); default: throw new InternalError("Unrecognized normalization mode"); } }
private static void checkEmptyPath(final Shape s) { final float[] coords = new float[6]; final PathIterator it = s.getPathIterator(null); int n = 0; for (; !it.isDone(); it.next()) { int type = it.currentSegment(coords); System.out.println("unexpected segment type= " + type + " with coords: " + Arrays.toString(coords)); n++; } if (n != 0) { System.out.println("path elements = " + n); throw new IllegalStateException("Not empty path: " + n + " path elements !"); } }
public static ShapeSpanIterator getStrokeSpans(SunGraphics2D sg2d, Shape s) { ShapeSpanIterator sr = new ShapeSpanIterator(false); try { sr.setOutputArea(sg2d.getCompClip()); sr.setRule(PathIterator.WIND_NON_ZERO); BasicStroke bs = (BasicStroke) sg2d.stroke; boolean thin = (sg2d.strokeState <= SunGraphics2D.STROKE_THINDASHED); boolean normalize = (sg2d.strokeHint != SunHints.INTVAL_STROKE_PURE); RenderEngine.strokeTo(s, sg2d.transform, bs, thin, normalize, false, sr); } catch (Throwable t) { sr.dispose(); sr = null; throw new InternalError("Unable to Stroke shape ("+ t.getMessage()+")", t); } return sr; }
protected void deviceFill(PathIterator pathIter, Color color, AffineTransform tx, Shape clip) { setTransform(tx); setClip(clip); setColor(color); convertToPSPath(pathIter); /* Specify the path to fill as the clip, this ensures that only * pixels which are inside the path will be filled, which is * what the Java 2D APIs specify */ mPSStream.println(GSAVE_STR); selectClipPath(); fillPath(); mPSStream.println(GRESTORE_STR + " " + NEWPATH_STR); }
public int getSegment(double coords[]) { if (direction == INCREASING) { coords[0] = cx0; coords[1] = cy0; coords[2] = cx1; coords[3] = cy1; coords[4] = x1; coords[5] = y1; } else { coords[0] = cx1; coords[1] = cy1; coords[2] = cx0; coords[3] = cy0; coords[4] = x0; coords[5] = y0; } return PathIterator.SEG_CUBICTO; }
/** * Checks if previous command was a moveto command, * skipping a close command (if present). */ protected void checkMoveTo() { if (numSeg == 0) return; switch (types[numSeg - 1]) { case PathIterator.SEG_MOVETO: path.moveTo(values[numVals - 2], values[numVals - 1]); break; case PathIterator.SEG_CLOSE: if (numSeg == 1) return; if (types[numSeg - 2] == PathIterator.SEG_MOVETO) path.moveTo(values[numVals - 2], values[numVals - 1]); break; default: break; } }
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; }
/** * Returns a string containing the coordinates for a given shape. This * string is intended for use in an image map. * * @param shape the shape (<code>null</code> not permitted). * * @return The coordinates for a given shape as string. */ private String getPolyCoords(Shape shape) { if (shape == null) { throw new IllegalArgumentException("Null 'shape' argument."); } StringBuffer result = new StringBuffer(); boolean first = true; float[] coords = new float[6]; PathIterator pi = shape.getPathIterator(null, 1.0); while (!pi.isDone()) { pi.currentSegment(coords); if (first) { first = false; result.append((int) coords[0]); result.append(",").append((int) coords[1]); } else { result.append(","); result.append((int) coords[0]); result.append(","); result.append((int) coords[1]); } pi.next(); } return result.toString(); }
/** * Delegates to the enclosed <code>GeneralPath</code>. */ public synchronized void closePath() { // Don't double close path. if ((numSeg != 0) && (types[numSeg - 1] == PathIterator.SEG_CLOSE)) return; // Only close path if the previous command wasn't a moveto if ((numSeg != 0) && (types[numSeg - 1] != PathIterator.SEG_MOVETO)) path.closePath(); makeRoom(0); types[numSeg++] = PathIterator.SEG_CLOSE; cx = mx; cy = my; }
protected void validateCompClip() { int origClipState = clipState; if (usrClip == null) { clipState = CLIP_DEVICE; clipRegion = devClip; } else if (usrClip instanceof Rectangle2D) { clipState = CLIP_RECTANGULAR; clipRegion = devClip.getIntersection((Rectangle2D) usrClip); } else { PathIterator cpi = usrClip.getPathIterator(null); int box[] = new int[4]; ShapeSpanIterator sr = LoopPipe.getFillSSI(this); try { sr.setOutputArea(devClip); sr.appendPath(cpi); sr.getPathBox(box); Region r = Region.getInstance(box, sr); clipRegion = r; clipState = r.isRectangular() ? CLIP_RECTANGULAR : CLIP_SHAPE; } finally { sr.dispose(); } } if (origClipState != clipState && (clipState == CLIP_SHAPE || origClipState == CLIP_SHAPE)) { validFontInfo = false; invalidatePipe(); } }
private static StringBuilder appendPath(StringBuilder sb, int indent, PathIterator pathIterator) { double[] coords = new double[6]; while (!pathIterator.isDone()) { int type = pathIterator.currentSegment(coords); String typeStr; int endIndex; switch (type) { case PathIterator.SEG_CLOSE: typeStr = "SEG_CLOSE"; endIndex = 0; break; case PathIterator.SEG_CUBICTO: typeStr = "SEG_CUBICTO"; endIndex = 6; break; case PathIterator.SEG_LINETO: typeStr = "SEG_LINETO"; endIndex = 2; break; case PathIterator.SEG_MOVETO: typeStr = "SEG_MOVETO"; endIndex = 2; break; case PathIterator.SEG_QUADTO: typeStr = "SEG_QUADTO"; endIndex = 4; break; default: throw new IllegalStateException("Invalid type=" + type); } ArrayUtilities.appendSpaces(sb, indent); sb.append(typeStr).append(": "); for (int i = 0; i < endIndex;) { sb.append("[").append(coords[i++]).append(",").append(coords[i++]).append("] "); } sb.append('\n'); pathIterator.next(); } return sb; }
static void testIterator(Path2D pathA, Path2D pathB) { final PathIterator itA = pathA.getPathIterator(at); final PathIterator itB = pathB.getPathIterator(at); float[] coordsA = new float[6]; float[] coordsB = new float[6]; int n = 0; for (; !itA.isDone() && !itB.isDone(); itA.next(), itB.next(), n++) { int typeA = itA.currentSegment(coordsA); int typeB = itB.currentSegment(coordsB); if (typeA != typeB) { throw new IllegalStateException("Path-segment[" + n + "] " + "type are not equals [" + typeA + "|" + typeB + "] !"); } // Take care of floating-point precision: if (!equalsArrayEps(coordsA, coordsB, getLength(typeA))) { throw new IllegalStateException("Path-segment[" + n + "] coords" + " are not equals [" + Arrays.toString(coordsA) + "|" + Arrays.toString(coordsB) + "] !"); } } if (!itA.isDone() || !itB.isDone()) { throw new IllegalStateException("Paths do not have same lengths !"); } log("testIterator: " + n + " segments."); }
public String getType() { final StringBuilder buffer = new StringBuilder(); if (shape != null) { final PathIterator it = shape.getPathIterator(new AffineTransform()); final float[] pts = new float[6]; while (!it.isDone()) { switch (it.currentSegment(pts)) { case PathIterator.SEG_MOVETO: buffer.append('m') .append(',') .append(Math.round(pts[0])) .append(',') .append(Math.round(pts[1])); break; case PathIterator.SEG_LINETO: case PathIterator.SEG_CUBICTO: case PathIterator.SEG_QUADTO: buffer.append('l') .append(',') .append(Math.round(pts[0])) .append(',') .append(Math.round(pts[1])); break; case PathIterator.SEG_CLOSE: buffer.append('c'); break; } it.next(); if (!it.isDone()) { buffer.append(','); } } } return ID + buffer.toString(); }
private static String shapeToSVG(Shape sh) { StringBuffer s = new StringBuffer(); double[] pts = new double[6]; for (PathIterator p = sh.getPathIterator(null); !p.isDone(); p.next()) { switch (p.currentSegment(pts)) { case PathIterator.SEG_MOVETO: s.append('M'); s.append(' '); s.append(svgRound(pts[0])); s.append(' '); s.append(svgRound(pts[1])); s.append(' '); break; case PathIterator.SEG_LINETO: s.append('L'); s.append(' '); s.append(svgRound(pts[0])); s.append(' '); s.append(svgRound(pts[1])); s.append(' '); break; case PathIterator.SEG_QUADTO: s.append('Q'); s.append(' '); s.append(svgRound(pts[0])); s.append(' '); s.append(svgRound(pts[1])); s.append(' '); s.append(svgRound(pts[2])); s.append(' '); s.append(svgRound(pts[3])); s.append(' '); break; case PathIterator.SEG_CUBICTO: s.append('C'); s.append(' '); s.append(svgRound(pts[0])); s.append(' '); s.append(svgRound(pts[1])); s.append(' '); s.append(svgRound(pts[2])); s.append(' '); s.append(svgRound(pts[3])); s.append(' '); s.append(svgRound(pts[4])); s.append(' '); s.append(svgRound(pts[5])); s.append(' '); break; case PathIterator.SEG_CLOSE: s.append('Z'); s.append(' '); break; } } return s.toString().trim(); }
@Override PathIterator getNormalizingPathIterator(final DRendererContext rdrCtx, final PathIterator src) { // NormalizingPathIterator NearestPixelCenter: return rdrCtx.nPCPathIterator.init(src); }
@Override PathIterator getNormalizingPathIterator(final DRendererContext rdrCtx, final PathIterator src) { // return original path iterator if normalization is disabled: return src; }
@Override PathIterator getNormalizingPathIterator(final RendererContext rdrCtx, final PathIterator src) { // NormalizingPathIterator NearestPixelCenter: return rdrCtx.nPCPathIterator.init(src); }
public Shape createStrokedShape(Shape shape) { // We are flattening the path iterator to only get line segments. PathIterator path = shape.getPathIterator(null, 1); float points[] = new float[6]; GeneralPath strokepath = new GeneralPath(); float ix = 0, iy = 0; float px = 0, py = 0; while (!path.isDone()) { int type = path.currentSegment(points); switch (type) { case PathIterator.SEG_MOVETO: ix = px = points[0]; iy = py = points[1]; strokepath.moveTo(ix, iy); break; case PathIterator.SEG_LINETO: strokepath.append(createArrow(px, py, points[0], points[1]), false); px = points[0]; py = points[1]; break; case PathIterator.SEG_CLOSE: if (px != ix && py != ix) strokepath.append(createArrow(px, py, ix, iy), false); break; default: strokepath.append(createArrow(px, py, points[0], points[1]), false); px = points[0]; py = points[1]; // never appear. } path.next(); } return strokepath; }
private void addGeneralPath(GeneralPath path) { PathIterator itr = path.getPathIterator(null, 0.1); ArrayList<Point2D.Float> pathList = new ArrayList(); Point2D.Float pathStart = null, lastPoint = null; boolean closed = false; while (!itr.isDone()) { float[] coords = new float[6]; int segtype = itr.currentSegment(coords); switch (segtype) { case PathIterator.SEG_MOVETO: pathStart = new Point2D.Float(coords[0], coords[1]); // save start point case PathIterator.SEG_LINETO: case PathIterator.SEG_QUADTO: case PathIterator.SEG_CUBICTO: pathList.add((lastPoint = new Point2D.Float(coords[0], coords[1]))); // TODO store quads/cubes as well as linesSVG break; case PathIterator.SEG_CLOSE: closed = true; // if (pathStart != null) { // pathList.add(pathStart); // } break; default: log.info("found other element " + segtype); } itr.next(); } if (closed && lastPoint != null) { pathList.remove(lastPoint); } if (pathList.size() > longestPath) { ballPathSVG = pathList; longestPath = ballPathSVG.size(); } pathsSVG.add(pathList); }
@Override protected void deviceFill(PathIterator pathIter, Color color) { WPrinterJob wPrinterJob = (WPrinterJob) getPrinterJob(); convertToWPath(pathIter); wPrinterJob.selectSolidBrush(color); wPrinterJob.fillPath(); }
void appendGlyphOutline(int glyphID, GeneralPath result, float x, float y) { // !!! fontStrike needs a method for this. For that matter, GeneralPath does. GeneralPath gp = null; if (sgv.invdtx == null) { gp = strike.getGlyphOutline(glyphID, x + dx, y + dy); } else { gp = strike.getGlyphOutline(glyphID, 0, 0); gp.transform(sgv.invdtx); gp.transform(AffineTransform.getTranslateInstance(x + dx, y + dy)); } PathIterator iterator = gp.getPathIterator(null); result.append(iterator, false); }
public void appendPath(PathIterator pi) { float coords[] = new float[6]; setRule(pi.getWindingRule()); while (!pi.isDone()) { addSegment(pi.currentSegment(coords), coords); pi.next(); } pathDone(); }
protected void validateCompClip() { int origClipState = clipState; if (usrClip == null) { clipState = CLIP_DEVICE; clipRegion = devClip; } else if (usrClip instanceof Rectangle2D) { clipState = CLIP_RECTANGULAR; if (usrClip instanceof Rectangle) { clipRegion = devClip.getIntersection((Rectangle)usrClip); } else { clipRegion = devClip.getIntersection(usrClip.getBounds()); } } else { PathIterator cpi = usrClip.getPathIterator(null); int box[] = new int[4]; ShapeSpanIterator sr = LoopPipe.getFillSSI(this); try { sr.setOutputArea(devClip); sr.appendPath(cpi); sr.getPathBox(box); Region r = Region.getInstance(box); r.appendSpans(sr); clipRegion = r; clipState = r.isRectangular() ? CLIP_RECTANGULAR : CLIP_SHAPE; } finally { sr.dispose(); } } if (origClipState != clipState && (clipState == CLIP_SHAPE || origClipState == CLIP_SHAPE)) { validFontInfo = false; invalidatePipe(); } }
public int getSegment(double coords[]) { if (direction == INCREASING) { coords[0] = x1; coords[1] = y1; } else { coords[0] = x0; coords[1] = y0; } return PathIterator.SEG_LINETO; }
public int getSegment(double coords[]) { coords[0] = cx0; coords[1] = cy0; if (direction == INCREASING) { coords[2] = x1; coords[3] = y1; } else { coords[2] = x0; coords[3] = y0; } return PathIterator.SEG_QUADTO; }
@Override PathIterator getNormalizingPathIterator(final RendererContext rdrCtx, final PathIterator src) { // NearestPixel NormalizingPathIterator: return rdrCtx.nPQPathIterator.init(src); }
@Override PathIterator getNormalizingPathIterator(final RendererContext rdrCtx, final PathIterator src) { // return original path iterator if normalization is disabled: return src; }
@Override PathIterator getNormalizingPathIterator(final DRendererContext rdrCtx, final PathIterator src) { // NearestPixel NormalizingPathIterator: return rdrCtx.nPQPathIterator.init(src); }
/** * Delegates to the enclosed <code>GeneralPath</code>. */ public synchronized void moveTo(float x, float y) { // Don't add moveto to general path unless there is a reason. makeRoom(2); types[numSeg++] = PathIterator.SEG_MOVETO; cx = mx = values[numVals++] = x; cy = my = values[numVals++] = y; }