[cairo-commit] cairo-java/src/java/org/freedesktop/cairo PsSurface.java, 1.1, 1.2

Jeffrey Morgan commit at pdx.freedesktop.org
Tue Mar 8 12:47:47 PST 2005


Committed by: kuzman

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

Modified Files:
	PsSurface.java 
Log Message:
Completed PsSurface

Index: PsSurface.java
===================================================================
RCS file: /cvs/cairo/cairo-java/src/java/org/freedesktop/cairo/PsSurface.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- PsSurface.java	23 Feb 2005 18:17:52 -0000	1.1
+++ PsSurface.java	8 Mar 2005 20:47:44 -0000	1.2
@@ -1,47 +1,79 @@
-/*
- * Java-Gnome Bindings Library
- *
- * 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.
- */
-package org.freedesktop.cairo;
-
-import org.gnu.glib.Handle;
-
-/**
- * TODO: When / How does the file get closed ?
- * TODO: Is file opened twice ?
- */
-public class PsSurface extends Surface {
-	
-	private String filename;
-	private double width;
-	private double height;
-	private double xPixels;
-	private double yPixels;
-
-	public PsSurface(String filename, double widthInches, double heightInches,
-				double xPixelsPerInch, double yPixelsPerInch) {
-		super(cairo_ps_surface_create(filename, widthInches, heightInches,
-				xPixelsPerInch, yPixelsPerInch));
-		this.filename = filename;
-		width = widthInches;
-		height = heightInches;
-		xPixels = xPixelsPerInch;
-		yPixels = yPixelsPerInch;
-	}
-	
-	void makeTarget(Cairo cr) {
-		cairo_set_target_ps(cr.getHandle(), filename, width, height, xPixels, yPixels);
-	}
-
-	/*
-	 * Native calls
-	 */
-	native static final private void cairo_set_target_ps(Handle cr, String filename,
-			double width_inches, double height_inches, double x_pixels_per_inch, double y_pixels_per_inch);
-	native static final private Handle cairo_ps_surface_create(String filename, 
-			double width_inches, double height_inches, double x_pixels_per_inch, double y_pixels_per_inch);
-}
+/*
+ * Java-Gnome Bindings Library
+ *
+ * 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.
+ */
+package org.freedesktop.cairo;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.gnu.glib.Handle;
+
+/**
+ */
+public class PsSurface extends Surface {
+	
+	private String filename;
+	private double width;
+	private double height;
+	private double xPixels;
+	private double yPixels;
+
+	public PsSurface(String filename, double widthInches, double heightInches,
+				double xPixelsPerInch, double yPixelsPerInch) throws IOException {
+		super(initialize(filename, widthInches, heightInches, xPixelsPerInch, yPixelsPerInch));
+		this.filename = filename;
+		width = widthInches;
+		height = heightInches;
+		xPixels = xPixelsPerInch;
+		yPixels = yPixelsPerInch;
+	}
+	
+    public void close() {
+        close(getHandle());
+    }
+
+    private static Handle initialize(String filename, double widthInches, double heightInches,
+            double xPixelsPerInch, double yPixelsPerInch) 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_ps_surface_create(filename, widthInches, heightInches, xPixelsPerInch, yPixelsPerInch);
+    }
+    
+    void makeTarget(Cairo cr) {
+		cairo_set_target_ps(cr.getHandle(), getHandle(), width, height, xPixels, yPixels);
+	}
+
+	/*
+	 * Native calls
+	 */
+	native static final private void cairo_set_target_ps(Handle cr, Handle sur,
+			double width_inches, double height_inches, double x_pixels_per_inch, double y_pixels_per_inch);
+	native static final private Handle cairo_ps_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(Handle handle);
+}




More information about the cairo-commit mailing list