本文整理匯總了Java中java.awt.geom.PathIterator類的典型用法代碼示例。如果您正苦於以下問題:Java PathIterator類的具體用法?Java PathIterator怎麽用?Java PathIterator使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
PathIterator類屬於java.awt.geom包,在下文中一共展示了PathIterator類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: NormalizingPathIterator
import java.awt.geom.PathIterator; //導入依賴的package包/類
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");
}
}
示例2: checkEmptyPath
import java.awt.geom.PathIterator; //導入依賴的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 !");
}
}
示例3: getStrokeSpans
import java.awt.geom.PathIterator; //導入依賴的package包/類
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;
}
示例4: deviceFill
import java.awt.geom.PathIterator; //導入依賴的package包/類
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);
}
示例5: testIterator
import java.awt.geom.PathIterator; //導入依賴的package包/類
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.");
}
示例6: getSegment
import java.awt.geom.PathIterator; //導入依賴的package包/類
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;
}
示例7: checkMoveTo
import java.awt.geom.PathIterator; //導入依賴的package包/類
/**
* 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;
}
}
示例8: mapShape
import java.awt.geom.PathIterator; //導入依賴的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;
}
示例9: getPolyCoords
import java.awt.geom.PathIterator; //導入依賴的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();
}
示例10: testFlattening
import java.awt.geom.PathIterator; //導入依賴的package包/類
static void testFlattening(Path2D pathA, Path2D pathB) {
final PathIterator itA = pathA.getPathIterator(at, FLATNESS);
final PathIterator itB = pathB.getPathIterator(at, FLATNESS);
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("testFlattening: " + n + " segments.");
}
示例11: closePath
import java.awt.geom.PathIterator; //導入依賴的package包/類
/**
* 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;
}
示例12: validateCompClip
import java.awt.geom.PathIterator; //導入依賴的package包/類
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();
}
}
示例13: appendPath
import java.awt.geom.PathIterator; //導入依賴的package包/類
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;
}
示例14: getType
import java.awt.geom.PathIterator; //導入依賴的package包/類
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();
}
示例15: shapeToSVG
import java.awt.geom.PathIterator; //導入依賴的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();
}