[cairo-commit]
cairo-java/src/jni org_freedesktop_cairo_Cairo.c, 1.3, 1.4
Jeffrey Morgan
commit at pdx.freedesktop.org
Tue Mar 8 13:32:01 PST 2005
Committed by: kuzman
Update of /cvs/cairo/cairo-java/src/jni
In directory gabe:/tmp/cvs-serv2234/src/jni
Modified Files:
org_freedesktop_cairo_Cairo.c
Log Message:
Completed implementation of current_path and current_path_flat
Index: org_freedesktop_cairo_Cairo.c
===================================================================
RCS file: /cvs/cairo/cairo-java/src/jni/org_freedesktop_cairo_Cairo.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- org_freedesktop_cairo_Cairo.c 5 Mar 2005 01:59:41 -0000 1.3
+++ org_freedesktop_cairo_Cairo.c 8 Mar 2005 21:31:59 -0000 1.4
@@ -1151,6 +1151,199 @@
cairo_rel_line_to(cr, 0.0, y);
}
+
+typedef struct {
+ JNIEnv *env;
+ jobject obj;
+ jmethodID move_to;
+ jmethodID line_to;
+ jmethodID curve_to;
+ jmethodID close_path;
+} CairoCallback;
+
+CairoCallback* callback_data(JNIEnv *env, jobject cb)
+{
+ jthrowable exc;
+ jclass Exception;
+ CairoCallback *cbdata;
+
+ cbdata = g_new(CairoCallback, 1);
+ /* add the target object to the struct */
+ cbdata->obj = (*env)->NewGlobalRef(env, cb);
+
+ cbdata->move_to =
+ (*env)->GetMethodID(env, (*env)->GetObjectClass(env, cb),
+ "moveTo", "(DD)V");
+ exc = (*env)->ExceptionOccurred(env);
+ if (exc) {
+ g_warning("cairo-java - cannot find callback method moveTo\n");
+ (*env)->ExceptionClear(env);
+ Exception = (* env)->FindClass(env, "java/lang/RuntimeException");
+ (* env)->ThrowNew(env, Exception, "" );
+ return NULL;
+ }
+
+ cbdata->line_to =
+ (*env)->GetMethodID(env, (*env)->GetObjectClass(env, cb),
+ "lineTo", "(DD)V");
+ exc = (*env)->ExceptionOccurred(env);
+ if (exc) {
+ g_warning("cairo-java - cannot find callback method lineTo\n");
+ (*env)->ExceptionClear(env);
+ Exception = (* env)->FindClass(env, "java/lang/RuntimeException");
+ (* env)->ThrowNew(env, Exception, "" );
+ return NULL;
+ }
+
+ cbdata->curve_to =
+ (*env)->GetMethodID(env, (*env)->GetObjectClass(env, cb),
+ "curveTo", "(DDDDDD)V");
+ exc = (*env)->ExceptionOccurred(env);
+ if (exc) {
+ g_warning("cairo-java - cannot find callback method curveTo\n");
+ (*env)->ExceptionClear(env);
+ Exception = (* env)->FindClass(env, "java/lang/RuntimeException");
+ (* env)->ThrowNew(env, Exception, "" );
+ return NULL;
+ }
+
+ cbdata->close_path =
+ (*env)->GetMethodID(env, (*env)->GetObjectClass(env, cb),
+ "closePath", "()V");
+ exc = (*env)->ExceptionOccurred(env);
+ if (exc) {
+ g_warning("cairo-java - cannot find callback method closePath\n");
+ (*env)->ExceptionClear(env);
+ Exception = (* env)->FindClass(env, "java/lang/RuntimeException");
+ (* env)->ThrowNew(env, Exception, "" );
+ return NULL;
+ }
+
+ /* add the env to the struct */
+ cbdata->env = env;
+}
+
+void
+move_to_callback(void *data, double x, double y)
+{
+ jvalue *jargs;
+ CairoCallback* cbdata = data;
+ jthrowable exc;
+
+ jargs = alloca(2 * sizeof(jvalue));
+ jargs[0].d = x;
+ jargs[1].d = y;
+
+ (*cbdata->env)->CallVoidMethodA(cbdata->env,
+ cbdata->obj,
+ cbdata->move_to,
+ jargs);
+ if (exc) {
+ /* Print stack trace */
+ (* cbdata->env)->ExceptionDescribe(cbdata->env);
+ /* clear the exception, so we can continue. */
+ (* cbdata->env)->ExceptionClear(cbdata->env);
+ }
+}
+
+void
+line_to_callback(void *data, double x, double y)
+{
+ jvalue *jargs;
+ CairoCallback* cbdata = data;
+ jthrowable exc;
+
+ jargs = alloca(2 * sizeof(jvalue));
+ jargs[0].d = x;
+ jargs[1].d = y;
+
+ (*cbdata->env)->CallVoidMethodA(cbdata->env,
+ cbdata->obj,
+ cbdata->line_to,
+ jargs);
+ if (exc) {
+ /* Print stack trace */
+ (* cbdata->env)->ExceptionDescribe(cbdata->env);
+ /* clear the exception, so we can continue. */
+ (* cbdata->env)->ExceptionClear(cbdata->env);
+ }
+}
+
+void
+curve_to_callback(void *data, double x1, double y1, double x2, double y2,
+ double x3, double y3)
+{
+ jvalue *jargs;
+ CairoCallback* cbdata = data;
+ jthrowable exc;
+
+ jargs = alloca(6 * sizeof(jvalue));
+ jargs[0].d = x1;
+ jargs[1].d = y1;
+ jargs[2].d = x2;
+ jargs[3].d = y2;
+ jargs[4].d = x3;
+ jargs[5].d = y3;
+
+ (*cbdata->env)->CallVoidMethodA(cbdata->env,
+ cbdata->obj,
+ cbdata->curve_to,
+ jargs);
+ if (exc) {
+ /* Print stack trace */
+ (* cbdata->env)->ExceptionDescribe(cbdata->env);
+ /* clear the exception, so we can continue. */
+ (* cbdata->env)->ExceptionClear(cbdata->env);
+ }
+}
+
+void
+close_path_callback(void *data)
+{
+ CairoCallback* cbdata = data;
+ jthrowable exc;
+
+ (*cbdata->env)->CallVoidMethod(cbdata->env,
+ cbdata->obj,
+ cbdata->move_to);
+ exc = (* cbdata->env)->ExceptionOccurred(cbdata->env);
+ if (exc) {
+ /* Print stack trace */
+ (* cbdata->env)->ExceptionDescribe(cbdata->env);
+ /* clear the exception, so we can continue. */
+ (* cbdata->env)->ExceptionClear(cbdata->env);
+ }
+}
+
+
+/*
+ * Class: org_freedesktop_cairo_Cairo
+ * Method: cairo_current_path
+ * Signature: (Lorg/gnu/glib/Handle;Ljava/lang/Object;)V
+ */
+JNIEXPORT void JNICALL Java_org_freedesktop_cairo_Cairo_cairo_1current_1path
+ (JNIEnv *env, jclass cls, jobject obj, jobject cb)
+{
+ cairo_t *cr = (cairo_t*)getPointerFromHandle(env, obj);
+ CairoCallback *cbdata = callback_data(env, cb);
+ cairo_current_path(cr, move_to_callback, line_to_callback,
+ curve_to_callback, close_path_callback, cbdata);
+}
+
+/*
+ * Class: org_freedesktop_cairo_Cairo
+ * Method: cairo_current_path_flat
+ * Signature: (Lorg/gnu/glib/Handle;Ljava/lang/Object;)V
+ */
+JNIEXPORT void JNICALL Java_org_freedesktop_cairo_Cairo_cairo_1current_1path_1flat
+ (JNIEnv *env, jclass cls, jobject obj, jobject cb)
+{
+ cairo_t *cr = (cairo_t*)getPointerFromHandle(env, obj);
+ CairoCallback *cbdata = callback_data(env, cb);
+ cairo_current_path_flat(cr, move_to_callback, line_to_callback,
+ close_path_callback, cbdata);
+}
+
#ifdef __cplusplus
}
#endif
More information about the cairo-commit
mailing list