[cairo-commit] cairo-java/src/java/org/freedesktop/cairo PdfSurface.java, 1.2, 1.3 PngSurface.java, 1.1, 1.2

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/java/org/freedesktop/cairo
In directory gabe:/tmp/cvs-serv16001/src/java/org/freedesktop/cairo

Modified Files:
	PdfSurface.java PngSurface.java 
Log Message:
More updates and PNG snippet code

Index: PdfSurface.java
===================================================================
RCS file: /cvs/cairo/cairo-java/src/java/org/freedesktop/cairo/PdfSurface.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- PdfSurface.java	4 Mar 2005 20:34:47 -0000	1.2
+++ PdfSurface.java	4 Mar 2005 21:03:38 -0000	1.3
@@ -9,7 +9,6 @@
 package org.freedesktop.cairo;
 
 import java.io.File;
-import java.io.FileNotFoundException;
 import java.io.IOException;
 
 import org.gnu.glib.Handle;
@@ -36,8 +35,8 @@
 		yPixels = yPixelsPerInch;
 	}
 	
-	public void closeFile() {
-		close_file(getHandle());
+	public void close() {
+		close(getHandle());
 	}
 	
 	private static Handle initialize(String filename, double widthInches, double heightInches,
@@ -66,7 +65,7 @@
 		return cairo_pdf_surface_create(filename, widthInches, heightInches, xPixels, yPixels);
 	}
 	
-	void makeTarget(Cairo cr){
+	void makeTarget(Cairo cr) {
 		cairo_set_target_pdf(cr.getHandle(), getHandle(), width, height, xPixels, yPixels);
 	}
 
@@ -77,7 +76,7 @@
 				double width_inches, double height_inches,
 				double x_pixels_per_inch, double y_pixels_per_inch);
 	native static final private Handle cairo_pdf_surface_create(String filename,
-			double width_inches, double height_inches,
-			double x_pixels_per_inch, double y_pixels_per_inch);
-	native static final private void close_file(Handle handle);
+				double width_inches, double height_inches,
+				double x_pixels_per_inch, double y_pixels_per_inch);
+	native static final private void close(Handle handle);
 }

Index: PngSurface.java
===================================================================
RCS file: /cvs/cairo/cairo-java/src/java/org/freedesktop/cairo/PngSurface.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- PngSurface.java	23 Feb 2005 18:17:52 -0000	1.1
+++ PngSurface.java	4 Mar 2005 21:03:38 -0000	1.2
@@ -8,6 +8,9 @@
  */
 package org.freedesktop.cairo;
 
+import java.io.File;
+import java.io.IOException;
+
 import org.gnu.glib.Handle;
 
 /**
@@ -21,21 +24,56 @@
 	private int width;
 	private int height;
 
-	public PngSurface(String filename, Format format, int width, int height) {
-		super(cairo_png_surface_create(filename, format.getValue(), width, height));
+	public PngSurface(String filename, Format format, int width, int height)  
+			throws IOException {
+		super(initialize(filename, format, width, height));
 		this.filename = filename;
 		this.format = format;
 		this.width = width;
 		this.height = height;
 	}
 	
+	public void close() {
+		close(getHandle());
+	}
+	
+	private static Handle initialize(String filename, Format format, int width, int height)
+			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);
+		}
+		return cairo_png_surface_create(filename, format.getValue(), width, height);
+		
+	}
+	
 	void makeTarget(Cairo cr) {
-		cairo_set_target_png(cr.getHandle(), filename, format.getValue(), width, height);
+		cairo_set_target_png(cr.getHandle(), getHandle(), format.getValue(), width, height);
 	}
 
 	/*
 	 * Native calls
 	 */
-	native static final private void cairo_set_target_png(Handle cr, String filename, int format, int width, int height);
-	native static final private Handle cairo_png_surface_create(String filename, int format, int width, int height);
+	native static final private void cairo_set_target_png(Handle cr, Handle sur,
+				int format, int width, int height);
+	native static final private Handle cairo_png_surface_create(String filename, 
+				int format, int width, int height);
+	native static final private void close(Handle handle);
 }




More information about the cairo-commit mailing list