本文整理匯總了Java中java.awt.geom.PathIterator.SEG_CUBICTO屬性的典型用法代碼示例。如果您正苦於以下問題:Java PathIterator.SEG_CUBICTO屬性的具體用法?Java PathIterator.SEG_CUBICTO怎麽用?Java PathIterator.SEG_CUBICTO使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類java.awt.geom.PathIterator
的用法示例。
在下文中一共展示了PathIterator.SEG_CUBICTO屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getSegment
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;
}
示例2: curveTo
/**
* Delegates to the enclosed <code>GeneralPath</code>.
*/
public synchronized void curveTo(float x1, float y1, float x2, float y2,
float x3, float y3)
{
checkMoveTo(); // check if prev command was moveto
path.curveTo(x1, y1, x2, y2, x3, y3);
makeRoom(6);
types[numSeg++] = PathIterator.SEG_CUBICTO;
values[numVals++] = x1;
values[numVals++] = y1;
values[numVals++] = x2;
values[numVals++] = y2;
cx = values[numVals++] = x3;
cy = values[numVals++] = y3;
}
示例3: getType
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();
}
示例4: shapeToSVG
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();
}
示例5: addGeneralPath
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);
}
示例6: feedConsumer
/**
* Utility method to feed a {@link PathConsumer2D} object from a
* given {@link PathIterator}.
* This method deals with the details of running the iterator and
* feeding the consumer a segment at a time.
*/
public static void feedConsumer(PathIterator pi, PathConsumer2D consumer) {
float coords[] = new float[6];
while (!pi.isDone()) {
switch (pi.currentSegment(coords)) {
case PathIterator.SEG_MOVETO:
consumer.moveTo(coords[0], coords[1]);
break;
case PathIterator.SEG_LINETO:
consumer.lineTo(coords[0], coords[1]);
break;
case PathIterator.SEG_QUADTO:
consumer.quadTo(coords[0], coords[1],
coords[2], coords[3]);
break;
case PathIterator.SEG_CUBICTO:
consumer.curveTo(coords[0], coords[1],
coords[2], coords[3],
coords[4], coords[5]);
break;
case PathIterator.SEG_CLOSE:
consumer.closePath();
break;
}
pi.next();
}
}
示例7: drawShape
/** 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;
}
示例8: convertToPSPath
/**
* Given a Java2D {@code PathIterator} 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();
}
}
示例9: drawShape
/** 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;
}
示例10: currentSegment
public int currentSegment(float[] coords) {
int type = src.currentSegment(coords);
int lastCoord;
switch(type) {
case PathIterator.SEG_CUBICTO:
lastCoord = 4;
break;
case PathIterator.SEG_QUADTO:
lastCoord = 2;
break;
case PathIterator.SEG_LINETO:
case PathIterator.SEG_MOVETO:
lastCoord = 0;
break;
case PathIterator.SEG_CLOSE:
// we don't want to deal with this case later. We just exit now
curx_adjust = movx_adjust;
cury_adjust = movy_adjust;
return type;
default:
throw new InternalError("Unrecognized curve type");
}
// normalize endpoint
float x_adjust = (float)Math.floor(coords[lastCoord] + lval) +
rval - coords[lastCoord];
float y_adjust = (float)Math.floor(coords[lastCoord+1] + lval) +
rval - coords[lastCoord + 1];
coords[lastCoord ] += x_adjust;
coords[lastCoord + 1] += y_adjust;
// now that the end points are done, normalize the control points
switch(type) {
case PathIterator.SEG_CUBICTO:
coords[0] += curx_adjust;
coords[1] += cury_adjust;
coords[2] += x_adjust;
coords[3] += y_adjust;
break;
case PathIterator.SEG_QUADTO:
coords[0] += (curx_adjust + x_adjust) / 2;
coords[1] += (cury_adjust + y_adjust) / 2;
break;
case PathIterator.SEG_LINETO:
break;
case PathIterator.SEG_MOVETO:
movx_adjust = x_adjust;
movy_adjust = y_adjust;
break;
case PathIterator.SEG_CLOSE:
throw new InternalError("This should be handled earlier.");
}
curx_adjust = x_adjust;
cury_adjust = y_adjust;
return type;
}
示例11: feedConsumer
private void feedConsumer(PathConsumer consumer, PathIterator pi) {
try {
consumer.beginPath();
boolean pathClosed = false;
float mx = 0.0f;
float my = 0.0f;
float point[] = new float[6];
while (!pi.isDone()) {
int type = pi.currentSegment(point);
if (pathClosed == true) {
pathClosed = false;
if (type != PathIterator.SEG_MOVETO) {
// Force current point back to last moveto point
consumer.beginSubpath(mx, my);
}
}
switch (type) {
case PathIterator.SEG_MOVETO:
mx = point[0];
my = point[1];
consumer.beginSubpath(point[0], point[1]);
break;
case PathIterator.SEG_LINETO:
consumer.appendLine(point[0], point[1]);
break;
case PathIterator.SEG_QUADTO:
consumer.appendQuadratic(point[0], point[1],
point[2], point[3]);
break;
case PathIterator.SEG_CUBICTO:
consumer.appendCubic(point[0], point[1],
point[2], point[3],
point[4], point[5]);
break;
case PathIterator.SEG_CLOSE:
consumer.closedSubpath();
pathClosed = true;
break;
}
pi.next();
}
consumer.endPath();
} catch (PathException e) {
throw new InternalError("Unable to Stroke shape ("+
e.getMessage()+")", e);
}
}
示例12: currentSegment
@Override
public final int currentSegment(final float[] coords) {
int lastCoord;
final int type = src.currentSegment(coords);
switch(type) {
case PathIterator.SEG_MOVETO:
case PathIterator.SEG_LINETO:
lastCoord = 0;
break;
case PathIterator.SEG_QUADTO:
lastCoord = 2;
break;
case PathIterator.SEG_CUBICTO:
lastCoord = 4;
break;
case PathIterator.SEG_CLOSE:
// we don't want to deal with this case later. We just exit now
curx_adjust = movx_adjust;
cury_adjust = movy_adjust;
return type;
default:
throw new InternalError("Unrecognized curve type");
}
// normalize endpoint
float coord, x_adjust, y_adjust;
coord = coords[lastCoord];
x_adjust = normCoord(coord); // new coord
coords[lastCoord] = x_adjust;
x_adjust -= coord;
coord = coords[lastCoord + 1];
y_adjust = normCoord(coord); // new coord
coords[lastCoord + 1] = y_adjust;
y_adjust -= coord;
// now that the end points are done, normalize the control points
switch(type) {
case PathIterator.SEG_MOVETO:
movx_adjust = x_adjust;
movy_adjust = y_adjust;
break;
case PathIterator.SEG_LINETO:
break;
case PathIterator.SEG_QUADTO:
coords[0] += (curx_adjust + x_adjust) / 2.0f;
coords[1] += (cury_adjust + y_adjust) / 2.0f;
break;
case PathIterator.SEG_CUBICTO:
coords[0] += curx_adjust;
coords[1] += cury_adjust;
coords[2] += x_adjust;
coords[3] += y_adjust;
break;
case PathIterator.SEG_CLOSE:
// handled earlier
default:
}
curx_adjust = x_adjust;
cury_adjust = y_adjust;
return type;
}
示例13: append
/**
* Delegates to the enclosed <code>GeneralPath</code>.
*/
public void append(ExtendedPathIterator epi, boolean connect)
{
float[] vals = new float[7];
while (!epi.isDone())
{
Arrays.fill(vals, 0);
int type = epi.currentSegment(vals);
epi.next();
if (connect && (numVals != 0))
{
if (type == PathIterator.SEG_MOVETO)
{
float x = vals[0];
float y = vals[1];
if ((x != cx) || (y != cy))
{
// Change MOVETO to LINETO.
type = PathIterator.SEG_LINETO;
}
else
{
// Redundant segment (move to current loc) drop it...
if (epi.isDone())
break; // Nothing interesting
type = epi.currentSegment(vals);
epi.next();
}
}
connect = false;
}
switch (type)
{
case PathIterator.SEG_CLOSE:
closePath();
break;
case PathIterator.SEG_MOVETO:
moveTo(vals[0], vals[1]);
break;
case PathIterator.SEG_LINETO:
lineTo(vals[0], vals[1]);
break;
case PathIterator.SEG_QUADTO:
quadTo(vals[0], vals[1], vals[2], vals[3]);
break;
case PathIterator.SEG_CUBICTO:
curveTo(vals[0], vals[1], vals[2], vals[3], vals[4],
vals[5]);
break;
case ExtendedPathIterator.SEG_ARCTO:
arcTo(vals[0], vals[1], vals[2], (vals[3] != 0),
(vals[4] != 0), vals[5], vals[6]);
break;
}
}
}
示例14: convertToPSPath
/**
* 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();
}
}
示例15: convertToWPath
/**
* 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();
}