diff --git a/caca-php/examples/drivers.php b/caca-php/examples/drivers.php index 5133f8a..fd69fed 100755 --- a/caca-php/examples/drivers.php +++ b/caca-php/examples/drivers.php @@ -1,8 +1,57 @@ #!/usr/bin/php5 5 ? CACA_LIGHTBLUE : CACA_WHITE), CACA_DEFAULT); + $a = caca_get_attr($cv, -1, -1); + caca_put_attr($cv, $i, $j, $a); + caca_put_attr($cv, $i + 1, $j, $a); + } + } + caca_set_color_ansi($cv, CACA_LIGHTGREEN, CACA_DEFAULT); + caca_put_str($cv, 8, 0, "Moo!"); + echo caca_export_string($cv, "utf8"); +} + + +just_for_fun(); + +//--- Show caca's information ---// + +echo "libcaca version: ".caca_get_version()."\n\n"; echo "Available drivers:\n"; $list = caca_get_display_driver_list(); foreach($list as $type => $name) echo "* $name ($type)\n"; +echo "\n"; + +echo "Available export modules:\n"; +$list = caca_get_export_list(); +foreach($list as $type => $name) + echo "* $name ($type)\n"; +echo "\n"; + +echo "Available caca fonts:\n"; +$list = caca_get_font_list(); +foreach($list as $name) + echo "* $name\n"; +echo "\n"; diff --git a/caca-php/php_caca.c b/caca-php/php_caca.c index 15added..e87b880 100644 --- a/caca-php/php_caca.c +++ b/caca-php/php_caca.c @@ -956,6 +956,18 @@ PHP_FUNCTION(caca_set_dither_color) { } PHP_FUNCTION(caca_get_dither_color_list) { + zval *_zval; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) { + RETURN_FALSE; + } + caca_dither_t *dither; + ZEND_FETCH_RESOURCE(dither, caca_dither_t*, &_zval, -1, PHP_CACA_DITHER_RES_NAME, le_caca_dither); + + char const * const *list = caca_get_dither_antialias_list(dither); + int i; + array_init(return_value); + for(i = 0; list[i]; i += 2) + add_assoc_string(return_value, (char*) list[i], (char*) list[i + 1], 1); } PHP_FUNCTION(caca_get_dither_color) { @@ -965,6 +977,18 @@ PHP_FUNCTION(caca_set_dither_charset) { } PHP_FUNCTION(caca_get_dither_charset_list) { + zval *_zval; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) { + RETURN_FALSE; + } + caca_dither_t *dither; + ZEND_FETCH_RESOURCE(dither, caca_dither_t*, &_zval, -1, PHP_CACA_DITHER_RES_NAME, le_caca_dither); + + char const * const *list = caca_get_dither_charset_list(dither); + int i; + array_init(return_value); + for(i = 0; list[i]; i += 2) + add_assoc_string(return_value, (char*) list[i], (char*) list[i + 1], 1); } PHP_FUNCTION(caca_get_dither_charset) { @@ -974,6 +998,18 @@ PHP_FUNCTION(caca_set_dither_algorithm) { } PHP_FUNCTION(caca_get_dither_algorithm_list) { + zval *_zval; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) { + RETURN_FALSE; + } + caca_dither_t *dither; + ZEND_FETCH_RESOURCE(dither, caca_dither_t*, &_zval, -1, PHP_CACA_DITHER_RES_NAME, le_caca_dither); + + char const * const *list = caca_get_dither_algorithm_list(dither); + int i; + array_init(return_value); + for(i = 0; list[i]; i += 2) + add_assoc_string(return_value, (char*) list[i], (char*) list[i + 1], 1); } PHP_FUNCTION(caca_get_dither_algorithm) { @@ -983,12 +1019,31 @@ PHP_FUNCTION(caca_dither_bitmap) { } PHP_FUNCTION(caca_get_font_list) { + char const * const *list = caca_get_font_list(); + int i; + array_init(return_value); + for(i = 0; list[i]; i += 1) + add_next_index_string(return_value, (char*) list[i], 1); } PHP_FUNCTION(caca_get_font_width) { + zval *_zval; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) { + RETURN_FALSE; + } + caca_font_t *font; + ZEND_FETCH_RESOURCE(font, caca_font_t*, &_zval, -1, PHP_CACA_FONT_RES_NAME, le_caca_font); + RETURN_LONG(caca_get_font_width(font)); } PHP_FUNCTION(caca_get_font_height) { + zval *_zval; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) { + RETURN_FALSE; + } + caca_font_t *font; + ZEND_FETCH_RESOURCE(font, caca_font_t*, &_zval, -1, PHP_CACA_FONT_RES_NAME, le_caca_font); + RETURN_LONG(caca_get_font_height(font)); } PHP_FUNCTION(caca_render_canvas) { @@ -1061,6 +1116,11 @@ PHP_FUNCTION(caca_export_string) { } PHP_FUNCTION(caca_get_export_list) { + char const * const *list = caca_get_export_list(); + int i; + array_init(return_value); + for(i = 0; list[i]; i += 2) + add_assoc_string(return_value, (char*) list[i], (char*) list[i + 1], 1); } PHP_FUNCTION(caca_create_display) {