本文整理匯總了Java中java.awt.Shape.getPathIterator方法的典型用法代碼示例。如果您正苦於以下問題:Java Shape.getPathIterator方法的具體用法?Java Shape.getPathIterator怎麽用?Java Shape.getPathIterator使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.awt.Shape
的用法示例。
在下文中一共展示了Shape.getPathIterator方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: checkEmptyPath
import java.awt.Shape; //導入方法依賴的package包/類
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 !");
}
}
示例2: Float
import java.awt.Shape; //導入方法依賴的package包/類
/**
* Constructs a new single precision {@code Path2D} object
* from an arbitrary {@link Shape} object, transformed by an
* {@link AffineTransform} object.
* All of the initial geometry and the winding rule for this path are
* taken from the specified {@code Shape} object and transformed
* by the specified {@code AffineTransform} object.
*
* @param s the specified {@code Shape} object
* @param at the specified {@code AffineTransform} object
* @since 1.6
*/
public Float(Shape s, AffineTransform at) {
if (s instanceof Path2D) {
Path2D p2d = (Path2D) s;
setWindingRule(p2d.windingRule);
this.numTypes = p2d.numTypes;
this.pointTypes = Arrays.copyOf(p2d.pointTypes,
p2d.pointTypes.length);
this.numCoords = p2d.numCoords;
this.floatCoords = p2d.cloneCoordsFloat(at);
} else {
PathIterator pi = s.getPathIterator(at);
setWindingRule(pi.getWindingRule());
this.pointTypes = new byte[INIT_SIZE];
this.floatCoords = new float[INIT_SIZE * 2];
append(pi, false);
}
}
示例3: mapShape
import java.awt.Shape; //導入方法依賴的package包/類
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;
}
示例4: Float
import java.awt.Shape; //導入方法依賴的package包/類
/**
* Constructs a new single precision {@code Path2D} object
* from an arbitrary {@link Shape} object, transformed by an
* {@link AffineTransform} object.
* All of the initial geometry and the winding rule for this path are
* taken from the specified {@code Shape} object and transformed
* by the specified {@code AffineTransform} object.
*
* @param s the specified {@code Shape} object
* @param at the specified {@code AffineTransform} object
* @since 1.6
*/
public Float(Shape s, AffineTransform at) {
if (s instanceof Path2D) {
Path2D p2d = (Path2D) s;
setWindingRule(p2d.windingRule);
this.numTypes = p2d.numTypes;
// trim arrays:
this.pointTypes = Arrays.copyOf(p2d.pointTypes, p2d.numTypes);
this.numCoords = p2d.numCoords;
this.floatCoords = p2d.cloneCoordsFloat(at);
} else {
PathIterator pi = s.getPathIterator(at);
setWindingRule(pi.getWindingRule());
this.pointTypes = new byte[INIT_SIZE];
this.floatCoords = new float[INIT_SIZE * 2];
append(pi, false);
}
}
示例5: getPolyCoords
import java.awt.Shape; //導入方法依賴的package包/類
/**
* 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.");
}
String result = "";
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 = result + (int) coords[0] + "," + (int) coords[1];
}
else {
result = result + "," + (int) coords[0] + "," + (int) coords[1];
}
pi.next();
}
return result;
}
示例6: getPolyCoords
import java.awt.Shape; //導入方法依賴的package包/類
/**
* 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();
}
示例7: shapeToSVG
import java.awt.Shape; //導入方法依賴的package包/類
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();
}
示例8: createStrokedShape
import java.awt.Shape; //導入方法依賴的package包/類
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;
}
示例9: toSwtPath
import java.awt.Shape; //導入方法依賴的package包/類
/**
* Converts an AWT <code>Shape</code> into a SWT <code>Path</code>.
*
* @param shape the shape.
*
* @return The path.
*/
private Path toSwtPath(Shape shape) {
int type;
float[] coords = new float[6];
Path path = new Path(this.gc.getDevice());
PathIterator pit = shape.getPathIterator(null);
while (!pit.isDone()) {
type = pit.currentSegment(coords);
switch (type) {
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;
default:
break;
}
pit.next();
}
return path;
}
示例10: drawShape
import java.awt.Shape; //導入方法依賴的package包/類
/** Draws a shape. */
public OurPDFWriter drawShape(Shape shape, boolean fillOrNot) {
if (shape instanceof Polygon) {
Polygon obj = (Polygon)shape;
for(int i = 0; i < obj.npoints; i++) buf.writes(obj.xpoints[i]).writes(obj.ypoints[i]).write(i==0 ? "m\n" : "l\n");
buf.write("h\n");
} else {
double moveX = 0, moveY = 0, nowX = 0, nowY = 0, pt[] = new double[6];
for(PathIterator it = shape.getPathIterator(null); !it.isDone(); it.next()) switch(it.currentSegment(pt)) {
case PathIterator.SEG_MOVETO:
nowX = moveX = pt[0]; nowY = moveY = pt[1]; buf.writes(nowX).writes(nowY).write("m\n"); break;
case PathIterator.SEG_CLOSE:
nowX = moveX; nowY = moveY; buf.write("h\n"); break;
case PathIterator.SEG_LINETO:
nowX = pt[0]; nowY = pt[1]; buf.writes(nowX).writes(nowY).write("l\n"); break;
case PathIterator.SEG_CUBICTO:
nowX = pt[4]; nowY = pt[5];
buf.writes(pt[0]).writes(pt[1]).writes(pt[2]).writes(pt[3]).writes(nowX).writes(nowY).write("c\n"); break;
case PathIterator.SEG_QUADTO: // Convert quadratic bezier into cubic bezier using de Casteljau algorithm
double px = nowX + (pt[0] - nowX)*(2.0/3.0), qx = px + (pt[2] - nowX)/3.0;
double py = nowY + (pt[1] - nowY)*(2.0/3.0), qy = py + (pt[3] - nowY)/3.0;
nowX = pt[2]; nowY = pt[3];
buf.writes(px).writes(py).writes(qx).writes(qy).writes(nowX).writes(nowY).write("c\n"); break;
}
}
buf.write(fillOrNot ? "f\n" : "S\n");
return this;
}
示例11: createStrokedShape
import java.awt.Shape; //導入方法依賴的package包/類
/**
* @see java.awt.Stroke#createStrokedShape(java.awt.Shape)
*/
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;
float next = 0;
int phase = 0;
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);
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;
while (distance >= next) {
float x = lastX + next * dx * r;
float y = lastY + next * dy * 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;
lastX = thisX;
lastY = thisY;
if (type == PathIterator.SEG_CLOSE) result.closePath();
break;
}
it.next();
}
return new BasicStroke(getWidth(), BasicStroke.CAP_SQUARE, getJoin()).createStrokedShape(result);
}
示例12: strokeTo
import java.awt.Shape; //導入方法依賴的package包/類
/**
* {@inheritDoc}
*/
@Override
public void strokeTo(Shape src,
AffineTransform transform,
BasicStroke bs,
boolean thin,
boolean normalize,
boolean antialias,
PathConsumer2D sr)
{
PathStroker stroker = new PathStroker(sr);
PathConsumer consumer = stroker;
float matrix[] = null;
if (!thin) {
stroker.setPenDiameter(bs.getLineWidth());
if (transform != null) {
matrix = getTransformMatrix(transform);
}
stroker.setPenT4(matrix);
stroker.setPenFitting(PenUnits, MinPenUnits);
}
stroker.setCaps(RasterizerCaps[bs.getEndCap()]);
stroker.setCorners(RasterizerCorners[bs.getLineJoin()],
bs.getMiterLimit());
float[] dashes = bs.getDashArray();
if (dashes != null) {
PathDasher dasher = new PathDasher(stroker);
dasher.setDash(dashes, bs.getDashPhase());
if (transform != null && matrix == null) {
matrix = getTransformMatrix(transform);
}
dasher.setDashT4(matrix);
consumer = dasher;
}
try {
PathIterator pi = src.getPathIterator(transform);
feedConsumer(pi, consumer, normalize, 0.25f);
} catch (PathException e) {
throw new InternalError("Unable to Stroke shape ("+
e.getMessage()+")", e);
} finally {
while (consumer != null && consumer != sr) {
PathConsumer next = consumer.getConsumer();
consumer.dispose();
consumer = next;
}
}
}
示例13: createStrokedShape
import java.awt.Shape; //導入方法依賴的package包/類
/**
* @see java.awt.Stroke#createStrokedShape(java.awt.Shape)
*/
public Shape createStrokedShape (Shape shape) {
GeneralPath result = new GeneralPath();
shape = new BasicStroke(getWidth(), BasicStroke.CAP_SQUARE, getJoin()).createStrokedShape(shape);
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;
float next = 0;
while (!it.isDone()) {
type = it.currentSegment(points);
switch (type) {
case PathIterator.SEG_MOVETO:
moveX = lastX = randomize(points[0]);
moveY = lastY = randomize(points[1]);
result.moveTo(moveX, moveY);
next = 0;
break;
case PathIterator.SEG_CLOSE:
points[0] = moveX;
points[1] = moveY;
// Fall into....
case PathIterator.SEG_LINETO:
thisX = randomize(points[0]);
thisY = randomize(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;
while (distance >= next) {
float x = lastX + next * dx * r;
float y = lastY + next * dy * r;
result.lineTo(randomize(x), randomize(y));
next += detail;
}
}
next -= distance;
lastX = thisX;
lastY = thisY;
break;
}
it.next();
}
return result;
}
示例14: drawShape
import java.awt.Shape; //導入方法依賴的package包/類
/** Draws a shape. */
public OurPDFWriter drawShape(Shape shape, boolean fillOrNot) {
if (shape instanceof Polygon) {
Polygon obj = (Polygon) shape;
for (int i = 0; i < obj.npoints; i++)
buf.writes(obj.xpoints[i]).writes(obj.ypoints[i]).write(i == 0 ? "m\n" : "l\n");
buf.write("h\n");
} else {
double moveX = 0, moveY = 0, nowX = 0, nowY = 0, pt[] = new double[6];
for (PathIterator it = shape.getPathIterator(null); !it.isDone(); it.next())
switch (it.currentSegment(pt)) {
case PathIterator.SEG_MOVETO :
nowX = moveX = pt[0];
nowY = moveY = pt[1];
buf.writes(nowX).writes(nowY).write("m\n");
break;
case PathIterator.SEG_CLOSE :
nowX = moveX;
nowY = moveY;
buf.write("h\n");
break;
case PathIterator.SEG_LINETO :
nowX = pt[0];
nowY = pt[1];
buf.writes(nowX).writes(nowY).write("l\n");
break;
case PathIterator.SEG_CUBICTO :
nowX = pt[4];
nowY = pt[5];
buf.writes(pt[0]).writes(pt[1]).writes(pt[2]).writes(pt[3]).writes(nowX).writes(nowY).write(
"c\n");
break;
case PathIterator.SEG_QUADTO : // Convert quadratic bezier
// into cubic bezier using
// de Casteljau algorithm
double px = nowX + (pt[0] - nowX) * (2.0 / 3.0), qx = px + (pt[2] - nowX) / 3.0;
double py = nowY + (pt[1] - nowY) * (2.0 / 3.0), qy = py + (pt[3] - nowY) / 3.0;
nowX = pt[2];
nowY = pt[3];
buf.writes(px).writes(py).writes(qx).writes(qy).writes(nowX).writes(nowY).write("c\n");
break;
}
}
buf.write(fillOrNot ? "f\n" : "S\n");
return this;
}
示例15: getAATileGenerator
import java.awt.Shape; //導入方法依賴的package包/類
/**
* 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;
}