use of java.awt.geom.PathIterator in project platform_frameworks_base by android.
the class PathMeasure_Delegate method native_isClosed.
@LayoutlibDelegate
static /*package*/
boolean native_isClosed(long native_instance) {
PathMeasure_Delegate pathMeasure = sManager.getDelegate(native_instance);
assert pathMeasure != null;
Path_Delegate path = Path_Delegate.getDelegate(pathMeasure.mNativePath);
if (path == null) {
return false;
}
int type = 0;
float[] segment = new float[6];
for (PathIterator pi = path.getJavaShape().getPathIterator(null); !pi.isDone(); pi.next()) {
type = pi.currentSegment(segment);
}
// A path is a closed path if the last element is SEG_CLOSE
return type == PathIterator.SEG_CLOSE;
}
use of java.awt.geom.PathIterator in project platform_frameworks_base by android.
the class Path_Delegate method isEmpty.
/**
* Returns whether the path is empty (contains no lines or curves).
* @see Path#isEmpty
*/
public boolean isEmpty() {
if (!mCachedIsEmpty) {
return false;
}
float[] coords = new float[6];
mCachedIsEmpty = Boolean.TRUE;
for (PathIterator it = mPath.getPathIterator(null); !it.isDone(); it.next()) {
int type = it.currentSegment(coords);
if (type != PathIterator.SEG_MOVETO) {
// Once we know that the path is not empty, we do not need to check again unless
// Path#reset is called.
mCachedIsEmpty = false;
return false;
}
}
return true;
}
use of java.awt.geom.PathIterator in project platform_frameworks_base by android.
the class Path_Delegate method native_approximate.
@LayoutlibDelegate
static float[] native_approximate(long nPath, float error) {
Path_Delegate pathDelegate = sManager.getDelegate(nPath);
if (pathDelegate == null) {
return null;
}
// Get a FlatteningIterator
PathIterator iterator = pathDelegate.getJavaShape().getPathIterator(null, error);
float[] segment = new float[6];
float totalLength = 0;
ArrayList<Point2D.Float> points = new ArrayList<Point2D.Float>();
Point2D.Float previousPoint = null;
while (!iterator.isDone()) {
int type = iterator.currentSegment(segment);
Point2D.Float currentPoint = new Point2D.Float(segment[0], segment[1]);
// MoveTo shouldn't affect the length
if (previousPoint != null && type != PathIterator.SEG_MOVETO) {
totalLength += currentPoint.distance(previousPoint);
}
previousPoint = currentPoint;
points.add(currentPoint);
iterator.next();
}
int nPoints = points.size();
float[] result = new float[nPoints * 3];
previousPoint = null;
for (int i = 0; i < nPoints; i++) {
Point2D.Float point = points.get(i);
float distance = previousPoint != null ? (float) previousPoint.distance(point) : .0f;
result[i * 3] = distance / totalLength;
result[i * 3 + 1] = point.x;
result[i * 3 + 2] = point.y;
totalLength += distance;
previousPoint = point;
}
return result;
}
use of java.awt.geom.PathIterator in project platform_frameworks_base by android.
the class Path_Delegate method transform.
/**
* Transform the points in this path by matrix, and write the answer
* into dst. If dst is null, then the the original path is modified.
*
* @param matrix The matrix to apply to the path
* @param dst The transformed path is written here. If dst is null,
* then the the original path is modified
*/
public void transform(Matrix_Delegate matrix, Path_Delegate dst) {
if (matrix.hasPerspective()) {
assert false;
Bridge.getLog().fidelityWarning(LayoutLog.TAG_MATRIX_AFFINE, "android.graphics.Path#transform() only " + "supports affine transformations.", null, null);
}
GeneralPath newPath = new GeneralPath();
PathIterator iterator = mPath.getPathIterator(matrix.getAffineTransform());
newPath.append(iterator, false);
if (dst != null) {
dst.mPath = newPath;
} else {
mPath = newPath;
}
}
use of java.awt.geom.PathIterator in project jdk8u_jdk by JetBrains.
the class PiscesRenderingEngine method strokeTo.
void strokeTo(Shape src, AffineTransform at, float width, NormMode normalize, int caps, int join, float miterlimit, float[] dashes, float dashphase, PathConsumer2D pc2d) {
// We use strokerat and outat so that in Stroker and Dasher we can work only
// with the pre-transformation coordinates. This will repeat a lot of
// computations done in the path iterator, but the alternative is to
// work with transformed paths and compute untransformed coordinates
// as needed. This would be faster but I do not think the complexity
// of working with both untransformed and transformed coordinates in
// the same code is worth it.
// However, if a path's width is constant after a transformation,
// we can skip all this untransforming.
// If normalization is off we save some transformations by not
// transforming the input to pisces. Instead, we apply the
// transformation after the path processing has been done.
// We can't do this if normalization is on, because it isn't a good
// idea to normalize before the transformation is applied.
AffineTransform strokerat = null;
AffineTransform outat = null;
PathIterator pi = null;
if (at != null && !at.isIdentity()) {
final double a = at.getScaleX();
final double b = at.getShearX();
final double c = at.getShearY();
final double d = at.getScaleY();
final double det = a * d - c * b;
if (Math.abs(det) <= 2 * Float.MIN_VALUE) {
// this rendering engine takes one dimensional curves and turns
// them into 2D shapes by giving them width.
// However, if everything is to be passed through a singular
// transformation, these 2D shapes will be squashed down to 1D
// again so, nothing can be drawn.
// Every path needs an initial moveTo and a pathDone. If these
// are not there this causes a SIGSEGV in libawt.so (at the time
// of writing of this comment (September 16, 2010)). Actually,
// I am not sure if the moveTo is necessary to avoid the SIGSEGV
// but the pathDone is definitely needed.
pc2d.moveTo(0, 0);
pc2d.pathDone();
return;
}
// leave a bit of room for error.
if (nearZero(a * b + c * d, 2) && nearZero(a * a + c * c - (b * b + d * d), 2)) {
double scale = Math.sqrt(a * a + c * c);
if (dashes != null) {
dashes = java.util.Arrays.copyOf(dashes, dashes.length);
for (int i = 0; i < dashes.length; i++) {
dashes[i] = (float) (scale * dashes[i]);
}
dashphase = (float) (scale * dashphase);
}
width = (float) (scale * width);
pi = src.getPathIterator(at);
if (normalize != NormMode.OFF) {
pi = new NormalizingPathIterator(pi, normalize);
}
// by now strokerat == null && outat == null. Input paths to
// stroker (and maybe dasher) will have the full transform at
// applied to them and nothing will happen to the output paths.
} else {
if (normalize != NormMode.OFF) {
strokerat = at;
pi = src.getPathIterator(at);
pi = new NormalizingPathIterator(pi, normalize);
// by now strokerat == at && outat == null. Input paths to
// stroker (and maybe dasher) will have the full transform at
// applied to them, then they will be normalized, and then
// the inverse of *only the non translation part of at* will
// be applied to the normalized paths. This won't cause problems
// in stroker, because, suppose at = T*A, where T is just the
// translation part of at, and A is the rest. T*A has already
// been applied to Stroker/Dasher's input. Then Ainv will be
// applied. Ainv*T*A is not equal to T, but it is a translation,
// which means that none of stroker's assumptions about its
// input will be violated. After all this, A will be applied
// to stroker's output.
} else {
outat = at;
pi = src.getPathIterator(null);
// outat == at && strokerat == null. This is because if no
// normalization is done, we can just apply all our
// transformations to stroker's output.
}
}
} else {
// either at is null or it's the identity. In either case
// we don't transform the path.
pi = src.getPathIterator(null);
if (normalize != NormMode.OFF) {
pi = new NormalizingPathIterator(pi, normalize);
}
}
// by now, at least one of outat and strokerat will be null. Unless at is not
// a constant multiple of an orthogonal transformation, they will both be
// null. In other cases, outat == at if normalization is off, and if
// normalization is on, strokerat == at.
pc2d = TransformingPathConsumer2D.transformConsumer(pc2d, outat);
pc2d = TransformingPathConsumer2D.deltaTransformConsumer(pc2d, strokerat);
pc2d = new Stroker(pc2d, width, caps, join, miterlimit);
if (dashes != null) {
pc2d = new Dasher(pc2d, dashes, dashphase);
}
pc2d = TransformingPathConsumer2D.inverseDeltaTransformConsumer(pc2d, strokerat);
pathTo(pi, pc2d);
}
Aggregations