PHP_METHOD(WinGdiPath, beizerTo) { wingdi_devicecontext_object *dc_obj; wingdi_path_object *path_obj; zval ***parameters, **x, **y; POINT *points = NULL; DWORD points_total = 0; int param_count, i; WINGDI_ERROR_HANDLING(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "+", ¶meters, ¶m_count) == FAILURE) return; WINGDI_RESTORE_ERRORS(); path_obj = zend_object_store_get_object(getThis() TSRMLS_CC); dc_obj = zend_object_store_get_object(path_obj->device_context TSRMLS_CC); points = emalloc(param_count * sizeof(POINT)); for (i = 0; i < param_count; i++) { // We expect only arrays if (Z_TYPE_PP(parameters[i]) != IS_ARRAY) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "expected array for parameter %d, got %s", i + 1, zend_zval_type_name(*(parameters[i]))); goto CLEANUP; } else { // We want 2 elements if (zend_hash_num_elements(Z_ARRVAL_PP(parameters[i])) != 2) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "expected 2 elements for array at parameter %d, got %d", i + 1, zend_hash_num_elements(Z_ARRVAL_PP(parameters[i]))); goto CLEANUP; } else { zend_hash_index_find(Z_ARRVAL_PP(parameters[i]), 0, (void **)&x); zend_hash_index_find(Z_ARRVAL_PP(parameters[i]), 1, (void **)&y); if (Z_TYPE_PP(x) != IS_LONG) convert_to_long(*x); if (Z_TYPE_PP(y) != IS_LONG) convert_to_long(*y); points[i].x = Z_LVAL_PP(x); points[i].y = Z_LVAL_PP(y); points_total++; } } } RETVAL_BOOL(PolyBezierTo(dc_obj->hdc, points, points_total)); CLEANUP: efree(points); }
PHP_METHOD(WinGdiPath, frameRectangle) { wingdi_devicecontext_object *dc_obj; wingdi_brush_object *br_obj; wingdi_path_object *path_obj; zval *coords_zval, *br_zval, **tmp; RECT rect_coords; WINGDI_ERROR_HANDLING(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &br_zval, &coords_zval) == FAILURE) return; WINGDI_RESTORE_ERRORS(); path_obj = zend_object_store_get_object(getThis() TSRMLS_CC); dc_obj = zend_object_store_get_object(path_obj->device_context TSRMLS_CC); if (Z_TYPE_P(br_zval) == IS_OBJECT) br_obj = zend_object_store_get_object(br_zval TSRMLS_CC); else { php_error_docref(NULL TSRMLS_CC, E_ERROR, "expected an object for parameter 2, got %s", zend_zval_type_name(br_zval)); return; } // Is this the best way to do this? zend_hash_index_find(Z_ARRVAL_P(coords_zval), 0, (void **)&tmp); rect_coords.top = Z_LVAL_PP(tmp); zend_hash_index_find(Z_ARRVAL_P(coords_zval), 1, (void **)&tmp); rect_coords.left = Z_LVAL_PP(tmp); zend_hash_index_find(Z_ARRVAL_P(coords_zval), 2, (void **)&tmp); rect_coords.bottom = Z_LVAL_PP(tmp); zend_hash_index_find(Z_ARRVAL_P(coords_zval), 3, (void **)&tmp); rect_coords.right = Z_LVAL_PP(tmp); RETURN_BOOL(FrameRect(dc_obj->hdc, &rect_coords, br_obj->brush_handle)); }
/** * Produces an string representation of a variable * * @param mixed $variable * @return string */ PHP_METHOD(Phalcon_Debug, _getVarDump){ zval *variable, *class_name, *dumped_object; zval *array_dump = NULL, *dump = NULL; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &variable); if (PHALCON_IS_SCALAR(variable)) { /** * Boolean variables are represented as 'true'/'false' */ if (Z_TYPE_P(variable) == IS_BOOL) { if (zend_is_true(variable)) { RETURN_MM_STRING("true", 1); } else { RETURN_MM_STRING("false", 1); } } /** * String variables are escaped to avoid XSS injections */ if (Z_TYPE_P(variable) == IS_STRING) { phalcon_call_method_p1(return_value, this_ptr, "_escapestring", variable); RETURN_MM(); } /** * Other scalar variables are just converted to strings */ RETURN_CCTOR(variable); } /** * If the variable is an object print its class name */ if (Z_TYPE_P(variable) == IS_OBJECT) { PHALCON_INIT_VAR(class_name); phalcon_get_class(class_name, variable, 0 TSRMLS_CC); /** * Try to check for a 'dump' method, this surely produces a better printable * representation */ if (phalcon_method_exists_ex(variable, SS("dump") TSRMLS_CC) == SUCCESS) { PHALCON_INIT_VAR(dumped_object); phalcon_call_method(dumped_object, variable, "dump"); /** * dump() must return an array, generate a recursive representation using * getArrayDump */ PHALCON_INIT_VAR(array_dump); phalcon_call_method_p1(array_dump, this_ptr, "_getarraydump", dumped_object); PHALCON_INIT_VAR(dump); PHALCON_CONCAT_SVSVS(dump, "Object(", class_name, ": ", array_dump, ")"); } else { /** * If dump() is not available just print the class name */ PHALCON_INIT_NVAR(dump); PHALCON_CONCAT_SVS(dump, "Object(", class_name, ")</span>"); } RETURN_CTOR(dump); } /** * Recursively process the array and enclose it in Array() */ if (Z_TYPE_P(variable) == IS_ARRAY) { PHALCON_INIT_NVAR(array_dump); phalcon_call_method_p1(array_dump, this_ptr, "_getarraydump", variable); PHALCON_CONCAT_SVS(return_value, "Array(", array_dump, ")"); RETURN_MM(); } /** * Null variables are represented as 'null' * Other types are represented by its type */ RETURN_MM_STRING(zend_zval_type_name(variable), 1); }
PHP_METHOD(WinGdiPath, line) { wingdi_devicecontext_object *dc_obj; wingdi_path_object *path_obj = zend_object_store_get_object(getThis() TSRMLS_CC); POINT *points = NULL; DWORD *point_counts = NULL; zval ***parameters, **x, **y, **current_elem; HashTable *current_param; HashPointer p; int param_count = 0, total_points = 0, // The amount of POINTs in points i; WINGDI_ERROR_HANDLING(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "+", ¶meters, ¶m_count) == FAILURE) return; WINGDI_RESTORE_ERRORS(); for (i = 0; i < param_count; i++) { // All parameters should be arrays if (Z_TYPE_PP(parameters[i]) == IS_ARRAY) { // Add room for new DWORD point_counts = erealloc(point_counts, (i + 1) * sizeof(DWORD)); // Initialise number of points for current array point_counts[i] = 0; // Less typing current_param = Z_ARRVAL_PP(parameters[i]); // Loop over all elements in current array parameter for (zend_hash_internal_pointer_reset(current_param); zend_hash_has_more_elements(current_param) == SUCCESS; zend_hash_move_forward(current_param)) { // Add room for new POINT points = erealloc(points, (total_points + 1) * sizeof(POINT)); // We want the hash pointer so we know what index we're at currently zend_hash_get_pointer(current_param, &p); // Pull the current data from hashtable zend_hash_get_current_data(current_param, (void **)¤t_elem); // Sanity checks: // 1) An array // 2) 2 elements if (Z_TYPE_PP(current_elem) != IS_ARRAY) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "expected point-array for parameter %d, index %d, got %s", i + 1, p.h, zend_zval_type_name(*current_elem)); goto CLEANUP; } if (zend_hash_num_elements(Z_ARRVAL_PP(current_elem)) != 2) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "expected point-array for parameter %d index %d to have exactly 2 elements, %d given", i + 1, p.h, zend_hash_num_elements(Z_ARRVAL_PP(current_elem))); goto CLEANUP; } // Grab x and y coord and convert to long if needed zend_hash_index_find(Z_ARRVAL_PP(current_elem), 0, (void **)&x); zend_hash_index_find(Z_ARRVAL_PP(current_elem), 1, (void **)&y); if (Z_TYPE_PP(x) != IS_LONG) convert_to_long(*x); if (Z_TYPE_PP(y) != IS_LONG) convert_to_long(*y); // Store points[total_points].x = Z_LVAL_PP(x); points[total_points].y = Z_LVAL_PP(y); total_points++; point_counts[i]++; } } else { php_error_docref(NULL TSRMLS_CC, E_ERROR, "expected array for parameter %d, got %s", i + 1, zend_zval_type_name(*(parameters[i]))); goto CLEANUP; } } dc_obj = zend_object_store_get_object(path_obj->device_context TSRMLS_CC); RETURN_BOOL(PolyPolyline(dc_obj->hdc, points, point_counts, total_points)); CLEANUP: efree(points); efree(point_counts); }
// A carbon copy of the Win\Gdi\Region\Polygon implementation // without some parameter checks (no poly-fill-mode given) PHP_METHOD(WinGdiRegionPolygon, polygon) { wingdi_devicecontext_object *dc_obj; wingdi_path_object *path_obj; HashPointer p; // We use this to determine what index we are at in the array POINT *points = NULL; zval ***parameters, **current_elem, **x, **y; INT *point_counts = NULL; // Number of POINTs in corresponding points array int ints_in_count = 0, // Number of ints in point_counts param_count, i, t = 0; // Total number of POINTs WINGDI_ERROR_HANDLING(); // Will throw an exception if no parameters are given if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "+", ¶meters, ¶m_count) == FAILURE) return; WINGDI_RESTORE_ERRORS(); point_counts = emalloc(param_count * sizeof(INT)); for (i = 0; i < param_count; i++) { if (Z_TYPE_PP(parameters[i]) == IS_ARRAY) { point_counts[ints_in_count] = 0; for (zend_hash_internal_pointer_reset(Z_ARRVAL_PP(parameters[i])); zend_hash_has_more_elements(Z_ARRVAL_PP(parameters[i])) == SUCCESS; zend_hash_move_forward(Z_ARRVAL_PP(parameters[i]))) { points = erealloc(points, t * sizeof(POINT) + sizeof(POINT)); zend_hash_get_pointer(Z_ARRVAL_PP(parameters[i]), &p); zend_hash_get_current_data(Z_ARRVAL_PP(parameters[i]), (void **)¤t_elem); if (Z_TYPE_PP(current_elem) != IS_ARRAY) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "expected array in array for parameter %d, got %s", i + 1, zend_zval_type_name(*current_elem)); goto CLEANUP; } else { if (zend_hash_num_elements(Z_ARRVAL_PP(current_elem)) != 2) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "expected point-array at index %d for parameter %d to have 2 elements, %d given", p.h, i + 1, zend_hash_num_elements(Z_ARRVAL_PP(current_elem))); goto CLEANUP; } else { zend_hash_index_find(Z_ARRVAL_PP(current_elem), 0, (void **)&x); zend_hash_index_find(Z_ARRVAL_PP(current_elem), 1, (void **)&y); if (Z_TYPE_PP(x) != IS_LONG) convert_to_long(*x); if (Z_TYPE_PP(y) != IS_LONG) convert_to_long(*y); points[t].x = Z_LVAL_PP(x); points[t].y = Z_LVAL_PP(y); t++; point_counts[ints_in_count]++; } } } ints_in_count++; } else { php_error_docref(NULL TSRMLS_CC, E_ERROR, "expecting array for parameter %d, got %s", zend_zval_type_name(*(parameters[i]))); goto CLEANUP; } } path_obj = zend_object_store_get_object(getThis() TSRMLS_CC); dc_obj = zend_object_store_get_object(path_obj->device_context TSRMLS_CC); RETURN_BOOL(PolyPolygon(dc_obj->hdc, points, point_counts, ints_in_count)); CLEANUP: efree(parameters); efree(points); efree(point_counts); }