delete[] approximation;
return result;
}
-
- static jlong trim(JNIEnv* env, jobject clazz, jlong inPathPtr, jlong outPathPtr,
- jlong pathMeasurePtr, jfloat trimStart, jfloat trimEnd, jfloat trimOffset) {
- SkPath* inPath = reinterpret_cast<SkPath*>(inPathPtr);
- SkPath* outPath = reinterpret_cast<SkPath*>(outPathPtr);
- SkPathMeasure* pathMeasure = reinterpret_cast<SkPathMeasure*>(pathMeasurePtr);
- if (trimStart == 0 && trimEnd == 1) {
- if (outPath != NULL) {
- *outPath = *inPath;
- }
- return reinterpret_cast<jlong>(pathMeasure);
- }
-
- bool modifyPath = (outPath == NULL);
- if (modifyPath) {
- outPath = new SkPath();
- } else {
- outPath->reset();
- }
- if (pathMeasure == NULL) {
- pathMeasure = new SkPathMeasure(*inPath, false);
- }
- float length = pathMeasure->getLength();
- float start = (trimStart + trimOffset) * length;
- float end = (trimEnd + trimOffset) * length;
-
- if (end > length && start <= length) {
- pathMeasure->getSegment(start, length, outPath, true);
- pathMeasure->getSegment(0, end - length, outPath, true);
- } else {
- if (start > length) {
- start -= length;
- end -= length;
- }
- pathMeasure->getSegment(start, end, outPath, true);
- }
- if (modifyPath) {
- delete pathMeasure;
- pathMeasure = NULL;
- *inPath = *outPath;
- delete outPath;
- }
- return reinterpret_cast<jlong>(pathMeasure);
- }
-
- static void destroyMeasure(JNIEnv* env, jobject clazz, jlong measure) {
- delete reinterpret_cast<SkPathMeasure*>(measure);
- }
};
static JNINativeMethod methods[] = {
{"native_transform","(JJ)V", (void*) SkPathGlue::transform__Matrix},
{"native_op","(JJIJ)Z", (void*) SkPathGlue::op},
{"native_approximate", "(JF)[F", (void*) SkPathGlue::approximate},
- {"native_destroyMeasure","(J)V", (void*) SkPathGlue::destroyMeasure},
- {"native_trim","(JJJFFF)J", (void*) SkPathGlue::trim},
};
int register_android_graphics_Path(JNIEnv* env) {
* @hide
*/
public final long mNativePath;
- private long mNativePathMeasure;
/**
* @hide
final FillType fillType = getFillType();
native_reset(mNativePath);
setFillType(fillType);
- clearMeasure();
- }
-
- private void clearMeasure() {
- if (mNativePathMeasure != 0) {
- native_destroyMeasure(mNativePathMeasure);
- mNativePathMeasure = 0;
- }
}
/**
mLastDirection = null;
if (rects != null) rects.setEmpty();
native_rewind(mNativePath);
- clearMeasure();
}
/** Replace the contents of this with the contents of src.
if (this != src) {
isSimplePath = src.isSimplePath;
native_set(mNativePath, src.mNativePath);
- clearMeasure();
}
}
*/
public void setFillType(FillType ft) {
native_setFillType(mNativePath, ft.nativeInt);
- clearMeasure();
}
/**
int ft = native_getFillType(mNativePath);
ft ^= 2;
native_setFillType(mNativePath, ft);
- clearMeasure();
}
/**
*/
public void moveTo(float x, float y) {
native_moveTo(mNativePath, x, y);
- clearMeasure();
}
/**
*/
public void rMoveTo(float dx, float dy) {
native_rMoveTo(mNativePath, dx, dy);
- clearMeasure();
}
/**
public void lineTo(float x, float y) {
isSimplePath = false;
native_lineTo(mNativePath, x, y);
- clearMeasure();
}
/**
public void rLineTo(float dx, float dy) {
isSimplePath = false;
native_rLineTo(mNativePath, dx, dy);
- clearMeasure();
}
/**
public void quadTo(float x1, float y1, float x2, float y2) {
isSimplePath = false;
native_quadTo(mNativePath, x1, y1, x2, y2);
- clearMeasure();
}
/**
public void rQuadTo(float dx1, float dy1, float dx2, float dy2) {
isSimplePath = false;
native_rQuadTo(mNativePath, dx1, dy1, dx2, dy2);
- clearMeasure();
}
/**
float x3, float y3) {
isSimplePath = false;
native_cubicTo(mNativePath, x1, y1, x2, y2, x3, y3);
- clearMeasure();
}
/**
float x3, float y3) {
isSimplePath = false;
native_rCubicTo(mNativePath, x1, y1, x2, y2, x3, y3);
- clearMeasure();
}
/**
boolean forceMoveTo) {
isSimplePath = false;
native_arcTo(mNativePath, oval, startAngle, sweepAngle, forceMoveTo);
- clearMeasure();
}
/**
public void arcTo(RectF oval, float startAngle, float sweepAngle) {
isSimplePath = false;
native_arcTo(mNativePath, oval, startAngle, sweepAngle, false);
- clearMeasure();
}
/**
public void close() {
isSimplePath = false;
native_close(mNativePath);
- clearMeasure();
}
/**
}
detectSimplePath(rect.left, rect.top, rect.right, rect.bottom, dir);
native_addRect(mNativePath, rect, dir.nativeInt);
- clearMeasure();
}
/**
public void addRect(float left, float top, float right, float bottom, Direction dir) {
detectSimplePath(left, top, right, bottom, dir);
native_addRect(mNativePath, left, top, right, bottom, dir.nativeInt);
- clearMeasure();
}
/**
}
isSimplePath = false;
native_addOval(mNativePath, oval, dir.nativeInt);
- clearMeasure();
}
/**
public void addCircle(float x, float y, float radius, Direction dir) {
isSimplePath = false;
native_addCircle(mNativePath, x, y, radius, dir.nativeInt);
- clearMeasure();
}
/**
}
isSimplePath = false;
native_addArc(mNativePath, oval, startAngle, sweepAngle);
- clearMeasure();
}
/**
}
isSimplePath = false;
native_addRoundRect(mNativePath, rect, rx, ry, dir.nativeInt);
- clearMeasure();
}
/**
}
isSimplePath = false;
native_addRoundRect(mNativePath, rect, radii, dir.nativeInt);
- clearMeasure();
}
/**
public void addPath(Path src, float dx, float dy) {
isSimplePath = false;
native_addPath(mNativePath, src.mNativePath, dx, dy);
- clearMeasure();
}
/**
public void addPath(Path src) {
isSimplePath = false;
native_addPath(mNativePath, src.mNativePath);
- clearMeasure();
}
/**
public void addPath(Path src, Matrix matrix) {
if (!src.isSimplePath) isSimplePath = false;
native_addPath(mNativePath, src.mNativePath, matrix.native_instance);
- clearMeasure();
}
/**
dst.isSimplePath = false;
}
native_offset(mNativePath, dx, dy, dstNative);
- if (dst != null) {
- dst.clearMeasure();
- } else {
- clearMeasure();
- }
}
/**
public void offset(float dx, float dy) {
isSimplePath = false;
native_offset(mNativePath, dx, dy);
- clearMeasure();
}
/**
public void setLastPoint(float dx, float dy) {
isSimplePath = false;
native_setLastPoint(mNativePath, dx, dy);
- clearMeasure();
}
/**
dstNative = dst.mNativePath;
}
native_transform(mNativePath, matrix.native_instance, dstNative);
- if (dst != null) {
- dst.clearMeasure();
- } else {
- clearMeasure();
- }
}
/**
public void transform(Matrix matrix) {
isSimplePath = false;
native_transform(mNativePath, matrix.native_instance);
- clearMeasure();
}
protected void finalize() throws Throwable {
try {
- if (mNativePathMeasure != 0) {
- native_destroyMeasure(mNativePathMeasure);
- }
finalizer(mNativePath);
} finally {
super.finalize();
return native_approximate(mNativePath, acceptableError);
}
- /**
- * Modifies the <code>Path</code> by extracting a portion of it.
- * The portion of the <code>Path</code> used is between <code>trimStart</code> and
- * <code>trimEnd</code> with the value offset by <code>trimOffset</code>. When
- * <code>trimOffset</code> added to <code>trimEnd</code> is greater than 1, the
- * trimmed portion "wraps" to the start of the <code>Path</code>.
- * <p>For example, if <code>Path</code> is a circle and <code>trimStart</code> is 0
- * and <code>trimEnd</code> is 0.5, the resulting <code>Path</code> is the arc of
- * a semicircle. If <code>trimOffset</code> is set to 0.75, the arc will start at
- * 3/4 of the circle and continue to the end of the circle, then start again at the
- * beginning of the circle and end at 1/4 of the way around. It will appear as if
- * the semicircle arc wrapped around the <code>Path</code> start and end.</p>
- * @param trimStart A number between 0 and <code>trimEnd</code> indicating the fraction of the
- * <code>Path</code> to start. A value of 0 trims nothing from the start.
- * @param trimEnd A number between <code>trimStart</code> and 1 indicating the fraction of the
- * <code>Path</code> to end. A value of 1 trims nothing from the end.
- * @param trimOffset A fraction between 0 and 1 indicating the offset of the trimmed
- * portion of the <code>Path</code>.
- * @see #trim(float, float, float, Path)
- */
- public void trim(float trimStart, float trimEnd, float trimOffset) {
- trim(trimStart, trimEnd, trimOffset, null);
- }
-
- /**
- * Extracts a portion of the <code>Path</code> and writes it to <code>dst</code>.
- * The portion of the <code>Path</code> used is between <code>trimStart</code> and
- * <code>trimEnd</code> with the value offset by <code>trimOffset</code>. When
- * <code>trimOffset</code> added to <code>trimEnd</code> is greater than 1, the
- * trimmed portion "wraps" to the start of the <code>Path</code>.
- * <p>For example, if <code>Path</code> is a circle and <code>trimStart</code> is 0
- * and <code>trimEnd</code> is 0.5, the resulting <code>Path</code> is the arc of
- * a semicircle. If <code>trimOffset</code> is set to 0.75, the arc will start at
- * 3/4 of the circle and continue to the end of the circle, then start again at the
- * beginning of the circle and end at 1/4 of the way around. It will appear as if
- * the semicircle arc wrapped around the <code>Path</code> start and end.</p>
- * @param trimStart A number between 0 and <code>trimEnd</code> indicating the fraction of the
- * <code>Path</code> to start. A value of 0 trims nothing from the start.
- * @param trimEnd A number between <code>trimStart</code> and 1 indicating the fraction of the
- * <code>Path</code> to end. A value of 1 trims nothing from the end.
- * @param trimOffset A fraction between 0 and 1 indicating the offset of the trimmed
- * portion of the <code>Path</code>.
- * @param dst The trimmed <code>Path</code> is written here. If <code>dst</code> is null,
- * then the original <code>Path</code> is modified.
- * @see #trim(float, float, float)
- */
- public void trim(float trimStart, float trimEnd, float trimOffset, Path dst) {
- if (trimStart > 1 || trimEnd > 1 || trimOffset > 1
- || trimStart < 0 || trimEnd < 0 || trimOffset < 0) {
- throw new IllegalArgumentException("trim must be between 0 and 1");
- }
- if (trimStart > trimEnd) {
- throw new IllegalArgumentException("trim end cannot be less than start");
- }
- long dstNative = 0;
- if (dst != null) {
- dstNative = dst.mNativePath;
- dst.isSimplePath = false;
- dst.clearMeasure();
- }
- mNativePathMeasure = native_trim(mNativePath, dstNative, mNativePathMeasure,
- trimStart, trimEnd, trimOffset);
- }
-
private static native long init1();
private static native long init2(long nPath);
private static native void native_reset(long nPath);
private static native boolean native_op(long path1, long path2, int op, long result);
private static native void finalizer(long nPath);
private static native float[] native_approximate(long nPath, float error);
- private static native long native_trim(long nPath, long nTargetPath, long nPathMeasure,
- float trimStart, float trimEnd, float trimOffset);
- private static native void native_destroyMeasure(long nPathMeasure);
}