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

Jeffrey Morgan commit at pdx.freedesktop.org
Fri Mar 4 12:34:49 PST 2005


Committed by: kuzman

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

Modified Files:
	PdfSurface.java Cairo.java 
Log Message:
More updates and start of snippets tests.

Index: PdfSurface.java
===================================================================
RCS file: /cvs/cairo/cairo-java/src/java/org/freedesktop/cairo/PdfSurface.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- PdfSurface.java	23 Feb 2005 18:17:52 -0000	1.1
+++ PdfSurface.java	4 Mar 2005 20:34:47 -0000	1.2
@@ -8,6 +8,10 @@
  */
 package org.freedesktop.cairo;
 
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+
 import org.gnu.glib.Handle;
 
 /**
@@ -23,9 +27,8 @@
 	private double yPixels;
 	
 	public PdfSurface(String filename, double widthInches, double heightInches,
-				double xPixelsPerInch, double yPixelsPerInch) {
-		super(cairo_pdf_surface_create(filename, widthInches, heightInches,
-					xPixelsPerInch, yPixelsPerInch));
+				double xPixelsPerInch, double yPixelsPerInch) throws IOException {
+		super(initialize(filename, widthInches, heightInches, xPixelsPerInch, yPixelsPerInch));
 		this.filename = filename;
 		width = widthInches;
 		height = heightInches;
@@ -33,17 +36,48 @@
 		yPixels = yPixelsPerInch;
 	}
 	
+	public void closeFile() {
+		close_file(getHandle());
+	}
+	
+	private static Handle initialize(String filename, double widthInches, double heightInches,
+				double xPixels, double yPixels) 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_pdf_surface_create(filename, widthInches, heightInches, xPixels, yPixels);
+	}
+	
 	void makeTarget(Cairo cr){
-		cairo_set_target_pdf(cr.getHandle(), filename, width, height, xPixels, yPixels);
+		cairo_set_target_pdf(cr.getHandle(), getHandle(), width, height, xPixels, yPixels);
 	}
 
 	/*
 	 * Native calls
 	 */
-	native static final private void cairo_set_target_pdf(Handle cr, String filename, 
+	native static final private void cairo_set_target_pdf(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_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);
 }

Index: Cairo.java
===================================================================
RCS file: /cvs/cairo/cairo-java/src/java/org/freedesktop/cairo/Cairo.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- Cairo.java	23 Feb 2005 18:17:52 -0000	1.1
+++ Cairo.java	4 Mar 2005 20:34:47 -0000	1.2
@@ -11,7 +11,7 @@
 import org.gnu.glib.GObject;
 import org.gnu.glib.Handle;
 
-class Cairo extends CairoObject {
+public class Cairo extends CairoObject {
 	
 	/**
 	 * Create a new cairo target (cairo_t) 




More information about the cairo-commit mailing list