From 77ff19864fb387375699f309903705f611b945d6 Mon Sep 17 00:00:00 2001 From: Nicolas Vion Date: Tue, 28 Oct 2008 11:46:18 +0000 Subject: [PATCH] * Add php binding for functions: caca_file_write, caca_file_read --- caca-php/examples/demo.php | 2 ++ caca-php/php_caca.c | 31 +++++++++++++++++++++++++++++++ caca-php/php_caca.h | 2 ++ 3 files changed, 35 insertions(+) diff --git a/caca-php/examples/demo.php b/caca-php/examples/demo.php index 6583d1e..d0ec75d 100644 --- a/caca-php/examples/demo.php +++ b/caca-php/examples/demo.php @@ -361,6 +361,8 @@ function demo_triangles($cv, $bounds, $outline, $dithering) { caca_draw_triangle($cv, $xa, $ya, $xb, $yb, $xc, $yc, '#'); } +function demo_render($cv, $bounds, $outline, $dithering) { +} main(); diff --git a/caca-php/php_caca.c b/caca-php/php_caca.c index f9bc604..a62da56 100644 --- a/caca-php/php_caca.c +++ b/caca-php/php_caca.c @@ -107,9 +107,11 @@ static function_entry caca_functions[] = { PHP_FE(caca_get_dither_algorithm_list, NULL) PHP_FE(caca_get_dither_algorithm, NULL) PHP_FE(caca_dither_bitmap_gd, NULL) + PHP_FE(caca_load_font, NULL) PHP_FE(caca_get_font_list, NULL) PHP_FE(caca_get_font_width, NULL) PHP_FE(caca_get_font_height, NULL) + PHP_FE(caca_get_font_bloc, NULL) PHP_FE(caca_render_canvas, NULL) PHP_FE(caca_canvas_set_figfont, NULL) PHP_FE(caca_put_figchar, NULL) @@ -1198,6 +1200,9 @@ PHP_FUNCTION(caca_dither_bitmap_gd) { RETURN_TRUE; } +PHP_FUNCTION(caca_load_font) { +} + PHP_FUNCTION(caca_get_font_list) { char const * const *list = caca_get_font_list(); int i; @@ -1226,6 +1231,9 @@ PHP_FUNCTION(caca_get_font_height) { RETURN_LONG(caca_get_font_height(font)); } +PHP_FUNCTION(caca_get_font_bloc) { +} + PHP_FUNCTION(caca_render_canvas) { } @@ -1286,9 +1294,32 @@ PHP_FUNCTION(caca_file_tell) { } PHP_FUNCTION(caca_file_read) { + zval *_zval; + long len; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &_zval, &len) == FAILURE) { + RETURN_FALSE; + } + caca_file_t *file; + ZEND_FETCH_RESOURCE(file, caca_file_t*, &_zval, -1, PHP_CACA_FILE_RES_NAME, le_caca_file); + + char *buffer = emalloc(len); + caca_file_read(file, buffer, len); + + return_value->type = IS_STRING; + return_value->value.str.len = len; + return_value->value.str.val = buffer; } PHP_FUNCTION(caca_file_write) { + zval *_zval; + char *buf; + long buf_len = 0; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &_zval, &buf, &buf_len) == FAILURE) { + RETURN_FALSE; + } + caca_file_t *file; + ZEND_FETCH_RESOURCE(file, caca_file_t*, &_zval, -1, PHP_CACA_FILE_RES_NAME, le_caca_file); + RETURN_LONG(caca_file_write(file, buf, buf_len)); } PHP_FUNCTION(caca_file_gets) { diff --git a/caca-php/php_caca.h b/caca-php/php_caca.h index 2ccccbe..b18d25b 100644 --- a/caca-php/php_caca.h +++ b/caca-php/php_caca.h @@ -124,9 +124,11 @@ PHP_FUNCTION(caca_set_dither_algorithm); PHP_FUNCTION(caca_get_dither_algorithm_list); PHP_FUNCTION(caca_get_dither_algorithm); PHP_FUNCTION(caca_dither_bitmap_gd); +PHP_FUNCTION(caca_load_font); PHP_FUNCTION(caca_get_font_list); PHP_FUNCTION(caca_get_font_width); PHP_FUNCTION(caca_get_font_height); +PHP_FUNCTION(caca_get_font_bloc); PHP_FUNCTION(caca_render_canvas); PHP_FUNCTION(caca_canvas_set_figfont); PHP_FUNCTION(caca_put_figchar);