svn: /pecl/cairo/trunk/ cairo.c cairo_ft_font.c php_cairo.h php_cairo_api.h tests/CairoFontFace/CairoFtFontFace/cairo_ft_font_face_create.phpt
| From: | Michael Maclean | Date: | Wed, 28 Dec 2011 17:30:24 +0000 |
| Subject: | svn: /pecl/cairo/trunk/ cairo.c cairo_ft_font.c php_cairo.h php_cairo_api.h tests/CairoFontFace/CairoFtFontFace/cairo_ft_font_face_create.phpt | ||
| Groups: | php.pecl.cvs | ||
| Request: | Send a blank email to pecl-cvs+get-17419@lists.php.net to get a copy of this message | ||
mgdm Wed, 28 Dec 2011 17:30:24 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=321481
Log:
Make FreeType error handling give sensible error descriptions
Changed paths:
U pecl/cairo/trunk/cairo.c
U pecl/cairo/trunk/cairo_ft_font.c
U pecl/cairo/trunk/php_cairo.h
U pecl/cairo/trunk/php_cairo_api.h
U pecl/cairo/trunk/tests/CairoFontFace/CairoFtFontFace/cairo_ft_font_face_create.phpt
Modified: pecl/cairo/trunk/cairo.c
===================================================================
--- pecl/cairo/trunk/cairo.c 2011-12-28 17:16:51 UTC (rev 321480)
+++ pecl/cairo/trunk/cairo.c 2011-12-28 17:30:24 UTC (rev 321481)
@@ -39,6 +39,9 @@
#if defined(CAIRO_HAS_FT_FONT) && defined(HAVE_FREETYPE)
ZEND_DECLARE_MODULE_GLOBALS(cairo)
+const php_cairo_ft_error php_cairo_ft_errors[] =
+#include FT_ERRORS_H
+
PHP_GINIT_FUNCTION(cairo)
{
cairo_globals->ft_lib = NULL;
@@ -51,6 +54,7 @@
}
}
+
#endif
/* Cairo Functions */
@@ -604,6 +608,24 @@
ZEND_ARG_INFO(0, extents)
ZEND_END_ARG_INFO()
+
+#if defined(CAIRO_HAS_FT_FONT) && defined(HAVE_FREETYPE)
+
+const char* php_cairo_get_ft_error(int error TSRMLS_DC) {
+ int i;
+ php_cairo_ft_error *current_error = php_cairo_ft_errors;
+
+ while (current_error->err_msg != NULL) {
+ if (current_error->err_code == error) {
+ return current_error->err_msg;
+ }
+ current_error++;
+ }
+ return NULL;
+}
+
+#endif
+
/* {{{ proto int cairo_version(void)
Returns an integer version number of the cairo library being used */
PHP_FUNCTION(cairo_version)
Modified: pecl/cairo/trunk/cairo_ft_font.c
===================================================================
--- pecl/cairo/trunk/cairo_ft_font.c 2011-12-28 17:16:51 UTC (rev 321480)
+++ pecl/cairo/trunk/cairo_ft_font.c 2011-12-28 17:30:24 UTC (rev 321481)
@@ -187,7 +187,7 @@
}
if(php_stream_stat(stream, &ssbuf) != 0) {
- zend_error(E_WARNING, "Cannot determine size of stream");
+ zend_error(E_WARNING, "cairo_ft_font_face_create(): Cannot determine size of stream");
if(owned_stream) {
php_stream_close(stream);
}
@@ -199,14 +199,10 @@
error = php_cairo_create_ft_font_face(font_face_object, stream, owned_stream, load_flags, 0
TSRMLS_CC);
if (error) {
- if (error == FT_Err_Unknown_File_Format) {
- zend_error(E_WARNING, "Unknown file format");
- } else {
- zend_error(E_WARNING, "Error %d occurred opening the file", error);
- }
-
+ char *err_string = php_cairo_get_ft_error(error TSRMLS_CC);
+ zend_error(E_WARNING, "cairo_ft_font_face_create(): An error occurred opening the file:
%s", err_string);
RETURN_NULL();
- }
+ }
PHP_CAIRO_ERROR(cairo_font_face_status(font_face_object->font_face));
}
Modified: pecl/cairo/trunk/php_cairo.h
===================================================================
--- pecl/cairo/trunk/php_cairo.h 2011-12-28 17:16:51 UTC (rev 321480)
+++ pecl/cairo/trunk/php_cairo.h 2011-12-28 17:30:24 UTC (rev 321481)
@@ -170,6 +170,7 @@
FT_Library ft_lib;
ZEND_END_MODULE_GLOBALS(cairo)
+
#ifdef ZTS
# define CAIROG(v) TSRMG(cairo_globals_id, zend_cairo_globals *, v)
#else
@@ -177,6 +178,23 @@
#endif
ZEND_EXTERN_MODULE_GLOBALS(cairo)
+
+
+typedef struct _php_cairo_ft_error {
+ int err_code;
+ const char *err_msg;
+} php_cairo_ft_error;
+
+extern const php_cairo_ft_error php_cairo_ft_errors[];
+
+/* Helper for getting FreeType error strings */
+const char* php_cairo_get_ft_error(int error TSRMLS_DC);
+
+#undef __FTERRORS_H__
+#define FT_ERRORDEF( e, v, s ) { e, s },
+#define FT_ERROR_START_LIST {
+#define FT_ERROR_END_LIST { 0, 0 } };
+
#endif
PHP_MINIT_FUNCTION(cairo_matrix);
Modified: pecl/cairo/trunk/php_cairo_api.h
===================================================================
--- pecl/cairo/trunk/php_cairo_api.h 2011-12-28 17:16:51 UTC (rev 321480)
+++ pecl/cairo/trunk/php_cairo_api.h 2011-12-28 17:30:24 UTC (rev 321481)
@@ -63,6 +63,7 @@
cairo_surface_t *surface;
char * buffer;
stream_closure *closure;
+ zval *parent_zval;
} cairo_surface_object;
typedef struct _cairo_matrix_object {
@@ -110,6 +111,11 @@
extern cairo_font_options_t* php_cairo_font_options_copy(const cairo_font_options_t *);
extern cairo_t * php_cairo_context_reference(cairo_t *context);
+/* Helper for FreeType etc */
+#if defined(CAIRO_HAS_FT_FONT) && defined(HAVE_FREETYPE)
+const char* php_cairo_get_ft_error(int error);
+#endif
+
/* Helpers to make fetching internal objects work right with extended classes */
static inline cairo_context_object* cairo_context_object_get(zval *zobj TSRMLS_DC)
{
Modified: pecl/cairo/trunk/tests/CairoFontFace/CairoFtFontFace/cairo_ft_font_face_create.phpt
===================================================================
--- pecl/cairo/trunk/tests/CairoFontFace/CairoFtFontFace/cairo_ft_font_face_create.phpt 2011-12-28
17:16:51 UTC (rev 321480)
+++ pecl/cairo/trunk/tests/CairoFontFace/CairoFtFontFace/cairo_ft_font_face_create.phpt 2011-12-28
17:30:24 UTC (rev 321481)
@@ -48,5 +48,5 @@
Warning: cairo_ft_font_face_create expects parameter 1 to be a string or a stream resource in %s on
line 21
NULL
-Warning: cairo_ft_font_face_create(): An error occurred opening the file in %s on line 25
+Warning: cairo_ft_font_face_create(): An error occurred opening the file: %s in %s on line 25
NULL