[cairo-commit] cairo-java/src/jni org_freedesktop_cairo_PngSurface.c, 1.1, 1.2 org_freedesktop_cairo_PdfSurface.c, 1.2, 1.3

Jeffrey Morgan commit at pdx.freedesktop.org
Fri Mar 4 13:03:40 PST 2005


Committed by: kuzman

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

Modified Files:
	org_freedesktop_cairo_PngSurface.c 
	org_freedesktop_cairo_PdfSurface.c 
Log Message:
More updates and PNG snippet code

Index: org_freedesktop_cairo_PngSurface.c
===================================================================
RCS file: /cvs/cairo/cairo-java/src/jni/org_freedesktop_cairo_PngSurface.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- org_freedesktop_cairo_PngSurface.c	23 Feb 2005 18:17:52 -0000	1.1
+++ org_freedesktop_cairo_PngSurface.c	4 Mar 2005 21:03:38 -0000	1.2
@@ -8,8 +8,10 @@
  */
 
 #include <stdio.h>
+#include <stdlib.h>
 #include <jni.h>
 #include <cairo.h>
+#include <cairo-png.h>
 #include <jg_jnu.h>
 
 #ifndef _Included_org_freedesktop_cairo_PngSurface
@@ -18,20 +20,23 @@
 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_png
  * 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, jstring filename, jint format, 
+  (JNIEnv *env, jclass cls, jobject cr, jobject sur, jint format, 
   		jint width, jint height)
 {
 	cairo_t *cr_g = (cairo_t*)getPointerFromHandle(env, cr);
-	char *fn = (char*)(*env)->GetStringUTFChars(env, filename, NULL);
-	FILE *f = fopen(fn, "w");
-	cairo_set_target_png(cr_g, f, (cairo_format_t)format, width, height);
-	(*env)->ReleaseStringUTFChars(env, filename, fn);
+	jg_pngsurface_t *s = (jg_pngsurface_t*)getPointerFromHandle(env, sur);
+	cairo_set_target_png(cr_g, s->file, (cairo_format_t)format, width, height);
 }
 
 /*
@@ -42,12 +47,28 @@
 JNIEXPORT jobject JNICALL Java_org_freedesktop_cairo_PngSurface_cairo_1png_1surface_1create
   (JNIEnv *env, jclass cls, jstring filename, jint format, jint width, jint height)
 {
+	jg_pngsurface_t *s = malloc(sizeof(jg_pngsurface_t));
 	char *fn = (char*)(*env)->GetStringUTFChars(env, filename, NULL);
 	FILE *f = fopen(fn, "w");
 	cairo_surface_t *sur = cairo_png_surface_create(f, (cairo_format_t)format, 
 			width, height);
 	(*env)->ReleaseStringUTFChars(env, filename, fn);
-	return getHandleFromPointer(env, sur);
+	s->surface = sur;
+	s->file = f;
+	return getHandleFromPointer(env, s);
+}
+
+/*
+ * Class:     org_freedesktop_cairo_PngSurface
+ * Method:    close
+ * Signature: (Lorg/gnu/glib/Handle;)V
+ */
+JNIEXPORT void JNICALL Java_org_freedesktop_cairo_PngSurface_close
+  (JNIEnv *env, jclass cls, jobject sur)
+{
+	jg_pngsurface_t *s = (jg_pngsurface_t*)getPointerFromHandle(env, sur);
+	fclose(s->file);
+	free(s);
 }
 
 #ifdef __cplusplus

Index: org_freedesktop_cairo_PdfSurface.c
===================================================================
RCS file: /cvs/cairo/cairo-java/src/jni/org_freedesktop_cairo_PdfSurface.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- org_freedesktop_cairo_PdfSurface.c	4 Mar 2005 20:34:47 -0000	1.2
+++ org_freedesktop_cairo_PdfSurface.c	4 Mar 2005 21:03:38 -0000	1.3
@@ -63,11 +63,12 @@
  * Method:    close_file
  * Signature: (Lorg/gnu/glib/Handle;)V
  */
-JNIEXPORT void JNICALL Java_org_freedesktop_cairo_PdfSurface_close_1file
+JNIEXPORT void JNICALL Java_org_freedesktop_cairo_PdfSurface_close
   (JNIEnv *env, jclass cls, jobject sur)
 {
 	jg_pdfsurface_t *s = (jg_pdfsurface_t*)getPointerFromHandle(env, sur);
 	fclose(s->file);
+	free(s);
 }
 
 




More information about the cairo-commit mailing list