]> granicus.if.org Git - php/commitdiff
Unicode support
authorDmitry Stogov <dmitry@php.net>
Tue, 16 Aug 2005 09:11:00 +0000 (09:11 +0000)
committerDmitry Stogov <dmitry@php.net>
Tue, 16 Aug 2005 09:11:00 +0000 (09:11 +0000)
ext/standard/image.c
ext/standard/tests/image/bug13213.phpt
ext/standard/tests/image/getimagesize.phpt
ext/standard/tests/image/getimagesize_246x247.phpt
ext/standard/tests/image/getimagesize_384x385.phpt
ext/standard/tests/image/getimagesize_swc.phpt
ext/standard/tests/image/image_type_to_mime_type.phpt

index acc0b42ea122151536c89f6a3f3ef57212b6c8b8..3cc4a0e8b6eeace748b6b855601d218d325c5626 100644 (file)
@@ -1120,13 +1120,20 @@ PHP_FUNCTION(image_type_to_mime_type)
 {
        zval **p_image_type;
        int arg_c = ZEND_NUM_ARGS();
+       char *temp;
 
        if ((arg_c!=1) || zend_get_parameters_ex(arg_c, &p_image_type) == FAILURE) {
                RETVAL_FALSE;
                WRONG_PARAM_COUNT;
        }
        convert_to_long_ex(p_image_type);
-       ZVAL_STRING(return_value, (char*)php_image_type_to_mime_type(Z_LVAL_PP(p_image_type)), 1);
+       temp = (char*)php_image_type_to_mime_type(Z_LVAL_PP(p_image_type));
+       if (UG(unicode)) {
+               UChar *u_temp = zend_ascii_to_unicode(temp, strlen(temp)+1 ZEND_FILE_LINE_CC);
+               ZVAL_UNICODE(return_value, u_temp, 0);
+       } else {
+               ZVAL_STRING(return_value, temp, 1);
+       }
 }
 /* }}} */
 
@@ -1136,6 +1143,7 @@ PHP_FUNCTION(image_type_to_extension)
 {
        long image_type;
        zend_bool inc_dot=1;
+       char *temp = NULL;
 
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|b", &image_type, &inc_dot) == FAILURE) {
                RETURN_FALSE;
@@ -1143,30 +1151,38 @@ PHP_FUNCTION(image_type_to_extension)
 
        switch (image_type) {
                case IMAGE_FILETYPE_GIF:
-                       RETURN_STRING(".gif" + !inc_dot, 1);
+                       temp = ".gif";
                case IMAGE_FILETYPE_JPEG:
-                       RETURN_STRING(".jpeg" + !inc_dot, 1);
+                       temp = ".jpeg";
                case IMAGE_FILETYPE_PNG:
-                       RETURN_STRING(".png" + !inc_dot, 1);
+                       temp = ".png";
                case IMAGE_FILETYPE_SWF:
                case IMAGE_FILETYPE_SWC:
-                       RETURN_STRING(".swf" + !inc_dot, 1);
+                       temp = ".swf";
                case IMAGE_FILETYPE_PSD:
-                       RETURN_STRING(".psd" + !inc_dot, 1);
+                       temp = ".psd";
                case IMAGE_FILETYPE_BMP:
                case IMAGE_FILETYPE_WBMP:
-                       RETURN_STRING(".bmp" + !inc_dot, 1);
+                       temp = ".bmp";
                case IMAGE_FILETYPE_TIFF_II:
                case IMAGE_FILETYPE_TIFF_MM:
-                       RETURN_STRING(".tiff" + !inc_dot, 1);
+                       temp = ".tiff";
                case IMAGE_FILETYPE_IFF:
-                       RETURN_STRING(".iff" + !inc_dot, 1);
+                       temp = ".iff";
                case IMAGE_FILETYPE_JPC:
-                       RETURN_STRING(".jpc" + !inc_dot, 1);
+                       temp = ".jpc";
                case IMAGE_FILETYPE_JP2:
-                       RETURN_STRING(".jp2" + !inc_dot, 1);
+                       temp = ".jp2";
                case IMAGE_FILETYPE_XBM:
-                       RETURN_STRING(".xbm" + !inc_dot, 1);
+                       temp = ".xbm";
+       }
+       if (temp) {
+               if (UG(unicode)) {
+                       UChar *u_temp = zend_ascii_to_unicode(temp + !inc_dot, strlen(temp)+inc_dot ZEND_FILE_LINE_CC);
+                       RETURN_UNICODE(u_temp, 0);
+               } else {
+                       RETURN_STRING(temp + !inc_dot, 1);
+               }
        }
 
        RETURN_FALSE;
@@ -1357,7 +1373,13 @@ PHP_FUNCTION(getimagesize)
                add_index_long(return_value, 1, result->height);
                add_index_long(return_value, 2, itype);
                spprintf(&temp, 0, "width=\"%d\" height=\"%d\"", result->width, result->height);
-               add_index_string(return_value, 3, temp, 0);
+               if (UG(unicode)) {
+                       UChar *u_temp = zend_ascii_to_unicode(temp, strlen(temp)+1 ZEND_FILE_LINE_CC);
+                       add_index_unicode(return_value, 3, u_temp, 0);
+                       efree(temp);
+               } else {
+                       add_index_string(return_value, 3, temp, 0);
+               }
 
                if (result->bits != 0) {
                        add_assoc_long(return_value, "bits", result->bits);
@@ -1365,7 +1387,13 @@ PHP_FUNCTION(getimagesize)
                if (result->channels != 0) {
                        add_assoc_long(return_value, "channels", result->channels);
                }
-               add_assoc_string(return_value, "mime", (char*)php_image_type_to_mime_type(itype), 1);
+               temp = (char*)php_image_type_to_mime_type(itype);
+               if (UG(unicode)) {
+                       UChar *u_temp = zend_ascii_to_unicode(temp, strlen(temp)+1 ZEND_FILE_LINE_CC);
+                       add_assoc_unicode(return_value, "mime", u_temp, 0);
+               } else {
+                       add_assoc_string(return_value, "mime", temp, 1);
+               }
                efree(result);
        } else {
                RETURN_FALSE;
index c97b7016b41626b6751aa971512d1aa00dcd65c8..a19190584703847dc4502f2b932bb4d13071fcdd 100644 (file)
@@ -21,3 +21,20 @@ array(7) {
   ["mime"]=>
   string(10) "image/jpeg"
 }
+--UEXPECT--
+array(7) {
+  [0]=>
+  int(1)
+  [1]=>
+  int(1)
+  [2]=>
+  int(2)
+  [3]=>
+  unicode(20) "width="1" height="1""
+  [u"bits"]=>
+  int(8)
+  [u"channels"]=>
+  int(3)
+  [u"mime"]=>
+  unicode(10) "image/jpeg"
+}
index 46003cffac39d2e9177866a8a58ccc86778df52c..368da04ceaddf4cccebe251751a5c75528fcf641 100644 (file)
@@ -194,3 +194,175 @@ array(11) {
     string(10) "image/tiff"
   }
 }
+--UEXPECT--
+array(11) {
+  [u"test1pix.bmp"]=>
+  array(6) {
+    [0]=>
+    int(1)
+    [1]=>
+    int(1)
+    [2]=>
+    int(6)
+    [3]=>
+    unicode(20) "width="1" height="1""
+    [u"bits"]=>
+    int(24)
+    [u"mime"]=>
+    unicode(9) "image/bmp"
+  }
+  [u"test1pix.jp2"]=>
+  array(7) {
+    [0]=>
+    int(1)
+    [1]=>
+    int(1)
+    [2]=>
+    int(10)
+    [3]=>
+    unicode(20) "width="1" height="1""
+    [u"bits"]=>
+    int(8)
+    [u"channels"]=>
+    int(3)
+    [u"mime"]=>
+    unicode(9) "image/jp2"
+  }
+  [u"test1pix.jpc"]=>
+  array(7) {
+    [0]=>
+    int(1)
+    [1]=>
+    int(1)
+    [2]=>
+    int(9)
+    [3]=>
+    unicode(20) "width="1" height="1""
+    [u"bits"]=>
+    int(8)
+    [u"channels"]=>
+    int(3)
+    [u"mime"]=>
+    unicode(24) "application/octet-stream"
+  }
+  [u"test1pix.jpg"]=>
+  array(7) {
+    [0]=>
+    int(1)
+    [1]=>
+    int(1)
+    [2]=>
+    int(2)
+    [3]=>
+    unicode(20) "width="1" height="1""
+    [u"bits"]=>
+    int(8)
+    [u"channels"]=>
+    int(3)
+    [u"mime"]=>
+    unicode(10) "image/jpeg"
+  }
+  [u"test2pix.gif"]=>
+  array(7) {
+    [0]=>
+    int(2)
+    [1]=>
+    int(1)
+    [2]=>
+    int(1)
+    [3]=>
+    unicode(20) "width="2" height="1""
+    [u"bits"]=>
+    int(1)
+    [u"channels"]=>
+    int(3)
+    [u"mime"]=>
+    unicode(9) "image/gif"
+  }
+  [u"test4pix.gif"]=>
+  array(7) {
+    [0]=>
+    int(4)
+    [1]=>
+    int(1)
+    [2]=>
+    int(1)
+    [3]=>
+    unicode(20) "width="4" height="1""
+    [u"bits"]=>
+    int(2)
+    [u"channels"]=>
+    int(3)
+    [u"mime"]=>
+    unicode(9) "image/gif"
+  }
+  [u"test4pix.iff"]=>
+  array(6) {
+    [0]=>
+    int(4)
+    [1]=>
+    int(1)
+    [2]=>
+    int(14)
+    [3]=>
+    unicode(20) "width="4" height="1""
+    [u"bits"]=>
+    int(4)
+    [u"mime"]=>
+    unicode(9) "image/iff"
+  }
+  [u"test4pix.png"]=>
+  array(6) {
+    [0]=>
+    int(4)
+    [1]=>
+    int(1)
+    [2]=>
+    int(3)
+    [3]=>
+    unicode(20) "width="4" height="1""
+    [u"bits"]=>
+    int(4)
+    [u"mime"]=>
+    unicode(9) "image/png"
+  }
+  [u"test4pix.psd"]=>
+  array(5) {
+    [0]=>
+    int(4)
+    [1]=>
+    int(1)
+    [2]=>
+    int(5)
+    [3]=>
+    unicode(20) "width="4" height="1""
+    [u"mime"]=>
+    unicode(9) "image/psd"
+  }
+  [u"test4pix.swf"]=>
+  array(5) {
+    [0]=>
+    int(550)
+    [1]=>
+    int(400)
+    [2]=>
+    int(4)
+    [3]=>
+    unicode(24) "width="550" height="400""
+    [u"mime"]=>
+    unicode(29) "application/x-shockwave-flash"
+  }
+  [u"test4pix.tif"]=>
+  array(5) {
+    [0]=>
+    int(4)
+    [1]=>
+    int(1)
+    [2]=>
+    int(7)
+    [3]=>
+    unicode(20) "width="4" height="1""
+    [u"mime"]=>
+    unicode(10) "image/tiff"
+  }
+}
index e5a0aea7799b227de154d4d6d9bf43cb1411d9e8..6f1c44124d119206fa63629b9f8c144d23f8cf50 100644 (file)
@@ -40,3 +40,21 @@ array(1) {
     string(9) "image/png"
   }
 }
+--UEXPECT--
+array(1) {
+  [u"246x247.png"]=>
+  array(6) {
+    [0]=>
+    int(246)
+    [1]=>
+    int(247)
+    [2]=>
+    int(3)
+    [3]=>
+    unicode(24) "width="246" height="247""
+    [u"bits"]=>
+    int(4)
+    [u"mime"]=>
+    unicode(9) "image/png"
+  }
+}
index 0051df71e0705e83d059e83fdcb16005662107aa..a75c8e051a3542ba3a1c4600f54b97005ab156ed 100644 (file)
@@ -40,3 +40,21 @@ array(1) {
     string(9) "image/png"
   }
 }
+--UEXPECT--
+array(1) {
+  [u"384x385.png"]=>
+  array(6) {
+    [0]=>
+    int(384)
+    [1]=>
+    int(385)
+    [2]=>
+    int(3)
+    [3]=>
+    unicode(24) "width="384" height="385""
+    [u"bits"]=>
+    int(1)
+    [u"mime"]=>
+    unicode(9) "image/png"
+  }
+}
index f8c74498a43c9a671f757094f18743baa96fa5f2..516164d7a98e3ca2f05aaa0301c189098faff252 100644 (file)
@@ -23,3 +23,16 @@ array(5) {
   ["mime"]=>
   string(29) "application/x-shockwave-flash"
 }
+--UEXPECT--
+array(5) {
+  [0]=>
+  int(550)
+  [1]=>
+  int(400)
+  [2]=>
+  int(13)
+  [3]=>
+  unicode(24) "width="550" height="400""
+  [u"mime"]=>
+  unicode(29) "application/x-shockwave-flash"
+}
index 94aabba0b99b10375c19bbc9fde957c7c4b6ebfc..d241aaf4edeb6f87bbeb3533c159e4e17a11ede0 100644 (file)
@@ -48,4 +48,29 @@ array(11) {
   string(29) "application/x-shockwave-flash"
   ["test4pix.tif"]=>
   string(10) "image/tiff"
+}
+--UEXPECT--
+array(11) {
+  [u"test1pix.bmp"]=>
+  unicode(9) "image/bmp"
+  [u"test1pix.jp2"]=>
+  unicode(9) "image/jp2"
+  [u"test1pix.jpc"]=>
+  unicode(24) "application/octet-stream"
+  [u"test1pix.jpg"]=>
+  unicode(10) "image/jpeg"
+  [u"test2pix.gif"]=>
+  unicode(9) "image/gif"
+  [u"test4pix.gif"]=>
+  unicode(9) "image/gif"
+  [u"test4pix.iff"]=>
+  unicode(9) "image/iff"
+  [u"test4pix.png"]=>
+  unicode(9) "image/png"
+  [u"test4pix.psd"]=>
+  unicode(9) "image/psd"
+  [u"test4pix.swf"]=>
+  unicode(29) "application/x-shockwave-flash"
+  [u"test4pix.tif"]=>
+  unicode(10) "image/tiff"
 }
\ No newline at end of file