[cairo-commit] cairo/src cairo-png.c, 1.19, 1.20 cairo-surface.c, 1.84, 1.85 cairo.c, 1.116, 1.117 cairo.h, 1.141, 1.142 cairoint.h, 1.173, 1.174

Carl Worth commit at pdx.freedesktop.org
Thu Jul 28 10:41:11 PDT 2005


Committed by: cworth

Update of /cvs/cairo/cairo/src
In directory gabe:/tmp/cvs-serv5350/src

Modified Files:
	cairo-png.c cairo-surface.c cairo.c cairo.h cairoint.h 
Log Message:

        * src/cairo-png.c: (read_png),
        (cairo_image_surface_create_from_png): Fix so that one of three
        different error status values will be returned:

                CAIRO_STATUS_NO_MEMORY
                CAIRO_STATUS_FILE_NOT_FOUND
                CAIRO_STATUS_READ_ERROR

        * src/cairo.h:
        * src/cairo.c: (cairo_status_to_string): Add new
        CAIRO_STATUS_FILE_NOT_FOUND.

        * src/cairoint.h:
        * src/cairo-surface.c: Add new _cairo_surface_nil_read_error and
        _cairo_surface_nil_file_not_found.

        * test/create-from-png.c: (draw): Test the new FILE_NOT_FOUND
        error.


Index: cairo-png.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-png.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- cairo-png.c	28 Jul 2005 16:46:38 -0000	1.19
+++ cairo-png.c	28 Jul 2005 17:41:08 -0000	1.20
@@ -340,8 +340,10 @@
 
     png_set_read_fn (png, closure, read_func);
 
-    if (setjmp (png_jmpbuf (png)))
+    if (setjmp (png_jmpbuf (png))) {
+	surface = &_cairo_surface_nil_read_error;
 	goto BAIL;
+    }
 
     png_read_info (png, info);
 
@@ -413,8 +415,8 @@
     if (png)
 	png_destroy_read_struct (&png, &info, NULL);
 
-    if (surface == &_cairo_surface_nil)
-	_cairo_error (CAIRO_STATUS_NO_MEMORY);
+    if (surface->status)
+	_cairo_error (surface->status);
 
     return surface;
 }
@@ -437,16 +439,13 @@
  * given PNG file.
  * 
  * Return value: a new #cairo_surface_t initialized with the contents
- * of the PNG file, or a "nil" surface if any error occured. A nil
+ * of the PNG file, or a "nil" surface if any error occurred. A nil
  * surface can be checked for with cairo_surface_status(surface) which
  * may return one of the following values: 
  *
  *	CAIRO_STATUS_NO_MEMORY
- *
- * XXX: We may want to add a few more error values here, (file not
- * found? permission denied? file not png?). One way to do this would
- * be to create several variations on cairo_surface_nil to house the
- * status values we care about.
+ *	CAIRO_STATUS_FILE_NOT_FOUND
+ *	CAIRO_STATUS_READ_ERROR
  **/
 cairo_surface_t *
 cairo_image_surface_create_from_png (const char *filename)
@@ -455,8 +454,19 @@
     cairo_surface_t *surface;
 
     fp = fopen (filename, "rb");
-    if (fp == NULL)
-	return (cairo_surface_t*) &_cairo_surface_nil;
+    if (fp == NULL) {
+	switch (errno) {
+	case ENOMEM:
+	    _cairo_error (CAIRO_STATUS_NO_MEMORY);
+	    return (cairo_surface_t*) &_cairo_surface_nil;
+	case ENOENT:
+	    _cairo_error (CAIRO_STATUS_FILE_NOT_FOUND);
+	    return (cairo_surface_t*) &_cairo_surface_nil_file_not_found;
+	default:
+	    _cairo_error (CAIRO_STATUS_READ_ERROR);
+	    return (cairo_surface_t*) &_cairo_surface_nil_read_error;
+	}
+    }
   
     surface = read_png (stdio_read_func, fp);
 

Index: cairo-surface.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-surface.c,v
retrieving revision 1.84
retrieving revision 1.85
diff -u -d -r1.84 -r1.85
--- cairo-surface.c	28 Jul 2005 16:46:38 -0000	1.84
+++ cairo-surface.c	28 Jul 2005 17:41:08 -0000	1.85
@@ -56,6 +56,38 @@
     0					/* current_clip_serial */
 };
 
+const cairo_surface_t _cairo_surface_nil_file_not_found = {
+    &cairo_image_surface_backend,	/* backend */
+    -1,					/* ref_count */
+    CAIRO_STATUS_FILE_NOT_FOUND,	/* status */
+    FALSE,				/* finished */
+    { 0,	/* size */
+      0,	/* num_elements */
+      0,	/* element_size */
+      NULL,	/* elements */
+    },					/* user_data */
+    0.0,				/* device_x_offset */
+    0.0,				/* device_y_offset */
+    0,					/* next_clip_serial */
+    0					/* current_clip_serial */
+};
+
+const cairo_surface_t _cairo_surface_nil_read_error = {
+    &cairo_image_surface_backend,	/* backend */
+    -1,					/* ref_count */
+    CAIRO_STATUS_READ_ERROR,		/* status */
+    FALSE,				/* finished */
+    { 0,	/* size */
+      0,	/* num_elements */
+      0,	/* element_size */
+      NULL,	/* elements */
+    },					/* user_data */
+    0.0,				/* device_x_offset */
+    0.0,				/* device_y_offset */
+    0,					/* next_clip_serial */
+    0					/* current_clip_serial */
+};
+
 /**
  * _cairo_surface_set_error:
  * @surface: a surface

Index: cairo.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo.c,v
retrieving revision 1.116
retrieving revision 1.117
diff -u -d -r1.116 -r1.117
--- cairo.c	28 Jul 2005 16:46:39 -0000	1.116
+++ cairo.c	28 Jul 2005 17:41:08 -0000	1.117
@@ -62,7 +62,7 @@
  * a bit of a pain, but it should be easy to always catch as long as
  * one adds a new test case to test a trigger of the new status value.
  */
-#define CAIRO_STATUS_LAST_STATUS CAIRO_STATUS_INVALID_VISUAL
+#define CAIRO_STATUS_LAST_STATUS CAIRO_STATUS_FILE_NOT_FOUND
 
 /**
  * _cairo_error:
@@ -2391,6 +2391,8 @@
 	return "invalid value for an input cairo_format_t";
     case CAIRO_STATUS_INVALID_VISUAL:
 	return "invalid value for an input Visual*";
+    case CAIRO_STATUS_FILE_NOT_FOUND:
+	return "file not found";
     }
 
     return "<unknown error status>";

Index: cairo.h
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo.h,v
retrieving revision 1.141
retrieving revision 1.142
diff -u -d -r1.141 -r1.142
--- cairo.h	28 Jul 2005 16:29:47 -0000	1.141
+++ cairo.h	28 Jul 2005 17:41:08 -0000	1.142
@@ -157,6 +157,7 @@
  * @CAIRO_STATUS_INVALID_CONTENT: invalid value for an input cairo_content_t
  * @CAIRO_STATUS_INVALID_FORMAT: invalid value for an input cairo_format_t
  * @CAIRO_STATUS_INVALID_VISUAL: invalid value for an input Visual*
+ * @CAIRO_STATUS_FILE_NOT_FOUND: file not found
  *
  * #cairo_status_t is used to indicate errors that can occur when
  * using Cairo. In some cases it is returned directly by functions.
@@ -181,7 +182,8 @@
     CAIRO_STATUS_PATTERN_TYPE_MISMATCH,
     CAIRO_STATUS_INVALID_CONTENT,
     CAIRO_STATUS_INVALID_FORMAT,
-    CAIRO_STATUS_INVALID_VISUAL
+    CAIRO_STATUS_INVALID_VISUAL,
+    CAIRO_STATUS_FILE_NOT_FOUND
 } cairo_status_t;
 
 /**

Index: cairoint.h
===================================================================
RCS file: /cvs/cairo/cairo/src/cairoint.h,v
retrieving revision 1.173
retrieving revision 1.174
diff -u -d -r1.173 -r1.174
--- cairoint.h	28 Jul 2005 16:46:39 -0000	1.173
+++ cairoint.h	28 Jul 2005 17:41:08 -0000	1.174
@@ -1484,6 +1484,8 @@
 /* cairo-surface.c */
 
 extern const cairo_surface_t _cairo_surface_nil;
+extern const cairo_surface_t _cairo_surface_nil_read_error;
+extern const cairo_surface_t _cairo_surface_nil_file_not_found;
 
 cairo_private cairo_surface_t *
 _cairo_surface_create_similar_scratch (cairo_surface_t *other,




More information about the cairo-commit mailing list