Преглед на файлове

* Add binding for 7 new functions

* Add just_for_fun() function in sample program drivers.php
tags/v0.99.beta17
Nicolas Vion nico преди 16 години
родител
ревизия
e52449b14f
променени са 2 файла, в които са добавени 110 реда и са изтрити 1 реда
  1. +50
    -1
      caca-php/examples/drivers.php
  2. +60
    -0
      caca-php/php_caca.c

+ 50
- 1
caca-php/examples/drivers.php Целия файл

@@ -1,8 +1,57 @@
#!/usr/bin/php5
<?

echo "libcaca version: ".caca_get_version()."\n";

//--- Just for fun ---//

function just_for_fun() {

$moo = <<<EOT
(__)
(oo)
/------\/
/ | ||
* /\---/\
~~ ~~
EOT;

$cv = caca_create_canvas(0, 0);
caca_set_color_ansi($cv, CACA_LIGHTBLUE, CACA_DEFAULT);
caca_import_string($cv, $moo, "text");

for($j = 0; $j < caca_get_canvas_height($cv); $j++) {
for($i = 0; $i < caca_get_canvas_width($cv); $i += 2) {
caca_set_color_ansi($cv, (caca_rand(1, 10) > 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";

+ 60
- 0
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) {


Зареждане…
Отказ
Запис