/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* The <code>Dasher</code> class takes a series of linear commands
* (<code>moveTo</code>, <code>lineTo</code>, <code>close</code> and
* <code>end</code>) and breaks them into smaller segments according to a
* dash pattern array and a starting dash phase.
*
* <p> Issues: in J2Se, a zero length dash segment as drawn as a very
* short dash, whereas Pisces does not draw anything. The PostScript
* semantics are unclear.
*
*/
private final float[] dash;
private final float startPhase;
private final boolean startDashOn;
private final int startIdx;
private boolean starting;
private boolean needsMoveTo;
private int idx;
private boolean dashOn;
private float phase;
// temporary storage for the current curve
private float[] curCurvepts;
/**
* Constructs a <code>Dasher</code>.
*
* @param out an output <code>PathConsumer2D</code>.
* @param dash an array of <code>float</code>s containing the dash pattern
* @param phase a <code>float</code> containing the dash phase
*/
if (phase < 0) {
throw new IllegalArgumentException("phase < 0 !");
}
// Normalize so 0 <= phase < dash[0]
int idx = 0;
dashOn = true;
float d;
phase -= d;
}
this.startDashOn = dashOn;
this.starting = true;
// we need curCurvepts to be able to contain 2 curves because when
// dashing curves, we need to subdivide it
}
if (firstSegidx > 0) {
}
needsMoveTo = true;
this.dashOn = this.startDashOn;
this.phase = this.startPhase;
this.starting = true;
}
switch (type) {
case 8:
break;
case 6:
break;
case 4:
}
}
private void emitFirstSegments() {
for (int i = 0; i < firstSegidx; ) {
i += (((int)firstSegmentsBuffer[i]) - 1);
}
firstSegidx = 0;
}
// We don't emit the first dash right away. If we did, caps would be
// drawn on it, but we need joins to be drawn if there's a closePath()
// So, we store the path elements that make up the first dash in the
// buffer below.
// precondition: pts must be in relative coordinates (relative to x0,y0)
// fullCurve is true iff the curve in pts has not been split.
if (dashOn) {
if (starting) {
} else {
if (needsMoveTo) {
needsMoveTo = false;
}
}
} else {
starting = false;
needsMoveTo = true;
}
this.x0 = x;
this.y0 = y;
}
if (len == 0) {
return;
}
// The scaling factors needed to get the dx and dy of the
// transformed dash segments.
while (true) {
if (len <= leftInThisDashSegment) {
// Advance phase within current dash segment
if (len == leftInThisDashSegment) {
phase = 0f;
}
return;
}
if (phase == 0) {
} else {
}
// Advance to next dash segment
phase = 0;
}
}
// preconditions: curCurvepts must be an array of length at least 2 * type,
// that contains the curve we want to dash in the first type elements
return;
}
}
float lastSplitT = 0;
float t = 0;
if (t != 0) {
curCurvepts, 0,
lastSplitT = t;
curCurveoff = type;
}
// Advance to next dash segment
phase = 0;
}
phase = 0f;
}
}
for (int i = 2; i < type; i++) {
return false;
}
}
return true;
}
// Objects of this class are used to iterate through curves. They return
// t values where the left side of the curve has a specified length.
// It does this by subdividing the input curve until a certain error
// condition has been met. A recursive subdivision procedure would
// return as many as 1<<limit curves, but this is an iterator and we
// don't need all the curves all at once, so what we carry out a
// lazy inorder traversal of the recursion tree (meaning we only move
// through the tree when we need the next subdivided curve). This saves
// us a lot of memory because at any one time we only need to store
// limit+1 curves - one for each level of the tree + 1.
// NOTE: the way we do things here is not enough to traverse a general
// tree; however, the trees we are interested in have the property that
// every non leaf node has exactly 2 children
private static class LengthIterator {
// Holds the curves at various levels of the recursion. The root
// (i.e. the original curve) is at recCurveStack[0] (but then it
// gets subdivided, the left half is put at 1, so most of the time
// only the right half of the original curve is at 0)
private float[][] recCurveStack;
// sides[i] indicates whether the node at level i+1 in the path from
// the root to the current leaf is a left or right child of its parent.
private int curveType;
private final int limit;
private final float ERR;
private final float minTincrement;
// lastT and nextT delimit the current leaf.
private float nextT;
private float lenAtNextT;
private float lastT;
private float lenAtLastT;
private float lenAtLastSplit;
private float lastSegLen;
// the current level in the recursion tree. 0 is the root. limit
// is the deepest possible leaf.
private int recLevel;
private boolean done;
// the lengths of the lines of the control polygon. Only its first
// curveType/2 - 1 elements are valid. This is an optimization. See
// next(float) for more detail.
// if any methods are called without first initializing this object on
// a curve, we want it to fail ASAP.
this.done = true;
}
this.recLevel = 0;
this.lastT = 0;
this.lenAtLastT = 0;
this.nextT = 0;
this.lenAtNextT = 0;
goLeft(); // initializes nextT and lenAtNextT properly
this.lenAtLastSplit = 0;
if (recLevel > 0) {
this.done = false;
} else {
// the root of the tree is a leaf so we're done.
this.done = true;
}
this.lastSegLen = 0;
}
// 0 == false, 1 == true, -1 == invalid cached value.
if (cachedHaveLowAcceleration == -1) {
// It is using a multiplication instead of a division, so it
// should be a bit faster.
return false;
}
if (curveType == 8) {
// if len1 is close to 2 and 2 is close to 3, that probably
// means 1 is close to 3 so the second part of this test might
// not be needed, but it doesn't hurt to include it.
return false;
}
}
return true;
}
return (cachedHaveLowAcceleration == 1);
}
// we want to avoid allocations/gc so we keep this array so we
// can put roots in it,
// caches the coefficients of the current leaf in its flattened
// form (see inside next() for what that means). The cache is
// invalid when it's third element is negative, since in any
// valid flattened curve, this would be >= 0.
// returns the t value where the remaining curve should be split in
// order for the left subdivided curve to have length len. If len
// is >= than the length of the uniterated curve, it returns 1.
while(lenAtNextT < targetLength) {
if (done) {
return 1;
}
goToNextLeaf();
}
// cubicRootsInAB is a fairly expensive call, so we just don't do it
// if the acceleration in this section of the curve is small enough.
if (!haveLowAcceleration(0.05f)) {
// We flatten the current leaf along the x axis, so that we're
// left with a, b, c which define a 1D Bezier curve. We then
// solve this to get the parameter of the original leaf that
// gives us the desired length.
y = x+curLeafCtrlPolyLengths[1];
if (curveType == 8) {
float z = y + curLeafCtrlPolyLengths[2];
flatLeafCoefCache[3] = -z;
} else if (curveType == 6) {
flatLeafCoefCache[3] = -y;
}
}
float a = flatLeafCoefCache[0];
float b = flatLeafCoefCache[1];
float c = flatLeafCoefCache[2];
float d = t*flatLeafCoefCache[3];
// we use cubicRootsInAB here, because we want only roots in 0, 1,
// and our quadratic root finder doesn't filter, so it's just a
// matter of convenience.
t = nextRoots[0];
}
}
// t is relative to the current leaf, so we must make it a valid parameter
// of the original curve.
if (t >= 1) {
t = 1;
done = true;
}
// even if done = true, if we're here, that means targetLength
// is equal to, or very, very close to the total length of the
// curve, so lastSegLen won't be too high. In cases where len
// overshoots the curve, this method will exit in the while
// loop, and lastSegLen will still be set to the right value.
lastSegLen = len;
return t;
}
public float lastSegLen() {
return lastSegLen;
}
// go to the next leaf (in an inorder traversal) in the recursion tree
// preconditions: must be on a leaf, and that leaf must not be the root.
private void goToNextLeaf() {
// We must go to the first ancestor node that has an unvisited
// right child.
recLevel--;
if (recLevel == 0) {
done = true;
return;
}
recLevel--;
}
recLevel++;
goLeft();
}
// go to the leftmost node from the current node. Return its length.
private void goLeft() {
if (len >= 0) {
lenAtNextT += len;
// invalidate caches
} else {
recLevel++;
goLeft();
}
}
// this is a bit of a hack. It returns -1 if we're not on a leaf, and
// the length of the leaf if we are on a leaf.
private float onLeaf() {
float polyLen = 0;
}
}
return -1;
}
}
{
somethingTo(8);
}
somethingTo(6);
}
public void closePath() {
if (firstSegidx > 0) {
if (!dashOn || needsMoveTo) {
}
}
}
public void pathDone() {
if (firstSegidx > 0) {
}
}
public long getNativeConsumer() {
throw new InternalError("Dasher does not use a native consumer");
}
}