/** * Writes the <code>shape</code>, <code>coords</code>, <code>href</code>, * <code>nohref</code> Attribute for the specified figure and shape. * * @return Returns true, if the polygon is inside of the image bounds. */ private boolean writePolyAttributes(IXMLElement elem, SVGFigure f, Shape shape) { AffineTransform t = TRANSFORM.getClone(f); if (t == null) { t = drawingTransform; } else { t.preConcatenate(drawingTransform); } StringBuilder buf = new StringBuilder(); float[] coords = new float[6]; GeneralPath path = new GeneralPath(); for (PathIterator i = shape.getPathIterator(t, 1.5f); ! i.isDone(); i.next()) { switch (i.currentSegment(coords)) { case PathIterator.SEG_MOVETO : if (buf.length() != 0) { throw new IllegalArgumentException("Illegal shape "+shape); } if (buf.length() != 0) { buf.append(','); } buf.append((int) coords[0]); buf.append(','); buf.append((int) coords[1]); path.moveTo(coords[0], coords[1]); break; case PathIterator.SEG_LINETO : if (buf.length() != 0) { buf.append(','); } buf.append((int) coords[0]); buf.append(','); buf.append((int) coords[1]); path.lineTo(coords[0], coords[1]); break; case PathIterator.SEG_CLOSE : path.closePath(); break; default : throw new InternalError("Illegal segment type "+i.currentSegment(coords)); } } elem.setAttribute("shape", "poly"); elem.setAttribute("coords", buf.toString()); writeHrefAttribute(elem, f); return path.intersects(new Rectangle2D.Float(bounds.x, bounds.y, bounds.width, bounds.height)); }
/** * Build a shape for the entire subtree by joining together the shapes for each of its edges. * Vertices included since needed for FullTextPanel. */ public Shape constructInternalShape(DiagramBase diagram, boolean includeVertices) { GeneralPath shape = new GeneralPath(); Enumeration edges = m_edgeList.elements(); while (edges.hasMoreElements()) { TreeEdge edge = (TreeEdge) edges.nextElement(); Shape edgeShape = edge.getSchemeShape(diagram); PathIterator path = edgeShape.getPathIterator(null); shape.append(path, false); if (includeVertices) { Shape vertexShape; if (!edge.getSourceVertex().isVirtual()) { vertexShape = edge.getSourceVertex().getShape(diagram); path = vertexShape.getPathIterator(null); shape.append(path, false); } if (!edge.getDestVertex().isVirtual()) { vertexShape = edge.getDestVertex().getShape(diagram); path = vertexShape.getPathIterator(null); shape.append(path, false); } } } BasicStroke stroke = new BasicStroke( diagram.getSubtreeLineWidth() - DiagramBase.EDGE_OUTLINE_WIDTH + 1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER); internalShapeTable.put(diagram, stroke.createStrokedShape(shape)); return (Shape) internalShapeTable.get(diagram); }
/** * Convert an AWT Shape to an SWT Path. * * @param shape * @return the SWT Path or <code>null</code> if <code>shape == null</code> */ private Path convertToPath(Shape shape) { if (shape == null) { return null; } Path path = new Path(_gc.getDevice()); PathIterator iter = shape.getPathIterator(null); float[] coords = new float[6]; while (!iter.isDone()) { int op = iter.currentSegment(coords); switch (op) { case PathIterator.SEG_MOVETO: path.moveTo(coords[0], coords[1]); break; case PathIterator.SEG_LINETO: path.lineTo(coords[0], coords[1]); break; case PathIterator.SEG_QUADTO: path.quadTo(coords[0], coords[1], coords[2], coords[3]); break; case PathIterator.SEG_CUBICTO: path.cubicTo(coords[0], coords[1], coords[2], coords[3], coords[4], coords[5]); break; case PathIterator.SEG_CLOSE: path.close(); break; } iter.next(); } return path; }
/** Build a shape for the entire subtree by joining together the shapes for each of its edges. */ public Shape constructShape(DiagramBase diagram) { GeneralPath shape = new GeneralPath(); Enumeration edges = m_edgeList.elements(); while (edges.hasMoreElements()) { TreeEdge edge = (TreeEdge) edges.nextElement(); if (!edge.visible) { continue; } Shape edgeShape = edge.getSchemeShape(diagram); PathIterator path = edgeShape.getPathIterator(null); shape.append(path, false); } BasicStroke stroke = new BasicStroke( diagram.getSubtreeLineWidth(), BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER); shapeTable.put(diagram, stroke.createStrokedShape(shape)); return (Shape) shapeTable.get(diagram); }
/** Build a shape for the entire subtree by joining together the shapes for each of its edges. */ public Shape constructFullTextShape(DiagramBase diagram) { GeneralPath shape = new GeneralPath(); Enumeration edges = m_edgeList.elements(); while (edges.hasMoreElements()) { TreeEdge edge = (TreeEdge) edges.nextElement(); if (!edge.visible) { continue; } Shape edgeShape = edge.getSchemeShape(diagram); PathIterator path = edgeShape.getPathIterator(null); shape.append(path, false); TreeVertex vertex = edge.getSourceVertex(); if (!vertex.isVirtual()) { shape.append(vertex.getShape(diagram).getPathIterator(null), false); } vertex = edge.getDestVertex(); if (!vertex.isVirtual()) { shape.append(vertex.getShape(diagram).getPathIterator(null), false); } } BasicStroke stroke = new BasicStroke(20, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER); shapeTable.put(diagram, stroke.createStrokedShape(shape)); return (Shape) shapeTable.get(diagram); }
protected int convertPathData(Shape s, AffineTransform at) { PathIterator pi = s.getPathIterator(at); double[] coords = new double[6]; double currX = 0; double currY = 0; while (!pi.isDone()) { int curOp = pi.currentSegment(coords); int pointIndex; switch (curOp) { case PathIterator.SEG_MOVETO: ops.addByte(CAIRO_PATH_OP_MOVE_TO); pointIndex = points.getNextIndex(); points.setX(pointIndex, DoubleToCairoFixed(coords[0])); points.setY(pointIndex, DoubleToCairoFixed(coords[1])); currX = coords[0]; currY = coords[1]; break; case PathIterator.SEG_LINETO: ops.addByte(CAIRO_PATH_OP_LINE_TO); pointIndex = points.getNextIndex(); points.setX(pointIndex, DoubleToCairoFixed(coords[0])); points.setY(pointIndex, DoubleToCairoFixed(coords[1])); currX = coords[0]; currY = coords[1]; break; /** q0 = p0 q1 = (p0+2*p1)/3 q2 = (p2+2*p1)/3 q3 = p2 */ case PathIterator.SEG_QUADTO: double x1 = coords[0]; double y1 = coords[1]; double x2, y2; double x3 = coords[2]; double y3 = coords[3]; x2 = x1 + (x3 - x1) / 3; y2 = y1 + (y3 - y1) / 3; x1 = currX + 2 * (x1 - currX) / 3; y1 = currY + 2 * (y1 - currY) / 3; ops.addByte(CAIRO_PATH_OP_CURVE_TO); pointIndex = points.getNextIndex(); points.setX(pointIndex, DoubleToCairoFixed(x1)); points.setY(pointIndex, DoubleToCairoFixed(y1)); pointIndex = points.getNextIndex(); points.setX(pointIndex, DoubleToCairoFixed(x2)); points.setY(pointIndex, DoubleToCairoFixed(y2)); pointIndex = points.getNextIndex(); points.setX(pointIndex, DoubleToCairoFixed(x3)); points.setY(pointIndex, DoubleToCairoFixed(y3)); currX = x3; currY = y3; break; case PathIterator.SEG_CUBICTO: ops.addByte(CAIRO_PATH_OP_CURVE_TO); pointIndex = points.getNextIndex(); points.setX(pointIndex, DoubleToCairoFixed(coords[0])); points.setY(pointIndex, DoubleToCairoFixed(coords[1])); pointIndex = points.getNextIndex(); points.setX(pointIndex, DoubleToCairoFixed(coords[2])); points.setY(pointIndex, DoubleToCairoFixed(coords[3])); pointIndex = points.getNextIndex(); points.setX(pointIndex, DoubleToCairoFixed(coords[4])); points.setY(pointIndex, DoubleToCairoFixed(coords[5])); currX = coords[4]; currY = coords[5]; break; case PathIterator.SEG_CLOSE: ops.addByte(CAIRO_PATH_OP_CLOSE_PATH); break; } pi.next(); } return pi.getWindingRule(); }
public Shape createStrokedShape(Shape shape) { GeneralPath result = new GeneralPath(); PathIterator it = new FlatteningPathIterator(shape.getPathIterator(null), FLATNESS); float points[] = new float[6]; float moveX = 0, moveY = 0; float lastX = 0, lastY = 0; float thisX = 0, thisY = 0; int type = 0; boolean first = false; float next = 0; int phase = 0; float factor = 1; while (!it.isDone()) { type = it.currentSegment(points); switch (type) { case PathIterator.SEG_MOVETO: moveX = lastX = points[0]; moveY = lastY = points[1]; result.moveTo(moveX, moveY); first = true; next = wavelength / 2; break; case PathIterator.SEG_CLOSE: points[0] = moveX; points[1] = moveY; // Fall into.... case PathIterator.SEG_LINETO: thisX = points[0]; thisY = points[1]; float dx = thisX - lastX; float dy = thisY - lastY; float distance = (float) Math.sqrt(dx * dx + dy * dy); if (distance >= next) { float r = 1.0f / distance; float angle = (float) Math.atan2(dy, dx); while (distance >= next) { float x = lastX + next * dx * r; float y = lastY + next * dy * r; float tx = amplitude * dy * r; float ty = amplitude * dx * r; if ((phase & 1) == 0) result.lineTo(x + amplitude * dy * r, y - amplitude * dx * r); else result.lineTo(x - amplitude * dy * r, y + amplitude * dx * r); next += wavelength; phase++; } } next -= distance; first = false; lastX = thisX; lastY = thisY; if (type == PathIterator.SEG_CLOSE) result.closePath(); break; } it.next(); } // return stroke.createStrokedShape( result ); return result; }