From 0b7482f6d72ec21d5b3d3a5c30b2a30ecd160305 Mon Sep 17 00:00:00 2001 From: aki Date: Sat, 24 May 2008 23:20:07 +0530 Subject: [PATCH] Added some more functions - reached miter_limit --- individual_files/phpCairoContext.c | 220 ++++++++++++++++++------------------- individual_files/phpCairoSurface.c | 2 +- individual_files/php_phpCairo.h | 23 +++- 3 files changed, 128 insertions(+), 117 deletions(-) diff --git a/individual_files/phpCairoContext.c b/individual_files/phpCairoContext.c index b17e31f..da4f80a 100644 --- a/individual_files/phpCairoContext.c +++ b/individual_files/phpCairoContext.c @@ -239,7 +239,7 @@ PHP_METHOD(CairoContext, copy_clip_rectangle_list) cairo_rectangle_t *r; cairo_rectangle_list_t *rlist; zval *arr; - zval *temp_arr; + zval **temp_arr; int i; if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoContext_ce_ptr) == FAILURE) { @@ -249,6 +249,7 @@ PHP_METHOD(CairoContext, copy_clip_rectangle_list) context_object *curr=(context_object *)zend_objects_get_address(_this_zval TSRMLS_CC); rlist = cairo_copy_clip_rectangle_list(curr->context); phpCAIRO_ERROR(rlist->status) + /* ALLOC_INIT_ZVAL(arr); array_init(arr); @@ -315,7 +316,7 @@ PHP_METHOD(CairoContext, copy_path) object_init(return_value); path_object *pobj = (path_object *)zend_objects_get_address(return_value TSRMLS_CC); - pobj = cairo_copy_path(curr->context); + pobj->path = cairo_copy_path(curr->context); } /* }}} copy_path */ @@ -338,8 +339,10 @@ PHP_METHOD(CairoContext, copy_path_flat) _this_ce = Z_OBJCE_P(_this_zval); context_object *curr=(context_object *)zend_objects_get_address(_this_zval TSRMLS_CC); - object_init(return_value); + path_object *pobj = (path_object *)zend_objects_get_address(return_value TSRMLS_CC); + pobj->path = cairo_copy_path_flat(curr->context); + } /* }}} copy_path_flat */ @@ -368,8 +371,8 @@ PHP_METHOD(CairoContext, curve_to) _this_ce = Z_OBJCE_P(_this_zval); context_object *curr=(context_object *)zend_objects_get_address(_this_zval TSRMLS_CC); - - php_error(E_WARNING, "curve_to: not yet implemented"); RETURN_FALSE; + cairo_curve_to(curr->context, x1, y1, x2, y2, x3, y3); + phpCAIRO_CONTEXT_ERROR(curr->context) } /* }}} curve_to */ @@ -394,13 +397,14 @@ PHP_METHOD(CairoContext, device_to_user) _this_ce = Z_OBJCE_P(_this_zval); context_object *curr=(context_object *)zend_objects_get_address(_this_zval TSRMLS_CC); - - + + cairo_device_to_user(curr->context, &x, &y); + phpCAIRO_CONTEXT_ERROR(curr->context) + array_init(return_value); + add_assoc_double(return_value, "x", x); + add_assoc_double(return_value, "y", y); - php_error(E_WARNING, "device_to_user: not yet implemented"); RETURN_FALSE; - - array_init(return_value); } /* }}} device_to_user */ @@ -424,13 +428,12 @@ PHP_METHOD(CairoContext, device_to_user_distance) _this_ce = Z_OBJCE_P(_this_zval); context_object *curr=(context_object *)zend_objects_get_address(_this_zval TSRMLS_CC); - - + cairo_device_to_user_distance(curr->context, &x, &y); + phpCAIRO_CONTEXT_ERROR(curr->context) array_init(return_value); + add_assoc_double(return_value, "x", x); + add_assoc_double(return_value, "y", y); - php_error(E_WARNING, "device_to_user_distance: not yet implemented"); RETURN_FALSE; - - array_init(return_value); } /* }}} device_to_user_distance */ @@ -452,10 +455,10 @@ PHP_METHOD(CairoContext, fill) _this_ce = Z_OBJCE_P(_this_zval); context_object *curr=(context_object *)zend_objects_get_address(_this_zval TSRMLS_CC); + cairo_fill(curr->context); + phpCAIRO_CONTEXT_ERROR(curr->context) - php_error(E_WARNING, "fill: not yet implemented"); RETURN_FALSE; - } /* }}} fill */ @@ -468,7 +471,7 @@ PHP_METHOD(CairoContext, fill_extents) zend_class_entry * _this_ce; zval * _this_zval = NULL; - + cairo_font_extents_t e; if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoContext_ce_ptr) == FAILURE) { @@ -477,13 +480,15 @@ PHP_METHOD(CairoContext, fill_extents) _this_ce = Z_OBJCE_P(_this_zval); context_object *curr=(context_object *)zend_objects_get_address(_this_zval TSRMLS_CC); - - - array_init(return_value); - - php_error(E_WARNING, "fill_extents: not yet implemented"); RETURN_FALSE; - + cairo_font_extents(curr->context, &e); + + phpCAIRO_CONTEXT_ERROR(curr->context) array_init(return_value); + add_assoc_double(return_value, "ascent", e.ascent); + add_assoc_double(return_value, "descent", e.descent); + add_assoc_double(return_value, "height", e.height); + add_assoc_double(return_value, "max X advance", e.max_x_advance); + add_assoc_double(return_value, "max Y advance", e.max_y_advance); } /* }}} fill_extents */ @@ -505,10 +510,10 @@ PHP_METHOD(CairoContext, fill_preserve) _this_ce = Z_OBJCE_P(_this_zval); context_object *curr=(context_object *)zend_objects_get_address(_this_zval TSRMLS_CC); + cairo_fill_preserve(curr->context); + phpCAIRO_CONTEXT_ERROR(curr->context) - php_error(E_WARNING, "fill_preserve: not yet implemented"); RETURN_FALSE; - } /* }}} fill_preserve */ @@ -519,10 +524,8 @@ PHP_METHOD(CairoContext, fill_preserve) PHP_METHOD(CairoContext, font_extents) { zend_class_entry * _this_ce; - zval * _this_zval = NULL; - - + cairo_font_extents_t e; if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoContext_ce_ptr) == FAILURE) { return; @@ -530,13 +533,16 @@ PHP_METHOD(CairoContext, font_extents) _this_ce = Z_OBJCE_P(_this_zval); context_object *curr=(context_object *)zend_objects_get_address(_this_zval TSRMLS_CC); - - + cairo_font_extents(curr->context, &e); + phpCAIRO_CONTEXT_ERROR(curr->context) + array_init(return_value); + add_assoc_double(return_value, "ascent", e.ascent); + add_assoc_double(return_value, "descent", e.descent); + add_assoc_double(return_value, "height", e.height); + add_assoc_double(return_value, "max X advance", e.max_x_advance); + add_assoc_double(return_value, "max Y advance", e.max_y_advance); - php_error(E_WARNING, "font_extents: not yet implemented"); RETURN_FALSE; - - array_init(return_value); } /* }}} font_extents */ @@ -547,10 +553,8 @@ PHP_METHOD(CairoContext, font_extents) PHP_METHOD(CairoContext, get_antialias) { zend_class_entry * _this_ce; - zval * _this_zval = NULL; - - + long temp; if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoContext_ce_ptr) == FAILURE) { return; @@ -558,11 +562,9 @@ PHP_METHOD(CairoContext, get_antialias) _this_ce = Z_OBJCE_P(_this_zval); context_object *curr=(context_object *)zend_objects_get_address(_this_zval TSRMLS_CC); + temp = cairo_get_antialias(curr->context); - - php_error(E_WARNING, "get_antialias: not yet implemented"); RETURN_FALSE; - - RETURN_LONG(0); + RETURN_LONG(temp); } /* }}} get_antialias */ @@ -575,8 +577,8 @@ PHP_METHOD(CairoContext, get_current_point) zend_class_entry * _this_ce; zval * _this_zval = NULL; - - + double x,y; + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoContext_ce_ptr) == FAILURE) { return; @@ -584,13 +586,10 @@ PHP_METHOD(CairoContext, get_current_point) _this_ce = Z_OBJCE_P(_this_zval); context_object *curr=(context_object *)zend_objects_get_address(_this_zval TSRMLS_CC); - - - array_init(return_value); - - php_error(E_WARNING, "get_current_point: not yet implemented"); RETURN_FALSE; - + cairo_get_current_point(curr->context, &x, &y); array_init(return_value); + add_assoc_double(return_value, "x", x); + add_assoc_double(return_value, "y", y); } /* }}} get_current_point */ @@ -601,10 +600,10 @@ PHP_METHOD(CairoContext, get_current_point) PHP_METHOD(CairoContext, get_dash) { zend_class_entry * _this_ce; - + zval *sub_array; zval * _this_zval = NULL; - - + double *dashes = NULL, offset; + int count, i; if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoContext_ce_ptr) == FAILURE) { return; @@ -612,13 +611,21 @@ PHP_METHOD(CairoContext, get_dash) _this_ce = Z_OBJCE_P(_this_zval); context_object *curr=(context_object *)zend_objects_get_address(_this_zval TSRMLS_CC); + count = cairo_get_dash_count(curr->context); + dashes = emalloc(count* sizeof(double)); + if(dashes==NULL) + return; + cairo_get_dashes(curr->context, dashes, &offset); - - array_init(return_value); - - php_error(E_WARNING, "get_dash: not yet implemented"); RETURN_FALSE; - + MAKE_STD_ZVAL(sub_array); + array_init(sub_array); + for(i=0; icontext); + + RETURN_LONG(count); } /* }}} get_dash_count */ @@ -657,7 +662,7 @@ PHP_METHOD(CairoContext, get_fill_rule) zend_class_entry * _this_ce; zval * _this_zval = NULL; - + long fill; if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoContext_ce_ptr) == FAILURE) { @@ -666,11 +671,9 @@ PHP_METHOD(CairoContext, get_fill_rule) _this_ce = Z_OBJCE_P(_this_zval); context_object *curr=(context_object *)zend_objects_get_address(_this_zval TSRMLS_CC); + fill = cairo_get_fill_rule(curr->context); - - php_error(E_WARNING, "get_fill_rule: not yet implemented"); RETURN_FALSE; - - RETURN_LONG(0); + RETURN_LONG(fill); } /* }}} get_fill_rule */ @@ -684,8 +687,6 @@ PHP_METHOD(CairoContext, get_font_face) zval * _this_zval = NULL; - - if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoContext_ce_ptr) == FAILURE) { return; } @@ -693,10 +694,9 @@ PHP_METHOD(CairoContext, get_font_face) _this_ce = Z_OBJCE_P(_this_zval); context_object *curr=(context_object *)zend_objects_get_address(_this_zval TSRMLS_CC); - - php_error(E_WARNING, "get_font_face: not yet implemented"); RETURN_FALSE; - object_init(return_value); + fontface_object *ffobj = (fontface_object *)zend_objects_get_address(return_value TSRMLS_CC); + ffobj->fontface = cairo_get_font_face(curr->context); } /* }}} get_font_face */ @@ -709,7 +709,7 @@ PHP_METHOD(CairoContext, get_font_matrix) zend_class_entry * _this_ce; zval * _this_zval = NULL; - + cairo_matrix_t matrix; if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoContext_ce_ptr) == FAILURE) { @@ -718,11 +718,11 @@ PHP_METHOD(CairoContext, get_font_matrix) _this_ce = Z_OBJCE_P(_this_zval); context_object *curr=(context_object *)zend_objects_get_address(_this_zval TSRMLS_CC); - - - php_error(E_WARNING, "get_font_matrix: not yet implemented"); RETURN_FALSE; + cairo_get_font_matrix(curr->context, &matrix); object_init(return_value); + matrix_object *matobj = (matrix_object *)zend_object_get_address(return_value TSRMLS_CC); + matobj->matrix = &matrix; } /* }}} get_font_matrix */ @@ -735,7 +735,7 @@ PHP_METHOD(CairoContext, get_font_options) zend_class_entry * _this_ce; zval * _this_zval = NULL; - + cairo_font_options_t *options = cairo_font_options_create(); if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoContext_ce_ptr) == FAILURE) { @@ -744,11 +744,12 @@ PHP_METHOD(CairoContext, get_font_options) _this_ce = Z_OBJCE_P(_this_zval); context_object *curr=(context_object *)zend_objects_get_address(_this_zval TSRMLS_CC); - - - php_error(E_WARNING, "get_font_options: not yet implemented"); RETURN_FALSE; - + cairo_get_font_options(curr->context, options); + object_init(return_value); + fontoptions_object *foobj = (fontoptions_object *)zend_objects_get_address(return_value TSRMLS_CC); + foobj->fontoptions = options; + } /* }}} get_font_options */ @@ -770,11 +771,11 @@ PHP_METHOD(CairoContext, get_group_target) _this_ce = Z_OBJCE_P(_this_zval); context_object *curr=(context_object *)zend_objects_get_address(_this_zval TSRMLS_CC); - - - php_error(E_WARNING, "get_group_target: not yet implemented"); RETURN_FALSE; - + object_init(return_value); + surface_object *sobj = (surface_object *)zend_objects_get_address(return_value TSRMLS_CC); + + sobj->surface = cairo_get_group_target(curr->context); } /* }}} get_group_target */ @@ -787,7 +788,7 @@ PHP_METHOD(CairoContext, get_line_cap) zend_class_entry * _this_ce; zval * _this_zval = NULL; - + long line_cap; if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoContext_ce_ptr) == FAILURE) { @@ -796,11 +797,10 @@ PHP_METHOD(CairoContext, get_line_cap) _this_ce = Z_OBJCE_P(_this_zval); context_object *curr=(context_object *)zend_objects_get_address(_this_zval TSRMLS_CC); + line_cap = cairo_get_line_cap(curr->context); - php_error(E_WARNING, "get_line_cap: not yet implemented"); RETURN_FALSE; - - RETURN_LONG(0); + RETURN_LONG(line_cap); } /* }}} get_line_cap */ @@ -813,7 +813,7 @@ PHP_METHOD(CairoContext, get_line_join) zend_class_entry * _this_ce; zval * _this_zval = NULL; - + long line_join; if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoContext_ce_ptr) == FAILURE) { @@ -823,10 +823,8 @@ PHP_METHOD(CairoContext, get_line_join) _this_ce = Z_OBJCE_P(_this_zval); context_object *curr=(context_object *)zend_objects_get_address(_this_zval TSRMLS_CC); - - php_error(E_WARNING, "get_line_join: not yet implemented"); RETURN_FALSE; - - RETURN_LONG(0); + line_join = cairo_get_line_join(curr->context); + RETURN_LONG(line_join); } /* }}} get_line_join */ @@ -840,6 +838,8 @@ PHP_METHOD(CairoContext, get_line_width) zval * _this_zval = NULL; + double width; + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoContext_ce_ptr) == FAILURE) { @@ -848,11 +848,9 @@ PHP_METHOD(CairoContext, get_line_width) _this_ce = Z_OBJCE_P(_this_zval); context_object *curr=(context_object *)zend_objects_get_address(_this_zval TSRMLS_CC); + width = cairo_get_line_width(curr->context); - - php_error(E_WARNING, "get_line_width: not yet implemented"); RETURN_FALSE; - - RETURN_DOUBLE(0.0); + RETURN_DOUBLE(width); } /* }}} get_line_width */ @@ -866,7 +864,7 @@ PHP_METHOD(CairoContext, get_matrix) zval * _this_zval = NULL; - + cairo_matrix_t matrix; if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoContext_ce_ptr) == FAILURE) { return; @@ -875,23 +873,23 @@ PHP_METHOD(CairoContext, get_matrix) _this_ce = Z_OBJCE_P(_this_zval); context_object *curr=(context_object *)zend_objects_get_address(_this_zval TSRMLS_CC); - - php_error(E_WARNING, "get_matrix: not yet implemented"); RETURN_FALSE; - + cairo_get_matrix(curr->context, &matrix); object_init(return_value); + matrix_object *mobj = (matrix_object *)zend_objects_get_address(return_value TSRMLS_CC); + mobj->matrix = &matrix; } /* }}} get_matrix */ -/* {{{ proto float get_matrix_limit() +/* {{{ proto float get_miter_limit() */ -PHP_METHOD(CairoContext, get_matrix_limit) +PHP_METHOD(CairoContext, get_miter_limit) { zend_class_entry * _this_ce; zval * _this_zval = NULL; - + double miter; if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoContext_ce_ptr) == FAILURE) { @@ -900,13 +898,11 @@ PHP_METHOD(CairoContext, get_matrix_limit) _this_ce = Z_OBJCE_P(_this_zval); context_object *curr=(context_object *)zend_objects_get_address(_this_zval TSRMLS_CC); + miter = cairo_get_miter_limit(curr->context); - - php_error(E_WARNING, "get_matrix_limit: not yet implemented"); RETURN_FALSE; - - RETURN_DOUBLE(0.0); + RETURN_DOUBLE(miter); } -/* }}} get_matrix_limit */ +/* }}} get_miter_limit */ @@ -2641,7 +2637,7 @@ static zend_function_entry CairoContext_methods[] = { PHP_ME(CairoContext, get_line_join, NULL, /**/ZEND_ACC_PUBLIC) PHP_ME(CairoContext, get_line_width, NULL, /**/ZEND_ACC_PUBLIC) PHP_ME(CairoContext, get_matrix, NULL, /**/ZEND_ACC_PUBLIC) - PHP_ME(CairoContext, get_matrix_limit, NULL, /**/ZEND_ACC_PUBLIC) + PHP_ME(CairoContext, get_miter_limit, NULL, /**/ZEND_ACC_PUBLIC) PHP_ME(CairoContext, get_operator, NULL, /**/ZEND_ACC_PUBLIC) PHP_ME(CairoContext, get_scaled_font, NULL, /**/ZEND_ACC_PUBLIC) PHP_ME(CairoContext, get_source, NULL, /**/ZEND_ACC_PUBLIC) diff --git a/individual_files/phpCairoSurface.c b/individual_files/phpCairoSurface.c index 15b89f6..80b9ba2 100644 --- a/individual_files/phpCairoSurface.c +++ b/individual_files/phpCairoSurface.c @@ -175,7 +175,7 @@ PHP_METHOD(CairoSurface, get_font_options) cairo_surface_get_font_options(curr->surface, options); object_init(return_value); fontoptions_object *fobj = (fontoptions_object *)zend_objects_get_address(return_value TSRMLS_CC); - fobj->font_options=options; + fobj->fontoptions=options; } /* }}} get_font_options */ diff --git a/individual_files/php_phpCairo.h b/individual_files/php_phpCairo.h index 47fc4ce..1c9b4cb 100644 --- a/individual_files/php_phpCairo.h +++ b/individual_files/php_phpCairo.h @@ -61,9 +61,24 @@ typedef struct _path_object { typedef struct _fontoptions_object { zend_object std; - cairo_font_options_t *font_options; + cairo_font_options_t *fontoptions; } fontoptions_object; +typedef struct _fontface_object { + zend_object std; + cairo_font_face_t *fontface; +} fontface_object; + +typedef struct _matrix_object { + zend_object std; + cairo_matrix_t *matrix; +} matrix_object; + +typedef struct _pattern_object { + zend_object std; + cairo_pattern_t *pattern; +} pattern_object; + #ifdef PHP_WIN32 #define PHP_PHPCAIRO_API __declspec(dllexport) @@ -389,12 +404,12 @@ ZEND_END_ARG_INFO() #define CairoContext__get_matrix_args NULL #endif -PHP_METHOD(CairoContext, get_matrix_limit); +PHP_METHOD(CairoContext, get_miter_limit); #if (PHP_MAJOR_VERSION >= 5) -ZEND_BEGIN_ARG_INFO_EX(CairoContext__get_matrix_limit_args, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_INFO_EX(CairoContext__get_miter_limit_args, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) ZEND_END_ARG_INFO() #else /* PHP 4.x */ -#define CairoContext__get_matrix_limit_args NULL +#define CairoContext__get_miter_limit_args NULL #endif PHP_METHOD(CairoContext, get_operator); -- 2.11.4.GIT