[cairo-commit] cairo-java/src/java/org/freedesktop/cairo PngSurface.java, 1.5, 1.6 ImageSurface.java, 1.4, 1.5

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


Committed by: kuzman

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

Modified Files:
	PngSurface.java ImageSurface.java 
Log Message:
fixed bug and updated to upstream API

Index: PngSurface.java
===================================================================
RCS file: /cvs/cairo/cairo-java/src/java/org/freedesktop/cairo/PngSurface.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- PngSurface.java	1 Apr 2005 13:58:45 -0000	1.5
+++ PngSurface.java	2 Apr 2005 16:07:34 -0000	1.6
@@ -15,58 +15,52 @@
 
 /**
  */
-public class PngSurface extends Surface {
+public class PngSurface extends ImageSurface {
 	
 	private String filename;
 //	private int width;
 //	private int height;
 
+	/**
+	 * Construct a new PngSurface initializing it with the contents
+	 * of an png file.
+	 */
 	public PngSurface(String filename)  
 			throws IOException {
 		super(initialize(filename));
 	}
+
+	public void write(String filename) throws IOException {
+		checkFile(filename);
+		
+		int status = cairo_surface_write_png(getHandle(), filename);
+	}
 	
-	public void close() {
-		close(getHandle());
+	public PngSurface(Format format, int width, int height) {
+		super(format, width, height);
 	}
 	
 	private static Handle initialize(String filename)
 			throws IOException {
-		File f = new File(filename);
-		
-		if (f.isDirectory())
-			throw new IOException(filename + " is a directory");
-		
-		if (f.exists()) {
-			if (!f.canWrite())
-				throw new IOException("cannot write to file: " + filename);
-		}
-		else {
-			String parent = f.getParent();
-			if (null == parent)
-				parent = System.getProperty("user.dir");
 
-			File dir = new File(parent);
-			if (!dir.exists()) {
-				throw new IOException("destination directory doesn't exist: " + filename);
-			}
-			if (!dir.canWrite())
-				throw new IOException("Cannot write to file: " + filename);
-		}
+		checkFile(filename);
+		
 		int[] w = new int[1];
 		int[] h = new int[1];
 		return cairo_image_surface_create_for_png(filename, w, h);
 	}
 	
-	void makeTarget(Cairo cr) {
-		cairo_set_target_surface(cr.getHandle(), getHandle());
+	private static void checkFile(String filename) throws IOException {
+		File f = new File(filename);
+		
+		if (f.isDirectory())
+			throw new IOException(filename + " is a directory");
 	}
-
+	
 	/*
 	 * Native calls
 	 */
-	native static final private void cairo_set_target_surface(Handle cr, Handle sur);
 	native static final private Handle cairo_image_surface_create_for_png(String filename, 
 				int[] width, int[] height);
-	native static final private void close(Handle handle);
+	native static final private int cairo_surface_write_png(Handle surface, String filename);
 }

Index: ImageSurface.java
===================================================================
RCS file: /cvs/cairo/cairo-java/src/java/org/freedesktop/cairo/ImageSurface.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- ImageSurface.java	2 Apr 2005 13:46:40 -0000	1.4
+++ ImageSurface.java	2 Apr 2005 16:07:34 -0000	1.5
@@ -43,9 +43,9 @@
 	
 	void makeTarget(Cairo cr) {
 		if (null == data)
-			Cairo.cairo_set_target_image_no_data(getHandle(), format.getValue(), width, height);
+			Cairo.cairo_set_target_image_no_data(cr.getHandle(), format.getValue(), width, height);
 		else
-			Cairo.cairo_set_target_image(getHandle(), data, format.getValue(), width, height, stride);
+			Cairo.cairo_set_target_image(cr.getHandle(), data, format.getValue(), width, height, stride);
 	}
 	
 	/*




More information about the cairo-commit mailing list