[cairo-commit] cairo-java/src/jni org_freedesktop_cairo_PngSurface.c, 1.4, 1.5

Jeffrey Morgan commit at pdx.freedesktop.org
Sat Apr 2 08:07:35 PST 2005


Committed by: kuzman

Update of /cvs/cairo/cairo-java/src/jni
In directory gabe:/tmp/cvs-serv11770/src/jni

Modified Files:
	org_freedesktop_cairo_PngSurface.c 
Log Message:
fixed bug and updated to upstream API

Index: org_freedesktop_cairo_PngSurface.c
===================================================================
RCS file: /cvs/cairo/cairo-java/src/jni/org_freedesktop_cairo_PngSurface.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- org_freedesktop_cairo_PngSurface.c	1 Apr 2005 13:58:45 -0000	1.4
+++ org_freedesktop_cairo_PngSurface.c	2 Apr 2005 16:07:33 -0000	1.5
@@ -1,7 +1,7 @@
 /*
  * Java-Gnome Bindings Library
  *
- * Copyright 1998-2004 the Java-Gnome Team, all rights reserved.
+ * Copyright 1998-2005 the Java-Gnome Team, all rights reserved.
  *
  * The Java-Gnome bindings library is free software distributed under
  * the terms of the GNU Library General Public License version 2.
@@ -20,24 +20,6 @@
 extern "C" {
 #endif
 
-typedef struct jg_pngsurface {
-	cairo_surface_t *surface;
-	FILE *file;
-} jg_pngsurface_t;
-
-/*
- * Class:     org_freedesktop_cairo_PngSurface
- * Method:    cairo_set_target_surface
- * Signature: (Lorg/gnu/glib/Handle;Ljava/lang/String;III)V
- */
-JNIEXPORT void JNICALL Java_org_freedesktop_cairo_PngSurface_cairo_1set_1target_1png
-  (JNIEnv *env, jclass cls, jobject cr, jobject sur)
-{
-	cairo_t *cr_g = (cairo_t*)getPointerFromHandle(env, cr);
-	jg_pngsurface_t *s = (jg_pngsurface_t*)getPointerFromHandle(env, sur);
-	cairo_set_target_surface(cr_g, s->surface);
-}
-
 /*
  * Class:     org_freedesktop_cairo_PngSurface
  * Method:    cairo_image_surface_create_for_png
@@ -46,31 +28,33 @@
 JNIEXPORT jobject JNICALL Java_org_freedesktop_cairo_PngSurface_cairo_1image_1surface_1create_1for_1png
   (JNIEnv *env, jclass cls, jstring filename, jintArray width, jintArray height)
 {
-	jg_pngsurface_t *s = malloc(sizeof(jg_pngsurface_t));
 	char *fn = (char*)(*env)->GetStringUTFChars(env, filename, NULL);
-	FILE *f = fopen(fn, "wb");
+	FILE *f = fopen(fn, "rb");
 	int* w = (int*)(*env)->GetIntArrayElements(env, width, NULL);
 	int* h = (int*)(*env)->GetIntArrayElements(env, height, NULL);
 	cairo_surface_t *sur = cairo_image_surface_create_for_png(f, w, h);
 	(*env)->ReleaseStringUTFChars(env, filename, fn);
 	(*env)->ReleaseIntArrayElements(env, width, w, 0);
 	(*env)->ReleaseIntArrayElements(env, height, h, 0);
-	s->surface = sur;
-	s->file = f;
-	return getHandleFromPointer(env, s);
+	fclose(f);
+	return getHandleFromPointer(env, sur);
 }
 
 /*
  * Class:     org_freedesktop_cairo_PngSurface
- * Method:    close
- * Signature: (Lorg/gnu/glib/Handle;)V
+ * Method:    cairo_surface_write_png
+ * Signature: (Lorg/gnu/javagnome/Handle;Ljava/lang/String;)I
  */
-JNIEXPORT void JNICALL Java_org_freedesktop_cairo_PngSurface_close
-  (JNIEnv *env, jclass cls, jobject sur)
+JNIEXPORT jint JNICALL Java_org_freedesktop_cairo_PngSurface_cairo_1surface_1write_1png
+  (JNIEnv *env, jclass cls, jobject surface, jstring filename)
 {
-	jg_pngsurface_t *s = (jg_pngsurface_t*)getPointerFromHandle(env, sur);
-	fclose(s->file);
-	free(s);
+	cairo_surface_t *surface_g = (cairo_surface_t*)getPointerFromHandle(env, surface);
+	char *fn = (char*)(*env)->GetStringUTFChars(env, filename, NULL);
+	FILE *f = fopen(fn, "wb");
+	int result = cairo_surface_write_png(surface_g, f);
+	fclose(f);
+	(*env)->ReleaseStringUTFChars(env, filename, fn);
+	return result;
 }
 
 #ifdef __cplusplus




More information about the cairo-commit mailing list