summaryrefslogtreecommitdiffstats
path: root/awt/java/awt/BasicStroke.java
diff options
context:
space:
mode:
Diffstat (limited to 'awt/java/awt/BasicStroke.java')
-rw-r--r--awt/java/awt/BasicStroke.java1499
1 files changed, 869 insertions, 630 deletions
diff --git a/awt/java/awt/BasicStroke.java b/awt/java/awt/BasicStroke.java
index 955dc6b..2457815 100644
--- a/awt/java/awt/BasicStroke.java
+++ b/awt/java/awt/BasicStroke.java
@@ -18,6 +18,7 @@
* @author Denis M. Kishenko
* @version $Revision$
*/
+
package java.awt;
import java.awt.geom.GeneralPath;
@@ -27,139 +28,188 @@ import org.apache.harmony.awt.internal.nls.Messages;
import org.apache.harmony.misc.HashCode;
/**
- * The BasicStroke class specifies a set of rendering attributes for the outlines
- * of graphics primitives. The BasicStroke attributes describe the shape of the
- * pen which draws the outline of a Shape and the decorations applied at the ends
- * and joins of path segments of the Shape. The BasicStroke has the following
- * rendering attributes:
+ * The BasicStroke class specifies a set of rendering attributes for the
+ * outlines of graphics primitives. The BasicStroke attributes describe the
+ * shape of the pen which draws the outline of a Shape and the decorations
+ * applied at the ends and joins of path segments of the Shape. The BasicStroke
+ * has the following rendering attributes:
* <p>
* <ul>
- * <li> line width -the pen width which draws the outlines.</li>
- * <li> end caps - indicates the decoration applied to the ends of unclosed
- * subpaths and dash segments. The BasicStroke defines three different decorations:
- * CAP_BUTT, CAP_ROUND, and CAP_SQUARE.</li>
- * <li>line joins - indicates the decoration applied at the intersection of
- * two path segments and at the intersection of the endpoints of a subpath.
- * The BasicStroke defines three decorations: JOIN_BEVEL, JOIN_MITER,
- * and JOIN_ROUND.</li>
- * <li>miter limit - the limit to trim a line join that has a JOIN_MITER
+ * <li>line width -the pen width which draws the outlines.</li>
+ * <li>end caps - indicates the decoration applied to the ends of unclosed
+ * subpaths and dash segments. The BasicStroke defines three different
+ * decorations: CAP_BUTT, CAP_ROUND, and CAP_SQUARE.</li>
+ * <li>line joins - indicates the decoration applied at the intersection of two
+ * path segments and at the intersection of the endpoints of a subpath. The
+ * BasicStroke defines three decorations: JOIN_BEVEL, JOIN_MITER, and
+ * JOIN_ROUND.</li>
+ * <li>miter limit - the limit to trim a line join that has a JOIN_MITER
* decoration.</li>
- * <li>dash attributes - the definition of how to make a dash pattern by
- * alternating between opaque and transparent sections </li>
+ * <li>dash attributes - the definition of how to make a dash pattern by
+ * alternating between opaque and transparent sections</li>
* </ul>
+ * </p>
+ *
+ * @since Android 1.0
*/
public class BasicStroke implements Stroke {
- /**
- * The Constant CAP_BUTT indicates the ends of unclosed subpaths
- * and dash segments have no added decoration.
+ /**
+ * The Constant CAP_BUTT indicates the ends of unclosed subpaths and dash
+ * segments have no added decoration.
*/
public static final int CAP_BUTT = 0;
-
- /**
- * The Constant CAP_ROUND indicates the ends of unclosed subpaths
- * and dash segments have a round decoration.
+
+ /**
+ * The Constant CAP_ROUND indicates the ends of unclosed subpaths and dash
+ * segments have a round decoration.
*/
public static final int CAP_ROUND = 1;
-
- /**
- * The Constant CAP_SQUARE indicates the ends of unclosed subpaths
- * and dash segments have a square projection.
+
+ /**
+ * The Constant CAP_SQUARE indicates the ends of unclosed subpaths and dash
+ * segments have a square projection.
*/
public static final int CAP_SQUARE = 2;
- /**
- * The Constant JOIN_MITER indicates that path segments are joined by
+ /**
+ * The Constant JOIN_MITER indicates that path segments are joined by
* extending their outside edges until they meet.
*/
public static final int JOIN_MITER = 0;
-
- /**
- * The Constant JOIN_ROUND indicates that path segments are joined by
+
+ /**
+ * The Constant JOIN_ROUND indicates that path segments are joined by
* rounding off the corner at a radius of half the line width.
*/
public static final int JOIN_ROUND = 1;
-
- /**
- * The Constant JOIN_BEVEL indicates that path segments are joined by
- * connecting the outer corners of their wide outlines with
- * a straight segment.
+
+ /**
+ * The Constant JOIN_BEVEL indicates that path segments are joined by
+ * connecting the outer corners of their wide outlines with a straight
+ * segment.
*/
public static final int JOIN_BEVEL = 2;
-
- /** Constants for calculating. */
- static final int MAX_LEVEL = 20; // Maximal deepness of curve subdivision
-
- /** The Constant CURVE_DELTA. */
- static final double CURVE_DELTA = 2.0; // Width tolerance
-
- /** The Constant CORNER_ANGLE. */
+
+ /**
+ * Constants for calculating.
+ */
+ static final int MAX_LEVEL = 20; // Maximal deepness of curve subdivision
+
+ /**
+ * The Constant CURVE_DELTA.
+ */
+ static final double CURVE_DELTA = 2.0; // Width tolerance
+
+ /**
+ * The Constant CORNER_ANGLE.
+ */
static final double CORNER_ANGLE = 4.0; // Minimum corner angle
-
- /** The Constant CORNER_ZERO. */
+
+ /**
+ * The Constant CORNER_ZERO.
+ */
static final double CORNER_ZERO = 0.01; // Zero angle
-
- /** The Constant CUBIC_ARC. */
+
+ /**
+ * The Constant CUBIC_ARC.
+ */
static final double CUBIC_ARC = 4.0 / 3.0 * (Math.sqrt(2.0) - 1);
- /** Stroke width. */
+ /**
+ * Stroke width.
+ */
float width;
-
- /** Stroke cap type. */
+
+ /**
+ * Stroke cap type.
+ */
int cap;
-
- /** Stroke join type. */
+
+ /**
+ * Stroke join type.
+ */
int join;
-
- /** Stroke miter limit. */
+
+ /**
+ * Stroke miter limit.
+ */
float miterLimit;
-
- /** Stroke dashes array. */
+
+ /**
+ * Stroke dashes array.
+ */
float dash[];
-
- /** Stroke dash phase. */
+
+ /**
+ * Stroke dash phase.
+ */
float dashPhase;
- /** The temporary pre-calculated values. */
+ /**
+ * The temporary pre-calculated values.
+ */
double curveDelta;
-
- /** The corner delta. */
+
+ /**
+ * The corner delta.
+ */
double cornerDelta;
-
- /** The zero delta. */
+
+ /**
+ * The zero delta.
+ */
double zeroDelta;
- /** The w2. */
+ /**
+ * The w2.
+ */
double w2;
-
- /** The fmy. */
+
+ /**
+ * The fmy.
+ */
double fmx, fmy;
-
- /** The smy. */
+
+ /**
+ * The smy.
+ */
double scx, scy, smx, smy;
-
- /** The cy. */
+
+ /**
+ * The cy.
+ */
double mx, my, cx, cy;
- /** The temporary indicators. */
+ /**
+ * The temporary indicators.
+ */
boolean isMove;
-
- /** The is first. */
+
+ /**
+ * The is first.
+ */
boolean isFirst;
-
- /** The check move. */
+
+ /**
+ * The check move.
+ */
boolean checkMove;
-
- /** The temporary and destination work paths. */
+
+ /**
+ * The temporary and destination work paths.
+ */
BufferedPath dst, lp, rp, sp;
-
- /** Stroke dasher class. */
+
+ /**
+ * Stroke dasher class.
+ */
Dasher dasher;
/**
- * Instantiates a new BasicStroke with default width, cap, join, limit,
- * dash attributes parameters. The default parameters are a solid line of
- * width 1.0, CAP_SQUARE, JOIN_MITER, a miter limit of 10.0, null dash attributes,
+ * Instantiates a new BasicStroke with default width, cap, join, limit, dash
+ * attributes parameters. The default parameters are a solid line of width
+ * 1.0, CAP_SQUARE, JOIN_MITER, a miter limit of 10.0, null dash attributes,
* and a dash phase of 0.0f.
*/
public BasicStroke() {
@@ -167,17 +217,24 @@ public class BasicStroke implements Stroke {
}
/**
- * Instantiates a new BasicStroke with the specified width,
- * caps, joins, limit, dash attributes, dash phase parameters.
+ * Instantiates a new BasicStroke with the specified width, caps, joins,
+ * limit, dash attributes, dash phase parameters.
*
- * @param width the width of BasikStroke.
- * @param cap the end decoration of BasikStroke.
- * @param join the join segments decoration.
- * @param miterLimit the limit to trim the miter join.
- * @param dash the array with the dashing pattern.
- * @param dashPhase the offset to start the dashing pattern.
- */
- public BasicStroke(float width, int cap, int join, float miterLimit, float[] dash, float dashPhase) {
+ * @param width
+ * the width of BasikStroke.
+ * @param cap
+ * the end decoration of BasikStroke.
+ * @param join
+ * the join segments decoration.
+ * @param miterLimit
+ * the limit to trim the miter join.
+ * @param dash
+ * the array with the dashing pattern.
+ * @param dashPhase
+ * the offset to start the dashing pattern.
+ */
+ public BasicStroke(float width, int cap, int join, float miterLimit, float[] dash,
+ float dashPhase) {
if (width < 0.0f) {
// awt.133=Negative width
throw new IllegalArgumentException(Messages.getString("awt.133")); //$NON-NLS-1$
@@ -204,7 +261,7 @@ public class BasicStroke implements Stroke {
throw new IllegalArgumentException(Messages.getString("awt.138")); //$NON-NLS-1$
}
ZERO: {
- for(int i = 0; i < dash.length; i++) {
+ for (int i = 0; i < dash.length; i++) {
if (dash[i] < 0.0) {
// awt.139=Negative dash[{0}]
throw new IllegalArgumentException(Messages.getString("awt.139", i)); //$NON-NLS-1$
@@ -226,35 +283,43 @@ public class BasicStroke implements Stroke {
}
/**
- * Instantiates a new BasicStroke with specified width, cap, join, limit
- * and default dash attributes parameters.
+ * Instantiates a new BasicStroke with specified width, cap, join, limit and
+ * default dash attributes parameters.
*
- * @param width the width of BasikStroke.
- * @param cap the end decoration of BasikStroke.
- * @param join the join segments decoration.
- * @param miterLimit the limit to trim the miter join.
+ * @param width
+ * the width of BasikStroke.
+ * @param cap
+ * the end decoration of BasikStroke.
+ * @param join
+ * the join segments decoration.
+ * @param miterLimit
+ * the limit to trim the miter join.
*/
public BasicStroke(float width, int cap, int join, float miterLimit) {
this(width, cap, join, miterLimit, null, 0.0f);
}
/**
- * Instantiates a new BasicStroke with specified width, cap, join
- * and default limit and dash attributes parameters.
+ * Instantiates a new BasicStroke with specified width, cap, join and
+ * default limit and dash attributes parameters.
*
- * @param width the width of BasikStroke.
- * @param cap the end decoration of BasikStroke.
- * @param join the join segments decoration.
+ * @param width
+ * the width of BasikStroke.
+ * @param cap
+ * the end decoration of BasikStroke.
+ * @param join
+ * the join segments decoration.
*/
public BasicStroke(float width, int cap, int join) {
this(width, cap, join, 10.0f, null, 0.0f);
}
/**
- * Instantiates a new BasicStroke with specified width and default cap, join,
- * limit, dash attributes parameters.
+ * Instantiates a new BasicStroke with specified width and default cap,
+ * join, limit, dash attributes parameters.
*
- * @param width the width of BasicStroke.
+ * @param width
+ * the width of BasicStroke.
*/
public BasicStroke(float width) {
this(width, CAP_SQUARE, JOIN_MITER, 10.0f, null, 0.0f);
@@ -288,7 +353,8 @@ public class BasicStroke implements Stroke {
}
/**
- * Gets the miter limit of the BasicStroke (the limit to trim the miter join).
+ * Gets the miter limit of the BasicStroke (the limit to trim the miter
+ * join).
*
* @return the miter limit of the BasicStroke.
*/
@@ -338,10 +404,10 @@ public class BasicStroke implements Stroke {
/**
* Compares this BasicStroke object with the specified Object.
*
- * @param obj the Object to be compared.
- *
- * @return true, if the Object is a BasicStroke with the same data
- * values as this BasicStroke; false otherwise.
+ * @param obj
+ * the Object to be compared.
+ * @return true, if the Object is a BasicStroke with the same data values as
+ * this BasicStroke; false otherwise.
*/
@Override
public boolean equals(Object obj) {
@@ -350,13 +416,9 @@ public class BasicStroke implements Stroke {
}
if (obj instanceof BasicStroke) {
BasicStroke bs = (BasicStroke)obj;
- return
- bs.width == width &&
- bs.cap == cap &&
- bs.join == join &&
- bs.miterLimit == miterLimit &&
- bs.dashPhase == dashPhase &&
- java.util.Arrays.equals(bs.dash, dash);
+ return bs.width == width && bs.cap == cap && bs.join == join
+ && bs.miterLimit == miterLimit && bs.dashPhase == dashPhase
+ && java.util.Arrays.equals(bs.dash, dash);
}
return false;
}
@@ -364,9 +426,9 @@ public class BasicStroke implements Stroke {
/**
* Calculates allowable curve derivation.
*
- * @param width the width
- *
- * @return the curve delta
+ * @param width
+ * the width.
+ * @return the curve delta.
*/
double getCurveDelta(double width) {
double a = width + CURVE_DELTA;
@@ -378,9 +440,9 @@ public class BasicStroke implements Stroke {
/**
* Calculates the value to detect a small angle.
*
- * @param width the width
- *
- * @return the corner delta
+ * @param width
+ * the width.
+ * @return the corner delta.
*/
double getCornerDelta(double width) {
return width * width * Math.sin(Math.PI * CORNER_ANGLE / 180.0);
@@ -389,22 +451,21 @@ public class BasicStroke implements Stroke {
/**
* Calculates value to detect a zero angle.
*
- * @param width the width
- *
- * @return the zero delta
+ * @param width
+ * the width.
+ * @return the zero delta.
*/
double getZeroDelta(double width) {
return width * width * Math.sin(Math.PI * CORNER_ZERO / 180.0);
}
/**
- * Creates a Shape from the outline of the specified shape
- * drawn with this BasicStroke.
- *
- * @param s the specified Shape to be stroked.
+ * Creates a Shape from the outline of the specified shape drawn with this
+ * BasicStroke.
*
+ * @param s
+ * the specified Shape to be stroked.
* @return the Shape of the stroked outline.
- *
* @see java.awt.Stroke#createStrokedShape(java.awt.Shape)
*/
public Shape createStrokedShape(Shape s) {
@@ -429,7 +490,8 @@ public class BasicStroke implements Stroke {
/**
* Generates a shape with a solid (not dashed) outline.
*
- * @param p - the PathIterator of source shape
+ * @param p
+ * the PathIterator of source shape.
*/
void createSolidShape(PathIterator p) {
double coords[] = new double[6];
@@ -439,36 +501,37 @@ public class BasicStroke implements Stroke {
checkMove = true;
boolean isClosed = true;
- while(!p.isDone()) {
- switch(p.currentSegment(coords)) {
- case PathIterator.SEG_MOVETO:
- if (!isClosed) {
- closeSolidShape();
- }
- rp.clean();
- mx = cx = coords[0];
- my = cy = coords[1];
- isMove = true;
- isClosed = false;
- break;
- case PathIterator.SEG_LINETO:
- addLine(cx, cy, cx = coords[0], cy = coords[1], true);
- break;
- case PathIterator.SEG_QUADTO:
- addQuad(cx, cy, coords[0], coords[1], cx = coords[2], cy = coords[3]);
- break;
- case PathIterator.SEG_CUBICTO:
- addCubic(cx, cy, coords[0], coords[1], coords[2], coords[3], cx = coords[4], cy = coords[5]);
- break;
- case PathIterator.SEG_CLOSE:
- addLine(cx, cy, mx, my, false);
- addJoin(lp, mx, my, lp.xMove, lp.yMove, true);
- addJoin(rp, mx, my, rp.xMove, rp.yMove, false);
- lp.closePath();
- rp.closePath();
- lp.appendReverse(rp);
- isClosed = true;
- break;
+ while (!p.isDone()) {
+ switch (p.currentSegment(coords)) {
+ case PathIterator.SEG_MOVETO:
+ if (!isClosed) {
+ closeSolidShape();
+ }
+ rp.clean();
+ mx = cx = coords[0];
+ my = cy = coords[1];
+ isMove = true;
+ isClosed = false;
+ break;
+ case PathIterator.SEG_LINETO:
+ addLine(cx, cy, cx = coords[0], cy = coords[1], true);
+ break;
+ case PathIterator.SEG_QUADTO:
+ addQuad(cx, cy, coords[0], coords[1], cx = coords[2], cy = coords[3]);
+ break;
+ case PathIterator.SEG_CUBICTO:
+ addCubic(cx, cy, coords[0], coords[1], coords[2], coords[3], cx = coords[4],
+ cy = coords[5]);
+ break;
+ case PathIterator.SEG_CLOSE:
+ addLine(cx, cy, mx, my, false);
+ addJoin(lp, mx, my, lp.xMove, lp.yMove, true);
+ addJoin(rp, mx, my, rp.xMove, rp.yMove, false);
+ lp.closePath();
+ rp.closePath();
+ lp.appendReverse(rp);
+ isClosed = true;
+ break;
}
p.next();
}
@@ -492,7 +555,8 @@ public class BasicStroke implements Stroke {
/**
* Generates dashed stroked shape.
*
- * @param p - the PathIterator of source shape
+ * @param p
+ * the PathIterator of source shape.
*/
void createDashedShape(PathIterator p) {
double coords[] = new double[6];
@@ -502,52 +566,53 @@ public class BasicStroke implements Stroke {
checkMove = false;
boolean isClosed = true;
- while(!p.isDone()) {
- switch(p.currentSegment(coords)) {
- case PathIterator.SEG_MOVETO:
+ while (!p.isDone()) {
+ switch (p.currentSegment(coords)) {
+ case PathIterator.SEG_MOVETO:
- if (!isClosed) {
- closeDashedShape();
- }
+ if (!isClosed) {
+ closeDashedShape();
+ }
- dasher = new Dasher(dash, dashPhase);
- lp.clean();
- rp.clean();
- sp = null;
- isFirst = true;
- isMove = true;
- isClosed = false;
- mx = cx = coords[0];
- my = cy = coords[1];
- break;
- case PathIterator.SEG_LINETO:
- addDashLine(cx, cy, cx = coords[0], cy = coords[1]);
- break;
- case PathIterator.SEG_QUADTO:
- addDashQuad(cx, cy, coords[0], coords[1], cx = coords[2], cy = coords[3]);
- break;
- case PathIterator.SEG_CUBICTO:
- addDashCubic(cx, cy, coords[0], coords[1], coords[2], coords[3], cx = coords[4], cy = coords[5]);
- break;
- case PathIterator.SEG_CLOSE:
- addDashLine(cx, cy, cx = mx, cy = my);
-
- if (dasher.isConnected()) {
- // Connect current and head segments
- addJoin(lp, fmx, fmy, sp.xMove, sp.yMove, true);
- lp.join(sp);
- addJoin(lp, fmx, fmy, rp.xLast, rp.yLast, true);
- lp.combine(rp);
- addCap(lp, smx, smy, lp.xMove, lp.yMove);
- lp.closePath();
- dst.append(lp);
+ dasher = new Dasher(dash, dashPhase);
+ lp.clean();
+ rp.clean();
sp = null;
- } else {
- closeDashedShape();
- }
+ isFirst = true;
+ isMove = true;
+ isClosed = false;
+ mx = cx = coords[0];
+ my = cy = coords[1];
+ break;
+ case PathIterator.SEG_LINETO:
+ addDashLine(cx, cy, cx = coords[0], cy = coords[1]);
+ break;
+ case PathIterator.SEG_QUADTO:
+ addDashQuad(cx, cy, coords[0], coords[1], cx = coords[2], cy = coords[3]);
+ break;
+ case PathIterator.SEG_CUBICTO:
+ addDashCubic(cx, cy, coords[0], coords[1], coords[2], coords[3],
+ cx = coords[4], cy = coords[5]);
+ break;
+ case PathIterator.SEG_CLOSE:
+ addDashLine(cx, cy, cx = mx, cy = my);
- isClosed = true;
- break;
+ if (dasher.isConnected()) {
+ // Connect current and head segments
+ addJoin(lp, fmx, fmy, sp.xMove, sp.yMove, true);
+ lp.join(sp);
+ addJoin(lp, fmx, fmy, rp.xLast, rp.yLast, true);
+ lp.combine(rp);
+ addCap(lp, smx, smy, lp.xMove, lp.yMove);
+ lp.closePath();
+ dst.append(lp);
+ sp = null;
+ } else {
+ closeDashedShape();
+ }
+
+ isClosed = true;
+ break;
}
p.next();
}
@@ -583,11 +648,16 @@ public class BasicStroke implements Stroke {
/**
* Adds cap to the work path.
*
- * @param p - the BufferedPath object of work path
- * @param x0 - the x coordinate of the source path
- * @param y0 - the y coordinate on the source path
- * @param x2 - the x coordinate of the next point on the work path
- * @param y2 - the y coordinate of the next point on the work path
+ * @param p
+ * the BufferedPath object of work path.
+ * @param x0
+ * the x coordinate of the source path.
+ * @param y0
+ * the y coordinate on the source path.
+ * @param x2
+ * the x coordinate of the next point on the work path.
+ * @param y2
+ * the y coordinate of the next point on the work path.
*/
void addCap(BufferedPath p, double x0, double y0, double x2, double y2) {
double x1 = p.xLast;
@@ -597,42 +667,49 @@ public class BasicStroke implements Stroke {
double x20 = x2 - x0;
double y20 = y2 - y0;
- switch(cap) {
- case CAP_BUTT:
- p.lineTo(x2, y2);
- break;
- case CAP_ROUND:
- double mx = x10 * CUBIC_ARC;
- double my = y10 * CUBIC_ARC;
-
- double x3 = x0 + y10;
- double y3 = y0 - x10;
-
- x10 *= CUBIC_ARC;
- y10 *= CUBIC_ARC;
- x20 *= CUBIC_ARC;
- y20 *= CUBIC_ARC;
-
- p.cubicTo(x1 + y10, y1 - x10, x3 + mx, y3 + my, x3, y3);
- p.cubicTo(x3 - mx, y3 - my, x2 - y20, y2 + x20, x2, y2);
- break;
- case CAP_SQUARE:
- p.lineTo(x1 + y10, y1 - x10);
- p.lineTo(x2 - y20, y2 + x20);
- p.lineTo(x2, y2);
- break;
+ switch (cap) {
+ case CAP_BUTT:
+ p.lineTo(x2, y2);
+ break;
+ case CAP_ROUND:
+ double mx = x10 * CUBIC_ARC;
+ double my = y10 * CUBIC_ARC;
+
+ double x3 = x0 + y10;
+ double y3 = y0 - x10;
+
+ x10 *= CUBIC_ARC;
+ y10 *= CUBIC_ARC;
+ x20 *= CUBIC_ARC;
+ y20 *= CUBIC_ARC;
+
+ p.cubicTo(x1 + y10, y1 - x10, x3 + mx, y3 + my, x3, y3);
+ p.cubicTo(x3 - mx, y3 - my, x2 - y20, y2 + x20, x2, y2);
+ break;
+ case CAP_SQUARE:
+ p.lineTo(x1 + y10, y1 - x10);
+ p.lineTo(x2 - y20, y2 + x20);
+ p.lineTo(x2, y2);
+ break;
}
}
/**
* Adds bevel and miter join to the work path.
*
- * @param p - the BufferedPath object of work path
- * @param x0 - the x coordinate of the source path
- * @param y0 - the y coordinate on the source path
- * @param x2 - the x coordinate of the next point on the work path
- * @param y2 - the y coordinate of the next point on the work path
- * @param isLeft - the orientation of work path, true if work path lies to the left from source path, false otherwise
+ * @param p
+ * the BufferedPath object of work path.
+ * @param x0
+ * the x coordinate of the source path.
+ * @param y0
+ * the y coordinate on the source path.
+ * @param x2
+ * the x coordinate of the next point on the work path.
+ * @param y2
+ * the y coordinate of the next point on the work path.
+ * @param isLeft
+ * the orientation of work path, true if work path lies to the
+ * left from source path, false otherwise.
*/
void addJoin(BufferedPath p, double x0, double y0, double x2, double y2, boolean isLeft) {
double x1 = p.xLast;
@@ -667,26 +744,26 @@ public class BasicStroke implements Stroke {
p.lineTo(x0, y0);
p.lineTo(x2, y2);
} else {
- switch(join) {
- case JOIN_BEVEL:
- p.lineTo(x2, y2);
- break;
- case JOIN_MITER:
- double s1 = x1 * x10 + y1 * y10;
- double s2 = x2 * x20 + y2 * y20;
- double x3 = (s1 * y20 - s2 * y10) / sin0;
- double y3 = (s2 * x10 - s1 * x20) / sin0;
- double x30 = x3 - x0;
- double y30 = y3 - y0;
- double miterLength = Math.sqrt(x30 * x30 + y30 * y30);
- if (miterLength < miterLimit * w2) {
- p.lineTo(x3, y3);
- }
- p.lineTo(x2, y2);
- break;
- case JOIN_ROUND:
- addRoundJoin(p, x0, y0, x2, y2, isLeft);
- break;
+ switch (join) {
+ case JOIN_BEVEL:
+ p.lineTo(x2, y2);
+ break;
+ case JOIN_MITER:
+ double s1 = x1 * x10 + y1 * y10;
+ double s2 = x2 * x20 + y2 * y20;
+ double x3 = (s1 * y20 - s2 * y10) / sin0;
+ double y3 = (s2 * x10 - s1 * x20) / sin0;
+ double x30 = x3 - x0;
+ double y30 = y3 - y0;
+ double miterLength = Math.sqrt(x30 * x30 + y30 * y30);
+ if (miterLength < miterLimit * w2) {
+ p.lineTo(x3, y3);
+ }
+ p.lineTo(x2, y2);
+ break;
+ case JOIN_ROUND:
+ addRoundJoin(p, x0, y0, x2, y2, isLeft);
+ break;
}
}
}
@@ -694,12 +771,19 @@ public class BasicStroke implements Stroke {
/**
* Adds round join to the work path.
*
- * @param p - the BufferedPath object of work path
- * @param x0 - the x coordinate of the source path
- * @param y0 - the y coordinate on the source path
- * @param x2 - the x coordinate of the next point on the work path
- * @param y2 - the y coordinate of the next point on the work path
- * @param isLeft - the orientation of work path, true if work path lies to the left from source path, false otherwise
+ * @param p
+ * the BufferedPath object of work path.
+ * @param x0
+ * the x coordinate of the source path.
+ * @param y0
+ * the y coordinate on the source path.
+ * @param x2
+ * the x coordinate of the next point on the work path.
+ * @param y2
+ * the y coordinate of the next point on the work path.
+ * @param isLeft
+ * the orientation of work path, true if work path lies to the
+ * left from source path, false otherwise.
*/
void addRoundJoin(BufferedPath p, double x0, double y0, double x2, double y2, boolean isLeft) {
double x1 = p.xLast;
@@ -763,11 +847,16 @@ public class BasicStroke implements Stroke {
/**
* Adds solid line segment to the work path.
*
- * @param x1 - the x coordinate of the start line point
- * @param y1 - the y coordinate of the start line point
- * @param x2 - the x coordinate of the end line point
- * @param y2 - the y coordinate of the end line point
- * @param zero - if true it's allowable to add zero length line segment
+ * @param x1
+ * the x coordinate of the start line point.
+ * @param y1
+ * the y coordinate of the start line point.
+ * @param x2
+ * the x coordinate of the end line point.
+ * @param y2
+ * the y coordinate of the end line point.
+ * @param zero
+ * if true it's allowable to add zero length line segment.
*/
void addLine(double x1, double y1, double x2, double y2, boolean zero) {
double dx = x2 - x1;
@@ -808,12 +897,18 @@ public class BasicStroke implements Stroke {
/**
* Adds solid quad segment to the work path.
*
- * @param x1 - the x coordinate of the first control point
- * @param y1 - the y coordinate of the first control point
- * @param x2 - the x coordinate of the second control point
- * @param y2 - the y coordinate of the second control point
- * @param x3 - the x coordinate of the third control point
- * @param y3 - the y coordinate of the third control point
+ * @param x1
+ * the x coordinate of the first control point.
+ * @param y1
+ * the y coordinate of the first control point.
+ * @param x2
+ * the x coordinate of the second control point.
+ * @param y2
+ * the y coordinate of the second control point.
+ * @param x3
+ * the x coordinate of the third control point.
+ * @param y3
+ * the y coordinate of the third control point.
*/
void addQuad(double x1, double y1, double x2, double y2, double x3, double y3) {
double x21 = x2 - x1;
@@ -841,11 +936,11 @@ public class BasicStroke implements Stroke {
double w;
w = w2 / l21;
- double mx1 = - y21 * w;
- double my1 = x21 * w;
+ double mx1 = -y21 * w;
+ double my1 = x21 * w;
w = w2 / l23;
- double mx3 = y23 * w;
- double my3 = - x23 * w;
+ double mx3 = y23 * w;
+ double my3 = -x23 * w;
double lx1 = x1 + mx1;
double ly1 = y1 + my1;
@@ -903,15 +998,23 @@ public class BasicStroke implements Stroke {
}
/**
- * Subdivides solid quad curve to make outline for source quad segment and adds it to work path.
+ * Subdivides solid quad curve to make outline for source quad segment and
+ * adds it to work path.
*
- * @param x1 - the x coordinate of the first control point
- * @param y1 - the y coordinate of the first control point
- * @param x2 - the x coordinate of the second control point
- * @param y2 - the y coordinate of the second control point
- * @param x3 - the x coordinate of the third control point
- * @param y3 - the y coordinate of the third control point
- * @param level - the maximum level of subdivision deepness
+ * @param x1
+ * the x coordinate of the first control point.
+ * @param y1
+ * the y coordinate of the first control point.
+ * @param x2
+ * the x coordinate of the second control point.
+ * @param y2
+ * the y coordinate of the second control point.
+ * @param x3
+ * the x coordinate of the third control point.
+ * @param y3
+ * the y coordinate of the third control point.
+ * @param level
+ * the maximum level of subdivision deepness.
*/
void addSubQuad(double x1, double y1, double x2, double y2, double x3, double y3, int level) {
double x21 = x2 - x1;
@@ -939,8 +1042,8 @@ public class BasicStroke implements Stroke {
double mx2 = (x21 * l23 + x23 * l21) * w;
double my2 = (y21 * l23 + y23 * l21) * w;
w = w2 / l23;
- double mx3 = y23 * w;
- double my3 = - x23 * w;
+ double mx3 = y23 * w;
+ double my3 = -x23 * w;
lp.quadTo(x2 + mx2, y2 + my2, x3 + mx3, y3 + my3);
rp.quadTo(x2 - mx2, y2 - my2, x3 - mx3, y3 - my3);
}
@@ -949,16 +1052,25 @@ public class BasicStroke implements Stroke {
/**
* Adds solid cubic segment to the work path.
*
- * @param x1 - the x coordinate of the first control point
- * @param y1 - the y coordinate of the first control point
- * @param x2 - the x coordinate of the second control point
- * @param y2 - the y coordinate of the second control point
- * @param x3 - the x coordinate of the third control point
- * @param y3 - the y coordinate of the third control point
- * @param x4 - the x coordinate of the fours control point
- * @param y4 - the y coordinate of the fours control point
- */
- void addCubic(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) {
+ * @param x1
+ * the x coordinate of the first control point.
+ * @param y1
+ * the y coordinate of the first control point.
+ * @param x2
+ * the x coordinate of the second control point.
+ * @param y2
+ * the y coordinate of the second control point.
+ * @param x3
+ * the x coordinate of the third control point.
+ * @param y3
+ * the y coordinate of the third control point.
+ * @param x4
+ * the x coordinate of the fours control point.
+ * @param y4
+ * the y coordinate of the fours control point.
+ */
+ void addCubic(double x1, double y1, double x2, double y2, double x3, double y3, double x4,
+ double y4) {
double x12 = x1 - x2;
double y12 = y1 - y2;
double x23 = x2 - x3;
@@ -997,35 +1109,32 @@ public class BasicStroke implements Stroke {
if (l12 == 0.0) {
w = w2 / l23;
- mx1 = y23 * w;
- my1 = - x23 * w;
+ mx1 = y23 * w;
+ my1 = -x23 * w;
w = w2 / l34;
- mx4 = y34 * w;
- my4 = - x34 * w;
- onLine = - x23 * y34 + y23 * x34 == 0.0; // sin3
- } else
- if (l34 == 0.0) {
+ mx4 = y34 * w;
+ my4 = -x34 * w;
+ onLine = -x23 * y34 + y23 * x34 == 0.0; // sin3
+ } else if (l34 == 0.0) {
w = w2 / l12;
- mx1 = y12 * w;
- my1 = - x12 * w;
+ mx1 = y12 * w;
+ my1 = -x12 * w;
w = w2 / l23;
- mx4 = y23 * w;
- my4 = - x23 * w;
- onLine = - x12 * y23 + y12 * x23 == 0.0; // sin2
+ mx4 = y23 * w;
+ my4 = -x23 * w;
+ onLine = -x12 * y23 + y12 * x23 == 0.0; // sin2
} else {
w = w2 / l12;
- mx1 = y12 * w;
- my1 = - x12 * w;
+ mx1 = y12 * w;
+ my1 = -x12 * w;
w = w2 / l34;
- mx4 = y34 * w;
- my4 = - x34 * w;
+ mx4 = y34 * w;
+ my4 = -x34 * w;
if (l23 == 0.0) {
- onLine = - x12 * y34 + y12 * x34 == 0.0;
+ onLine = -x12 * y34 + y12 * x34 == 0.0;
} else {
- onLine =
- - x12 * y34 + y12 * x34 == 0.0 &&
- - x12 * y23 + y12 * x23 == 0.0 && // sin2
- - x23 * y34 + y23 * x34 == 0.0; // sin3
+ onLine = -x12 * y34 + y12 * x34 == 0.0 && -x12 * y23 + y12 * x23 == 0.0 && // sin2
+ -x23 * y34 + y23 * x34 == 0.0; // sin3
}
}
@@ -1063,8 +1172,7 @@ public class BasicStroke implements Stroke {
if (0.0 < t && t < 1.0) {
roots[rc++] = t;
}
- } else
- if (d > 0.0) {
+ } else if (d > 0.0) {
d = Math.sqrt(d);
double z = l12 + l34 - l23 - l23;
double t;
@@ -1087,15 +1195,15 @@ public class BasicStroke implements Stroke {
}
roots[rc++] = 1.0;
- double ax = - x34 - x12 + x23 + x23;
- double ay = - y34 - y12 + y23 + y23;
- double bx = 3.0 * (- x23 + x12);
- double by = 3.0 * (- y23 + y12);
- double cx = 3.0 * (- x12);
- double cy = 3.0 * (- y12);
+ double ax = -x34 - x12 + x23 + x23;
+ double ay = -y34 - y12 + y23 + y23;
+ double bx = 3.0 * (-x23 + x12);
+ double by = 3.0 * (-y23 + y12);
+ double cx = 3.0 * (-x12);
+ double cy = 3.0 * (-y12);
double xPrev = x1;
double yPrev = y1;
- for(int i = 0; i < rc; i++) {
+ for (int i = 0; i < rc; i++) {
double t = roots[i];
double px = t * (t * (t * ax + bx) + cx) + x1;
double py = t * (t * (t * ay + by) + cy) + y1;
@@ -1109,8 +1217,8 @@ public class BasicStroke implements Stroke {
}
xPrev = px;
yPrev = py;
- mx1 = - mx1;
- my1 = - my1;
+ mx1 = -mx1;
+ my1 = -my1;
}
} else {
lp.cubicTo(x2 + mx1, y2 + my1, x3 + mx4, y3 + my4, x4 + mx4, y4 + my4);
@@ -1122,19 +1230,30 @@ public class BasicStroke implements Stroke {
}
/**
- * Subdivides solid cubic curve to make outline for source quad segment and adds it to work path.
+ * Subdivides solid cubic curve to make outline for source quad segment and
+ * adds it to work path.
*
- * @param x1 - the x coordinate of the first control point
- * @param y1 - the y coordinate of the first control point
- * @param x2 - the x coordinate of the second control point
- * @param y2 - the y coordinate of the second control point
- * @param x3 - the x coordinate of the third control point
- * @param y3 - the y coordinate of the third control point
- * @param x4 - the x coordinate of the fours control point
- * @param y4 - the y coordinate of the fours control point
- * @param level - the maximum level of subdivision deepness
- */
- void addSubCubic(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4, int level) {
+ * @param x1
+ * the x coordinate of the first control point.
+ * @param y1
+ * the y coordinate of the first control point.
+ * @param x2
+ * the x coordinate of the second control point.
+ * @param y2
+ * the y coordinate of the second control point.
+ * @param x3
+ * the x coordinate of the third control point.
+ * @param y3
+ * the y coordinate of the third control point.
+ * @param x4
+ * the x coordinate of the fours control point.
+ * @param y4
+ * the y coordinate of the fours control point.
+ * @param level
+ * the maximum level of subdivision deepness.
+ */
+ void addSubCubic(double x1, double y1, double x2, double y2, double x3, double y3, double x4,
+ double y4, int level) {
double x12 = x1 - x2;
double y12 = y1 - y2;
double x23 = x2 - x3;
@@ -1142,19 +1261,18 @@ public class BasicStroke implements Stroke {
double x34 = x3 - x4;
double y34 = y3 - y4;
- double cos2 = - x12 * x23 - y12 * y23;
- double cos3 = - x23 * x34 - y23 * y34;
- double sin2 = - x12 * y23 + y12 * x23;
- double sin3 = - x23 * y34 + y23 * x34;
- double sin0 = - x12 * y34 + y12 * x34;
- double cos0 = - x12 * x34 - y12 * y34;
-
- if (level < MAX_LEVEL && (sin2 != 0.0 || sin3 != 0.0 || sin0 != 0.0) &&
- (cos2 >= 0.0 || cos3 >= 0.0 || cos0 >= 0.0 ||
- (Math.abs(sin2 / cos2) > curveDelta) ||
- (Math.abs(sin3 / cos3) > curveDelta) ||
- (Math.abs(sin0 / cos0) > curveDelta)))
- {
+ double cos2 = -x12 * x23 - y12 * y23;
+ double cos3 = -x23 * x34 - y23 * y34;
+ double sin2 = -x12 * y23 + y12 * x23;
+ double sin3 = -x23 * y34 + y23 * x34;
+ double sin0 = -x12 * y34 + y12 * x34;
+ double cos0 = -x12 * x34 - y12 * y34;
+
+ if (level < MAX_LEVEL
+ && (sin2 != 0.0 || sin3 != 0.0 || sin0 != 0.0)
+ && (cos2 >= 0.0 || cos3 >= 0.0 || cos0 >= 0.0
+ || (Math.abs(sin2 / cos2) > curveDelta)
+ || (Math.abs(sin3 / cos3) > curveDelta) || (Math.abs(sin0 / cos0) > curveDelta))) {
double cx = (x2 + x3) / 2.0;
double cy = (y2 + y3) / 2.0;
double lx2 = (x2 + x1) / 2.0;
@@ -1177,27 +1295,26 @@ public class BasicStroke implements Stroke {
if (l12 == 0.0) {
w = w2 / l23;
- mx1 = y23 * w;
- my1 = - x23 * w;
+ mx1 = y23 * w;
+ my1 = -x23 * w;
w = w2 / l34;
- mx4 = y34 * w;
- my4 = - x34 * w;
- } else
- if (l34 == 0.0) {
+ mx4 = y34 * w;
+ my4 = -x34 * w;
+ } else if (l34 == 0.0) {
w = w2 / l12;
- mx1 = y12 * w;
- my1 = - x12 * w;
+ mx1 = y12 * w;
+ my1 = -x12 * w;
w = w2 / l23;
- mx4 = y23 * w;
- my4 = - x23 * w;
+ mx4 = y23 * w;
+ my4 = -x23 * w;
} else {
// Common case
w = w2 / l12;
- mx1 = y12 * w;
- my1 = - x12 * w;
+ mx1 = y12 * w;
+ my1 = -x12 * w;
w = w2 / l34;
- mx4 = y34 * w;
- my4 = - x34 * w;
+ mx4 = y34 * w;
+ my4 = -x34 * w;
}
if (sin2 == 0.0) {
@@ -1225,10 +1342,14 @@ public class BasicStroke implements Stroke {
/**
* Adds dashed line segment to the work path.
*
- * @param x1 - the x coordinate of the start line point
- * @param y1 - the y coordinate of the start line point
- * @param x2 - the x coordinate of the end line point
- * @param y2 - the y coordinate of the end line point
+ * @param x1
+ * the x coordinate of the start line point.
+ * @param y1
+ * the y coordinate of the start line point.
+ * @param x2
+ * the x coordinate of the end line point.
+ * @param y2
+ * the y coordinate of the end line point.
*/
void addDashLine(double x1, double y1, double x2, double y2) {
double x21 = x2 - x1;
@@ -1243,12 +1364,12 @@ public class BasicStroke implements Stroke {
double px1, py1;
px1 = py1 = 0.0;
double w = w2 / l21;
- double mx = - y21 * w;
- double my = x21 * w;
+ double mx = -y21 * w;
+ double my = x21 * w;
dasher.init(new DashIterator.Line(l21));
- while(!dasher.eof()) {
+ while (!dasher.eof()) {
double t = dasher.getValue();
scx = x1 + t * x21;
scy = y1 + t * y21;
@@ -1271,28 +1392,27 @@ public class BasicStroke implements Stroke {
addJoin(lp, x1, y1, lx1, ly1, true);
addJoin(rp, x1, y1, rx1, ry1, false);
}
- } else
- if (dasher.isContinue()) {
- double px2 = scx;
- double py2 = scy;
- lp.lineTo(px2 + mx, py2 + my);
- rp.lineTo(px2 - mx, py2 - my);
- if (dasher.close) {
- addCap(lp, px2, py2, rp.xLast, rp.yLast);
- lp.combine(rp);
- if (isFirst) {
- isFirst = false;
- fmx = smx;
- fmy = smy;
- sp = lp;
- lp = new BufferedPath();
- } else {
- addCap(lp, smx, smy, lp.xMove, lp.yMove);
- lp.closePath();
- }
- isMove = true;
+ } else if (dasher.isContinue()) {
+ double px2 = scx;
+ double py2 = scy;
+ lp.lineTo(px2 + mx, py2 + my);
+ rp.lineTo(px2 - mx, py2 - my);
+ if (dasher.close) {
+ addCap(lp, px2, py2, rp.xLast, rp.yLast);
+ lp.combine(rp);
+ if (isFirst) {
+ isFirst = false;
+ fmx = smx;
+ fmy = smy;
+ sp = lp;
+ lp = new BufferedPath();
+ } else {
+ addCap(lp, smx, smy, lp.xMove, lp.yMove);
+ lp.closePath();
}
+ isMove = true;
}
+ }
dasher.next();
}
@@ -1301,12 +1421,18 @@ public class BasicStroke implements Stroke {
/**
* Adds dashed quad segment to the work path.
*
- * @param x1 - the x coordinate of the first control point
- * @param y1 - the y coordinate of the first control point
- * @param x2 - the x coordinate of the second control point
- * @param y2 - the y coordinate of the second control point
- * @param x3 - the x coordinate of the third control point
- * @param y3 - the y coordinate of the third control point
+ * @param x1
+ * the x coordinate of the first control point.
+ * @param y1
+ * the y coordinate of the first control point.
+ * @param x2
+ * the x coordinate of the second control point.
+ * @param y2
+ * the y coordinate of the second control point.
+ * @param x3
+ * the x coordinate of the third control point.
+ * @param y3
+ * the y coordinate of the third control point.
*/
void addDashQuad(double x1, double y1, double x2, double y2, double x3, double y3) {
@@ -1345,7 +1471,7 @@ public class BasicStroke implements Stroke {
dasher.init(new DashIterator.Quad(x1, y1, x2, y2, x3, y3));
- while(!dasher.eof()) {
+ while (!dasher.eof()) {
double t = dasher.getValue();
double dx = t * ax + bx;
double dy = t * ay + by;
@@ -1357,8 +1483,8 @@ public class BasicStroke implements Stroke {
dx1 = dx;
dy1 = dy;
double w = w2 / Math.sqrt(dx1 * dx1 + dy1 * dy1);
- double mx1 = - dy1 * w;
- double my1 = dx1 * w;
+ double mx1 = -dy1 * w;
+ double my1 = dx1 * w;
double lx1 = px1 + mx1;
double ly1 = py1 + my1;
double rx1 = px1 - mx1;
@@ -1374,33 +1500,32 @@ public class BasicStroke implements Stroke {
addJoin(lp, x1, y1, lx1, ly1, true);
addJoin(rp, x1, y1, rx1, ry1, false);
}
- } else
- if (dasher.isContinue()) {
- double px3 = scx;
- double py3 = scy;
- double sx = x2 - x23 * prev;
- double sy = y2 - y23 * prev;
- double t2 = (t - prev) / (1 - prev);
- double px2 = px1 + (sx - px1) * t2;
- double py2 = py1 + (sy - py1) * t2;
-
- addQuad(px1, py1, px2, py2, px3, py3);
- if (dasher.isClosed()) {
- addCap(lp, px3, py3, rp.xLast, rp.yLast);
- lp.combine(rp);
- if (isFirst) {
- isFirst = false;
- fmx = smx;
- fmy = smy;
- sp = lp;
- lp = new BufferedPath();
- } else {
- addCap(lp, smx, smy, lp.xMove, lp.yMove);
- lp.closePath();
- }
- isMove = true;
+ } else if (dasher.isContinue()) {
+ double px3 = scx;
+ double py3 = scy;
+ double sx = x2 - x23 * prev;
+ double sy = y2 - y23 * prev;
+ double t2 = (t - prev) / (1 - prev);
+ double px2 = px1 + (sx - px1) * t2;
+ double py2 = py1 + (sy - py1) * t2;
+
+ addQuad(px1, py1, px2, py2, px3, py3);
+ if (dasher.isClosed()) {
+ addCap(lp, px3, py3, rp.xLast, rp.yLast);
+ lp.combine(rp);
+ if (isFirst) {
+ isFirst = false;
+ fmx = smx;
+ fmy = smy;
+ sp = lp;
+ lp = new BufferedPath();
+ } else {
+ addCap(lp, smx, smy, lp.xMove, lp.yMove);
+ lp.closePath();
}
+ isMove = true;
}
+ }
prev = t;
dasher.next();
@@ -1410,16 +1535,25 @@ public class BasicStroke implements Stroke {
/**
* Adds dashed cubic segment to the work path.
*
- * @param x1 - the x coordinate of the first control point
- * @param y1 - the y coordinate of the first control point
- * @param x2 - the x coordinate of the second control point
- * @param y2 - the y coordinate of the second control point
- * @param x3 - the x coordinate of the third control point
- * @param y3 - the y coordinate of the third control point
- * @param x4 - the x coordinate of the fours control point
- * @param y4 - the y coordinate of the fours control point
+ * @param x1
+ * the x coordinate of the first control point.
+ * @param y1
+ * the y coordinate of the first control point.
+ * @param x2
+ * the x coordinate of the second control point.
+ * @param y2
+ * the y coordinate of the second control point.
+ * @param x3
+ * the x coordinate of the third control point.
+ * @param y3
+ * the y coordinate of the third control point.
+ * @param x4
+ * the x coordinate of the fours control point.
+ * @param y4
+ * the y coordinate of the fours control point.
*/
- void addDashCubic(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) {
+ void addDashCubic(double x1, double y1, double x2, double y2, double x3, double y3, double x4,
+ double y4) {
double x12 = x1 - x2;
double y12 = y1 - y2;
@@ -1469,7 +1603,7 @@ public class BasicStroke implements Stroke {
dasher.init(new DashIterator.Cubic(x1, y1, x2, y2, x3, y3, x4, y4));
- while(!dasher.eof()) {
+ while (!dasher.eof()) {
double t = dasher.getValue();
scx = t * (t * (t * ax + bx) + cx) + dx;
@@ -1480,8 +1614,8 @@ public class BasicStroke implements Stroke {
double dx1 = t * (t * (ax + ax + ax) + bx + bx) + cx;
double dy1 = t * (t * (ay + ay + ay) + by + by) + cy;
double w = w2 / Math.sqrt(dx1 * dx1 + dy1 * dy1);
- double mx1 = - dy1 * w;
- double my1 = dx1 * w;
+ double mx1 = -dy1 * w;
+ double my1 = dx1 * w;
double lx1 = px1 + mx1;
double ly1 = py1 + my1;
double rx1 = px1 - mx1;
@@ -1497,42 +1631,41 @@ public class BasicStroke implements Stroke {
addJoin(lp, x1, y1, lx1, ly1, true);
addJoin(rp, x1, y1, rx1, ry1, false);
}
- } else
- if (dasher.isContinue()) {
- double sx1 = x2 - x23 * prev;
- double sy1 = y2 - y23 * prev;
- double sx2 = x3 - x34 * prev;
- double sy2 = y3 - y34 * prev;
- double sx3 = sx1 + (sx2 - sx1) * prev;
- double sy3 = sy1 + (sy2 - sy1) * prev;
- double t2 = (t - prev) / (1 - prev);
- double sx4 = sx3 + (sx2 - sx3) * t2;
- double sy4 = sy3 + (sy2 - sy3) * t2;
-
- double px4 = scx;
- double py4 = scy;
- double px2 = px1 + (sx3 - px1) * t2;
- double py2 = py1 + (sy3 - py1) * t2;
- double px3 = px2 + (sx4 - px2) * t2;
- double py3 = py2 + (sy4 - py2) * t2;
-
- addCubic(px1, py1, px2, py2, px3, py3, px4, py4);
- if (dasher.isClosed()) {
- addCap(lp, px4, py4, rp.xLast, rp.yLast);
- lp.combine(rp);
- if (isFirst) {
- isFirst = false;
- fmx = smx;
- fmy = smy;
- sp = lp;
- lp = new BufferedPath();
- } else {
- addCap(lp, smx, smy, lp.xMove, lp.yMove);
- lp.closePath();
- }
- isMove = true;
+ } else if (dasher.isContinue()) {
+ double sx1 = x2 - x23 * prev;
+ double sy1 = y2 - y23 * prev;
+ double sx2 = x3 - x34 * prev;
+ double sy2 = y3 - y34 * prev;
+ double sx3 = sx1 + (sx2 - sx1) * prev;
+ double sy3 = sy1 + (sy2 - sy1) * prev;
+ double t2 = (t - prev) / (1 - prev);
+ double sx4 = sx3 + (sx2 - sx3) * t2;
+ double sy4 = sy3 + (sy2 - sy3) * t2;
+
+ double px4 = scx;
+ double py4 = scy;
+ double px2 = px1 + (sx3 - px1) * t2;
+ double py2 = py1 + (sy3 - py1) * t2;
+ double px3 = px2 + (sx4 - px2) * t2;
+ double py3 = py2 + (sy4 - py2) * t2;
+
+ addCubic(px1, py1, px2, py2, px3, py3, px4, py4);
+ if (dasher.isClosed()) {
+ addCap(lp, px4, py4, rp.xLast, rp.yLast);
+ lp.combine(rp);
+ if (isFirst) {
+ isFirst = false;
+ fmx = smx;
+ fmy = smy;
+ sp = lp;
+ lp = new BufferedPath();
+ } else {
+ addCap(lp, smx, smy, lp.xMove, lp.yMove);
+ lp.closePath();
}
+ isMove = true;
}
+ }
prev = t;
dasher.next();
@@ -1543,30 +1676,44 @@ public class BasicStroke implements Stroke {
* Dasher class provides dashing for particular dash style.
*/
class Dasher {
-
- /** The pos. */
+
+ /**
+ * The pos.
+ */
double pos;
-
- /** The first. */
+
+ /**
+ * The first.
+ */
boolean close, visible, first;
-
- /** The dash. */
+
+ /**
+ * The dash.
+ */
float dash[];
-
- /** The phase. */
+
+ /**
+ * The phase.
+ */
float phase;
-
- /** The index. */
+
+ /**
+ * The index.
+ */
int index;
-
- /** The iter. */
+
+ /**
+ * The iter.
+ */
DashIterator iter;
-
+
/**
* Instantiates a new dasher.
*
- * @param dash the dash
- * @param phase the phase
+ * @param dash
+ * the dash.
+ * @param phase
+ * the phase.
*/
Dasher(float dash[], float phase) {
this.dash = dash;
@@ -1578,52 +1725,53 @@ public class BasicStroke implements Stroke {
visible = !visible;
pos -= dash[index];
index = (index + 1) % dash.length;
- }
+ }
pos = -pos;
first = visible;
}
-
+
/**
* Inits the.
*
- * @param iter the iter
+ * @param iter
+ * the iter.
*/
void init(DashIterator iter) {
this.iter = iter;
close = true;
}
-
+
/**
* Checks if is open.
*
- * @return true, if is open
+ * @return true, if is open.
*/
boolean isOpen() {
return visible && pos < iter.length;
}
-
+
/**
* Checks if is continue.
*
- * @return true, if is continue
+ * @return true, if is continue.
*/
boolean isContinue() {
return !visible && pos > 0;
}
-
+
/**
* Checks if is closed.
*
- * @return true, if is closed
+ * @return true, if is closed.
*/
boolean isClosed() {
return close;
}
-
+
/**
* Checks if is connected.
*
- * @return true, if is connected
+ * @return true, if is connected.
*/
boolean isConnected() {
return first && !close;
@@ -1632,7 +1780,7 @@ public class BasicStroke implements Stroke {
/**
* Eof.
*
- * @return true, if successful
+ * @return true, if successful.
*/
boolean eof() {
if (!close) {
@@ -1648,7 +1796,7 @@ public class BasicStroke implements Stroke {
}
return false;
}
-
+
/**
* Next.
*/
@@ -1663,17 +1811,17 @@ public class BasicStroke implements Stroke {
}
visible = !visible;
}
-
+
/**
* Gets the value.
*
- * @return the value
+ * @return the value.
*/
double getValue() {
double t = iter.getNext(pos);
return t < 0 ? 0 : (t > 1 ? 1 : t);
}
-
+
}
/**
@@ -1681,7 +1829,9 @@ public class BasicStroke implements Stroke {
*/
static abstract class DashIterator {
- /** The Constant FLATNESS. */
+ /**
+ * The Constant FLATNESS.
+ */
static final double FLATNESS = 1.0;
/**
@@ -1692,7 +1842,8 @@ public class BasicStroke implements Stroke {
/**
* Instantiates a new line.
*
- * @param len the len
+ * @param len
+ * the len.
*/
Line(double len) {
length = len;
@@ -1710,36 +1861,56 @@ public class BasicStroke implements Stroke {
*/
static class Quad extends DashIterator {
- /** The val size. */
+ /**
+ * The val size.
+ */
int valSize;
-
- /** The val pos. */
+
+ /**
+ * The val pos.
+ */
int valPos;
-
- /** The cur len. */
+
+ /**
+ * The cur len.
+ */
double curLen;
-
- /** The prev len. */
+
+ /**
+ * The prev len.
+ */
double prevLen;
-
- /** The last len. */
+
+ /**
+ * The last len.
+ */
double lastLen;
-
- /** The values. */
+
+ /**
+ * The values.
+ */
double[] values;
-
- /** The step. */
+
+ /**
+ * The step.
+ */
double step;
/**
* Instantiates a new quad.
*
- * @param x1 the x1
- * @param y1 the y1
- * @param x2 the x2
- * @param y2 the y2
- * @param x3 the x3
- * @param y3 the y3
+ * @param x1
+ * the x1.
+ * @param y1
+ * the y1.
+ * @param x2
+ * the x2.
+ * @param y2
+ * the y2.
+ * @param x3
+ * the x3.
+ * @param y3
+ * the y3.
*/
Quad(double x1, double y1, double x2, double y2, double x3, double y3) {
@@ -1766,7 +1937,7 @@ public class BasicStroke implements Stroke {
double pvx = vx;
double pvy = vy;
length = 0.0;
- for(int i = 0; i < n; i++) {
+ for (int i = 0; i < n; i++) {
vx += dx1;
vy += dy1;
dx1 += dx2;
@@ -1804,40 +1975,63 @@ public class BasicStroke implements Stroke {
*/
static class Cubic extends DashIterator {
- /** The val size. */
+ /**
+ * The val size.
+ */
int valSize;
-
- /** The val pos. */
+
+ /**
+ * The val pos.
+ */
int valPos;
-
- /** The cur len. */
+
+ /**
+ * The cur len.
+ */
double curLen;
-
- /** The prev len. */
+
+ /**
+ * The prev len.
+ */
double prevLen;
-
- /** The last len. */
+
+ /**
+ * The last len.
+ */
double lastLen;
-
- /** The values. */
+
+ /**
+ * The values.
+ */
double[] values;
-
- /** The step. */
+
+ /**
+ * The step.
+ */
double step;
/**
* Instantiates a new cubic.
*
- * @param x1 the x1
- * @param y1 the y1
- * @param x2 the x2
- * @param y2 the y2
- * @param x3 the x3
- * @param y3 the y3
- * @param x4 the x4
- * @param y4 the y4
+ * @param x1
+ * the x1.
+ * @param y1
+ * the y1.
+ * @param x2
+ * the x2.
+ * @param y2
+ * the y2.
+ * @param x3
+ * the x3.
+ * @param y3
+ * the y3.
+ * @param x4
+ * the x4.
+ * @param y4
+ * the y4.
*/
- Cubic(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) {
+ Cubic(double x1, double y1, double x2, double y2, double x3, double y3, double x4,
+ double y4) {
double nx1 = x1 + x3 - x2 - x2;
double ny1 = y1 + y3 - y2 - y2;
@@ -1869,7 +2063,7 @@ public class BasicStroke implements Stroke {
double pvx = vx;
double pvy = vy;
length = 0.0;
- for(int i = 0; i < n; i++) {
+ for (int i = 0; i < n; i++) {
vx += dx1;
vy += dy1;
dx1 += dx2;
@@ -1904,15 +2098,17 @@ public class BasicStroke implements Stroke {
}
- /** The length. */
+ /**
+ * The length.
+ */
double length;
/**
* Gets the next.
*
- * @param dashPos the dash pos
- *
- * @return the next
+ * @param dashPos
+ * the dash pos.
+ * @return the next.
*/
abstract double getNext(double dashPos);
@@ -1923,39 +2119,60 @@ public class BasicStroke implements Stroke {
*/
static class BufferedPath {
- /** The Constant bufCapacity. */
+ /**
+ * The Constant bufCapacity.
+ */
private static final int bufCapacity = 10;
- /** The point shift. */
+ /**
+ * The point shift.
+ */
static int pointShift[] = {
- 2, // MOVETO
- 2, // LINETO
- 4, // QUADTO
- 6, // CUBICTO
- 0}; // CLOSE
+ 2, // MOVETO
+ 2, // LINETO
+ 4, // QUADTO
+ 6, // CUBICTO
+ 0
+ }; // CLOSE
- /** The types. */
+ /**
+ * The types.
+ */
byte[] types;
-
- /** The points. */
+
+ /**
+ * The points.
+ */
float[] points;
-
- /** The type size. */
+
+ /**
+ * The type size.
+ */
int typeSize;
-
- /** The point size. */
+
+ /**
+ * The point size.
+ */
int pointSize;
- /** The x last. */
+ /**
+ * The x last.
+ */
float xLast;
-
- /** The y last. */
+
+ /**
+ * The y last.
+ */
float yLast;
-
- /** The x move. */
+
+ /**
+ * The x move.
+ */
float xMove;
-
- /** The y move. */
+
+ /**
+ * The y move.
+ */
float yMove;
/**
@@ -1969,8 +2186,10 @@ public class BasicStroke implements Stroke {
/**
* Check buf.
*
- * @param typeCount the type count
- * @param pointCount the point count
+ * @param typeCount
+ * the type count.
+ * @param pointCount
+ * the point count.
*/
void checkBuf(int typeCount, int pointCount) {
if (typeSize + typeCount > types.length) {
@@ -1988,7 +2207,7 @@ public class BasicStroke implements Stroke {
/**
* Checks if is empty.
*
- * @return true, if is empty
+ * @return true, if is empty.
*/
boolean isEmpty() {
return typeSize == 0;
@@ -2005,8 +2224,10 @@ public class BasicStroke implements Stroke {
/**
* Move to.
*
- * @param x the x
- * @param y the y
+ * @param x
+ * the x.
+ * @param y
+ * the y.
*/
void moveTo(double x, double y) {
checkBuf(1, 2);
@@ -2018,8 +2239,10 @@ public class BasicStroke implements Stroke {
/**
* Line to.
*
- * @param x the x
- * @param y the y
+ * @param x
+ * the x.
+ * @param y
+ * the y.
*/
void lineTo(double x, double y) {
checkBuf(1, 2);
@@ -2031,10 +2254,14 @@ public class BasicStroke implements Stroke {
/**
* Quad to.
*
- * @param x1 the x1
- * @param y1 the y1
- * @param x2 the x2
- * @param y2 the y2
+ * @param x1
+ * the x1.
+ * @param y1
+ * the y1.
+ * @param x2
+ * the x2.
+ * @param y2
+ * the y2.
*/
void quadTo(double x1, double y1, double x2, double y2) {
checkBuf(1, 4);
@@ -2048,12 +2275,18 @@ public class BasicStroke implements Stroke {
/**
* Cubic to.
*
- * @param x1 the x1
- * @param y1 the y1
- * @param x2 the x2
- * @param y2 the y2
- * @param x3 the x3
- * @param y3 the y3
+ * @param x1
+ * the x1.
+ * @param y1
+ * the y1.
+ * @param x2
+ * the x2.
+ * @param y2
+ * the y2.
+ * @param x3
+ * the x3.
+ * @param y3
+ * the y3.
*/
void cubicTo(double x1, double y1, double x2, double y2, double x3, double y3) {
checkBuf(1, 6);
@@ -2077,8 +2310,10 @@ public class BasicStroke implements Stroke {
/**
* Sets the last.
*
- * @param x the x
- * @param y the y
+ * @param x
+ * the x.
+ * @param y
+ * the y.
*/
void setLast(double x, double y) {
points[pointSize - 2] = xLast = (float)x;
@@ -2088,7 +2323,8 @@ public class BasicStroke implements Stroke {
/**
* Append.
*
- * @param p the p
+ * @param p
+ * the p.
*/
void append(BufferedPath p) {
checkBuf(p.typeSize, p.pointSize);
@@ -2103,18 +2339,19 @@ public class BasicStroke implements Stroke {
/**
* Append reverse.
*
- * @param p the p
+ * @param p
+ * the p.
*/
void appendReverse(BufferedPath p) {
checkBuf(p.typeSize, p.pointSize);
// Skip last point, beacause it's the first point of the second path
- for(int i = p.pointSize - 2; i >= 0; i -= 2) {
+ for (int i = p.pointSize - 2; i >= 0; i -= 2) {
points[pointSize++] = p.points[i + 0];
points[pointSize++] = p.points[i + 1];
}
// Skip first type, beacuse it's always MOVETO
int closeIndex = 0;
- for(int i = p.typeSize - 1; i >= 0; i--) {
+ for (int i = p.typeSize - 1; i >= 0; i--) {
byte type = p.types[i];
if (type == PathIterator.SEG_MOVETO) {
types[closeIndex] = PathIterator.SEG_MOVETO;
@@ -2133,7 +2370,8 @@ public class BasicStroke implements Stroke {
/**
* Join.
*
- * @param p the p
+ * @param p
+ * the p.
*/
void join(BufferedPath p) {
// Skip MOVETO
@@ -2149,17 +2387,18 @@ public class BasicStroke implements Stroke {
/**
* Combine.
*
- * @param p the p
+ * @param p
+ * the p.
*/
void combine(BufferedPath p) {
checkBuf(p.typeSize - 1, p.pointSize - 2);
// Skip last point, beacause it's the first point of the second path
- for(int i = p.pointSize - 4; i >= 0; i -= 2) {
+ for (int i = p.pointSize - 4; i >= 0; i -= 2) {
points[pointSize++] = p.points[i + 0];
points[pointSize++] = p.points[i + 1];
}
// Skip first type, beacuse it's always MOVETO
- for(int i = p.typeSize - 1; i >= 1; i--) {
+ for (int i = p.typeSize - 1; i >= 1; i--) {
types[typeSize++] = p.types[i];
}
xLast = points[pointSize - 2];
@@ -2169,29 +2408,30 @@ public class BasicStroke implements Stroke {
/**
* Creates the general path.
*
- * @return the general path
+ * @return the general path.
*/
GeneralPath createGeneralPath() {
GeneralPath p = new GeneralPath();
int j = 0;
- for(int i = 0; i < typeSize; i++) {
+ for (int i = 0; i < typeSize; i++) {
int type = types[i];
- switch(type){
- case PathIterator.SEG_MOVETO:
- p.moveTo(points[j], points[j + 1]);
- break;
- case PathIterator.SEG_LINETO:
- p.lineTo(points[j], points[j + 1]);
- break;
- case PathIterator.SEG_QUADTO:
- p.quadTo(points[j], points[j + 1], points[j + 2], points[j + 3]);
- break;
- case PathIterator.SEG_CUBICTO:
- p.curveTo(points[j], points[j + 1], points[j + 2], points[j + 3], points[j + 4], points[j + 5]);
- break;
- case PathIterator.SEG_CLOSE:
- p.closePath();
- break;
+ switch (type) {
+ case PathIterator.SEG_MOVETO:
+ p.moveTo(points[j], points[j + 1]);
+ break;
+ case PathIterator.SEG_LINETO:
+ p.lineTo(points[j], points[j + 1]);
+ break;
+ case PathIterator.SEG_QUADTO:
+ p.quadTo(points[j], points[j + 1], points[j + 2], points[j + 3]);
+ break;
+ case PathIterator.SEG_CUBICTO:
+ p.curveTo(points[j], points[j + 1], points[j + 2], points[j + 3],
+ points[j + 4], points[j + 5]);
+ break;
+ case PathIterator.SEG_CLOSE:
+ p.closePath();
+ break;
}
j += pointShift[type];
}
@@ -2201,4 +2441,3 @@ public class BasicStroke implements Stroke {
}
}
-