- use PHP streams for font loading (lame copy&paste :p)

pp [2004-12-22 18:24:55]
- use PHP streams for font loading (lame copy&paste :p)


git-svn-id: https://siedziba.pl:790/svn/repos/php-imlib/trunk@92 455248ca-bdda-0310-9134-f4ebb693071a
Filename
php_imlib.c
diff --git a/php_imlib.c b/php_imlib.c
index 5422631..c142ef4 100644
--- a/php_imlib.c
+++ b/php_imlib.c
@@ -2028,6 +2028,8 @@ PHP_FUNCTION(imlib_load_font)
    zval **fontname, **encoding;
    PHP_Imlib_Font fn;
    int argc;
+   char* filename;
+   FILE* f;

    argc=ZEND_NUM_ARGS();
    if (argc < 1 || argc > 2 || zend_get_parameters_ex(argc, &fontname, &encoding) == FAILURE) {
@@ -2051,7 +2053,14 @@ PHP_FUNCTION(imlib_load_font)
    }

    convert_to_string_ex(fontname);
-   fn->font = imlib_load_font(Z_STRVAL_PP(fontname));
+
+   f = php_stream_open_wrapper_as_file(Z_STRVAL_PP(fontname), "rb", IGNORE_PATH | ENFORCE_SAFE_MODE | REPORT_ERRORS, &filename);
+   if (f == NULL) RETURN_FALSE;
+
+   fn->font = imlib_load_font(filename);
+
+   fclose(f);
+   efree(filename);

    if (!fn->font)
    {
@@ -2935,6 +2944,8 @@ PHP_FUNCTION(imlib_psloadfont)
 #if HAVE_LIBT1
         zval **file;
         int f_ind, *font;
+        char* filename;
+        FILE* f;

         if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &file) == FAILURE) {
                 ZEND_WRONG_PARAM_COUNT();
@@ -2942,7 +2953,13 @@ PHP_FUNCTION(imlib_psloadfont)

         convert_to_string_ex(file);

-        f_ind = T1_AddFont(Z_STRVAL_PP(file));
+        f = php_stream_open_wrapper_as_file(Z_STRVAL_PP(file), "rb", IGNORE_PATH | ENFORCE_SAFE_MODE | REPORT_ERRORS, &filename);
+        if (f == NULL) RETURN_FALSE;
+
+        f_ind = T1_AddFont(filename);
+
+        fclose(f);
+        efree(filename);

         if (f_ind < 0) {
                 switch (f_ind) {
@@ -3007,6 +3024,8 @@ PHP_FUNCTION(imlib_psencodefont)
         zval **fnt, **enc;
         char **enc_vector;
         int *f_ind;
+        char* filename;
+        FILE* f;

         if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &fnt, &enc) == FAILURE) {
                 ZEND_WRONG_PARAM_COUNT();
@@ -3016,7 +3035,15 @@ PHP_FUNCTION(imlib_psencodefont)

         ZEND_FETCH_RESOURCE(f_ind, int *, fnt, -1, "Type 1 font", le_ps_font);

-        if ((enc_vector = T1_LoadEncoding(Z_STRVAL_PP(enc))) == NULL) {
+        f = php_stream_open_wrapper_as_file(Z_STRVAL_PP(enc), "rb", IGNORE_PATH | ENFORCE_SAFE_MODE | REPORT_ERRORS, &filename);
+        if (f == NULL) RETURN_FALSE;
+
+        enc_vector = T1_LoadEncoding(filename);
+
+        fclose(f);
+        efree(filename);
+
+        if (enc_vector == NULL) {
                 php_error(E_WARNING, "Couldn't load encoding vector from %s", Z_STRVAL_PP(enc));
                 RETURN_FALSE;
         }
ViewGit