Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #7 from mgdm/mesh-patterns

Add support for mesh patterns
  • Loading branch information...
commit 1bc059c42683ee270e6c50d313cc5c70ba0ee2f2 2 parents 3e7bbe0 + 79e2be6
@auroraeosrose auroraeosrose authored
Showing with 517 additions and 14 deletions.
  1. +78 −1 cairo.c
  2. +424 −13 cairo_pattern.c
  3. +15 −0 php_cairo.h
View
79 cairo.c
@@ -328,6 +328,68 @@ ZEND_BEGIN_ARG_INFO(cairo_radialgradient_args, ZEND_SEND_BY_VAL)
ZEND_ARG_OBJ_INFO(0, pattern, CairoRadialGradient, 0)
ZEND_END_ARG_INFO()
+ZEND_BEGIN_ARG_INFO(cairo_mesh_pattern_args, ZEND_SEND_BY_VAL)
+ ZEND_ARG_OBJ_INFO(0, pattern, CairoMeshPattern, 0)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO(cairo_mesh_pattern_get_path_args, ZEND_SEND_BY_VAL)
+ ZEND_ARG_OBJ_INFO(0, pattern, CairoMeshPattern, 0)
+ ZEND_ARG_INFO(0, patch)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO(cairo_mesh_pattern_get_control_point_args, ZEND_SEND_BY_VAL)
+ ZEND_ARG_OBJ_INFO(0, pattern, CairoMeshPattern, 0)
+ ZEND_ARG_INFO(0, patch)
+ ZEND_ARG_INFO(0, corner)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO(cairo_mesh_pattern_get_corner_color_rgba_args, ZEND_SEND_BY_VAL)
+ ZEND_ARG_OBJ_INFO(0, pattern, CairoMeshPattern, 0)
+ ZEND_ARG_INFO(0, patch)
+ ZEND_ARG_INFO(0, index)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO(cairo_mesh_pattern_translate_args, ZEND_SEND_BY_VAL)
+ ZEND_ARG_OBJ_INFO(0, pattern, CairoMeshPattern, 0)
+ ZEND_ARG_INFO(0, x)
+ ZEND_ARG_INFO(0, y)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO(cairo_mesh_pattern_curve_to_args, ZEND_SEND_BY_VAL)
+ ZEND_ARG_OBJ_INFO(0, pattern, CairoMeshPattern, 0)
+ ZEND_ARG_INFO(0, x1)
+ ZEND_ARG_INFO(0, y1)
+ ZEND_ARG_INFO(0, x2)
+ ZEND_ARG_INFO(0, y2)
+ ZEND_ARG_INFO(0, x3)
+ ZEND_ARG_INFO(0, y3)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO(cairo_mesh_pattern_set_control_point_args, ZEND_SEND_BY_VAL)
+ ZEND_ARG_OBJ_INFO(0, pattern, CairoMeshPattern, 0)
+ ZEND_ARG_INFO(0, point)
+ ZEND_ARG_INFO(0, x)
+ ZEND_ARG_INFO(0, y)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO(cairo_mesh_pattern_set_corner_color_rgb_args, ZEND_SEND_BY_VAL)
+ ZEND_ARG_OBJ_INFO(0, pattern, CairoMeshPattern, 0)
+ ZEND_ARG_INFO(0, point)
+ ZEND_ARG_INFO(0, r)
+ ZEND_ARG_INFO(0, g)
+ ZEND_ARG_INFO(0, b)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO(cairo_mesh_pattern_set_corner_color_rgba_args, ZEND_SEND_BY_VAL)
+ ZEND_ARG_OBJ_INFO(0, pattern, CairoMeshPattern, 0)
+ ZEND_ARG_INFO(0, point)
+ ZEND_ARG_INFO(0, r)
+ ZEND_ARG_INFO(0, g)
+ ZEND_ARG_INFO(0, b)
+ ZEND_ARG_INFO(0, a)
+ZEND_END_ARG_INFO()
+
+
/* Matrix Functions */
ZEND_BEGIN_ARG_INFO_EX(cairo_matrix_init_args, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0)
ZEND_ARG_INFO(0, yx)
@@ -439,7 +501,7 @@ ZEND_BEGIN_ARG_INFO(cairo_scaled_font_glyph_extents_args, ZEND_SEND_BY_VAL)
ZEND_ARG_OBJ_INFO(0, scaledfont, CairoScaledFont, 0)
ZEND_ARG_INFO(0, glyphs)
ZEND_END_ARG_INFO()
-
+
#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 8, 0)
/* Toy Font Face functions */
ZEND_BEGIN_ARG_INFO_EX(cairo_toy_font_face_create_args, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1)
@@ -966,6 +1028,21 @@ static const zend_function_entry cairo_functions[] = {
PHP_FE(cairo_pattern_add_color_stop_rgba, cairo_pattern_add_color_stop_rgba_args)
PHP_FE(cairo_pattern_create_linear, cairo_pattern_create_linear_args)
PHP_FE(cairo_pattern_create_radial, cairo_pattern_create_radial_args)
+#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 12, 0)
+ PHP_FE(cairo_pattern_create_mesh, NULL)
+ PHP_FE(cairo_mesh_pattern_begin_patch, cairo_mesh_pattern_args)
+ PHP_FE(cairo_mesh_pattern_end_patch, cairo_mesh_pattern_args)
+ PHP_FE(cairo_mesh_pattern_move_to, cairo_mesh_pattern_translate_args)
+ PHP_FE(cairo_mesh_pattern_line_to, cairo_mesh_pattern_translate_args)
+ PHP_FE(cairo_mesh_pattern_curve_to, cairo_mesh_pattern_curve_to_args)
+ PHP_FE(cairo_mesh_pattern_set_control_point, cairo_mesh_pattern_set_control_point_args)
+ PHP_FE(cairo_mesh_pattern_set_corner_color_rgb, cairo_mesh_pattern_set_corner_color_rgb_args)
+ PHP_FE(cairo_mesh_pattern_set_corner_color_rgba, cairo_mesh_pattern_set_corner_color_rgba_args)
+ PHP_FE(cairo_mesh_pattern_get_patch_count, cairo_mesh_pattern_args)
+ PHP_FE(cairo_mesh_pattern_get_path, cairo_mesh_pattern_get_path_args)
+ PHP_FE(cairo_mesh_pattern_get_control_point, cairo_mesh_pattern_get_control_point_args)
+ PHP_FE(cairo_mesh_pattern_get_corner_color_rgba, cairo_mesh_pattern_get_corner_color_rgba_args)
+#endif
#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 4, 0)
PHP_FE(cairo_pattern_get_color_stop_count, cairo_gradientpattern_args)
PHP_FE(cairo_pattern_get_surface, cairo_surfacepattern_args)
View
437 cairo_pattern.c
@@ -29,6 +29,7 @@ zend_class_entry *cairo_ce_cairopattern;
zend_class_entry *cairo_ce_cairogradientpattern;
zend_class_entry *cairo_ce_cairosolidpattern;
zend_class_entry *cairo_ce_cairosurfacepattern;
+zend_class_entry *cairo_ce_cairomeshpattern;
zend_class_entry *cairo_ce_cairolineargradient;
zend_class_entry *cairo_ce_cairoradialgradient;
zend_class_entry *cairo_ce_cairopatterntype;
@@ -96,6 +97,55 @@ ZEND_BEGIN_ARG_INFO(CairoPattern_setMatrix_args, ZEND_SEND_BY_VAL)
ZEND_ARG_INFO(0, matrix)
ZEND_END_ARG_INFO()
+ZEND_BEGIN_ARG_INFO(CairoMeshPattern_translate_args, ZEND_SEND_BY_VAL)
+ ZEND_ARG_INFO(0, x)
+ ZEND_ARG_INFO(0, y)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO(CairoMeshPattern_curveTo_args, ZEND_SEND_BY_VAL)
+ ZEND_ARG_INFO(0, x1)
+ ZEND_ARG_INFO(0, y1)
+ ZEND_ARG_INFO(0, x2)
+ ZEND_ARG_INFO(0, y2)
+ ZEND_ARG_INFO(0, x3)
+ ZEND_ARG_INFO(0, y3)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO(CairoMeshPattern_setControlPoint_args, ZEND_SEND_BY_VAL)
+ ZEND_ARG_INFO(0, point)
+ ZEND_ARG_INFO(0, x)
+ ZEND_ARG_INFO(0, y)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO(CairoMeshPattern_setCornerColorRGB_args, ZEND_SEND_BY_VAL)
+ ZEND_ARG_INFO(0, point)
+ ZEND_ARG_INFO(0, r)
+ ZEND_ARG_INFO(0, g)
+ ZEND_ARG_INFO(0, b)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO(CairoMeshPattern_setCornerColorRGBA_args, ZEND_SEND_BY_VAL)
+ ZEND_ARG_INFO(0, point)
+ ZEND_ARG_INFO(0, r)
+ ZEND_ARG_INFO(0, g)
+ ZEND_ARG_INFO(0, b)
+ ZEND_ARG_INFO(0, a)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO(CairoMeshPattern_getPath_args, ZEND_SEND_BY_VAL)
+ ZEND_ARG_INFO(0, patch)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO(CairoMeshPattern_getControlPoint_args, ZEND_SEND_BY_VAL)
+ ZEND_ARG_INFO(0, patch)
+ ZEND_ARG_INFO(0, point)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO(CairoMeshPattern_getCornerColorRgba_args, ZEND_SEND_BY_VAL)
+ ZEND_ARG_INFO(0, patch)
+ ZEND_ARG_INFO(0, corner)
+ZEND_END_ARG_INFO()
+
/* {{{ proto void contruct()
CairoPattern CANNOT be extended in userspace, this will throw an exception on use */
PHP_METHOD(CairoPattern, __construct)
@@ -173,7 +223,7 @@ PHP_FUNCTION(cairo_pattern_get_matrix)
Z_SET_REFCOUNT_P(return_value, 1);
/* Otherwise we spawn a new object */
} else {
- object_init_ex(return_value, cairo_ce_cairomatrix);
+ object_init_ex(return_value, cairo_ce_cairomatrix);
}
cairo_pattern_get_matrix(pattern_object->pattern, &matrix);
@@ -322,7 +372,7 @@ PHP_FUNCTION(cairo_pattern_get_color_stop_count)
pattern_object = (cairo_pattern_object *) cairo_pattern_object_get(pattern_zval TSRMLS_CC);
PHP_CAIRO_ERROR(cairo_pattern_status(pattern_object->pattern));
cairo_pattern_get_color_stop_count(pattern_object->pattern, &count);
-
+
RETURN_LONG(count);
}
/* }}} */
@@ -361,10 +411,10 @@ PHP_METHOD(CairoGradientPattern, setExtend)
return;
}
PHP_CAIRO_RESTORE_ERRORS(TRUE)
-
+
pattern_object = (cairo_pattern_object *)cairo_pattern_object_get(getThis() TSRMLS_CC);
cairo_pattern_set_extend(pattern_object->pattern, extend);
- PHP_CAIRO_ERROR(cairo_pattern_status(pattern_object->pattern));
+ PHP_CAIRO_ERROR(cairo_pattern_status(pattern_object->pattern));
}
/* }}} */
@@ -559,7 +609,7 @@ PHP_FUNCTION(cairo_pattern_get_surface)
pattern_object = (cairo_pattern_object *)cairo_pattern_object_get(pattern_zval TSRMLS_CC);
PHP_CAIRO_ERROR(cairo_pattern_get_surface(pattern_object->pattern, &surface));
-
+
/* If we have a surface object stored, grab that zval to use */
if(pattern_object->surface) {
zval_dtor(return_value);
@@ -614,7 +664,7 @@ PHP_FUNCTION(cairo_pattern_set_filter)
return;
}
PHP_CAIRO_RESTORE_ERRORS(FALSE)
-
+
pattern_object = (cairo_pattern_object *)cairo_pattern_object_get(pattern_zval TSRMLS_CC);
cairo_pattern_set_filter(pattern_object->pattern, filter);
PHP_CAIRO_ERROR(cairo_pattern_status(pattern_object->pattern));
@@ -673,10 +723,10 @@ PHP_METHOD(CairoSurfacePattern, setExtend)
return;
}
PHP_CAIRO_RESTORE_ERRORS(TRUE)
-
+
pattern_object = (cairo_pattern_object *)cairo_pattern_object_get(getThis() TSRMLS_CC);
cairo_pattern_set_extend(pattern_object->pattern, extend);
- PHP_CAIRO_ERROR(cairo_pattern_status(pattern_object->pattern));
+ PHP_CAIRO_ERROR(cairo_pattern_status(pattern_object->pattern));
}
/* }}} */
@@ -695,10 +745,10 @@ PHP_FUNCTION(cairo_pattern_set_extend)
return;
}
}
-
+
pattern_object = (cairo_pattern_object *)cairo_pattern_object_get(pattern_zval TSRMLS_CC);
cairo_pattern_set_extend(pattern_object->pattern, extend);
- PHP_CAIRO_ERROR(cairo_pattern_status(pattern_object->pattern));
+ PHP_CAIRO_ERROR(cairo_pattern_status(pattern_object->pattern));
}
/* }}} */
@@ -774,7 +824,7 @@ PHP_FUNCTION(cairo_pattern_get_linear_points)
return;
}
PHP_CAIRO_RESTORE_ERRORS(FALSE)
-
+
pattern_object = (cairo_pattern_object *)cairo_pattern_object_get(pattern_zval TSRMLS_CC);
cairo_pattern_get_linear_points(pattern_object->pattern, &x0, &y0, &x1, &y1);
PHP_CAIRO_ERROR(cairo_pattern_status(pattern_object->pattern));
@@ -855,7 +905,7 @@ PHP_FUNCTION(cairo_pattern_get_radial_circles)
return;
}
PHP_CAIRO_RESTORE_ERRORS(FALSE)
-
+
pattern_object = (cairo_pattern_object *)cairo_pattern_object_get(pattern_zval TSRMLS_CC);
cairo_pattern_get_radial_circles(pattern_object->pattern, &x0, &y0, &r0, &x1, &y1, &r1);
PHP_CAIRO_ERROR(cairo_pattern_status(pattern_object->pattern));
@@ -870,6 +920,335 @@ PHP_FUNCTION(cairo_pattern_get_radial_circles)
}
#endif
+#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 12, 0)
+/* {{{ proto CairoMeshPattern cairo_pattern_create_mesh(void)
+ Create a new CairoMeshPattern */
+PHP_FUNCTION(cairo_pattern_create_mesh)
+{
+ cairo_pattern_object *pattern_object;
+
+ PHP_CAIRO_ERROR_HANDLING(TRUE)
+ if (zend_parse_parameters_none() == FAILURE) {
+ PHP_CAIRO_RESTORE_ERRORS(TRUE)
+ return;
+ }
+ PHP_CAIRO_RESTORE_ERRORS(TRUE)
+
+ object_init_ex(return_value, cairo_ce_cairomeshpattern);
+ pattern_object = (cairo_pattern_object *)zend_object_store_get_object(return_value TSRMLS_CC);
+
+ pattern_object->pattern = cairo_pattern_create_mesh();
+ php_cairo_trigger_error(cairo_pattern_status(pattern_object->pattern) TSRMLS_CC);
+}
+
+/* {{{ proto void construct()
+ Create a new CairoMeshPattern */
+PHP_METHOD(CairoMeshPattern, __construct)
+{
+ cairo_pattern_object *pattern_object;
+
+ PHP_CAIRO_ERROR_HANDLING(TRUE)
+ if (zend_parse_parameters_none() == FAILURE) {
+ PHP_CAIRO_RESTORE_ERRORS(TRUE)
+ return;
+ }
+ PHP_CAIRO_RESTORE_ERRORS(TRUE)
+
+ pattern_object = (cairo_pattern_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
+ pattern_object->pattern = cairo_pattern_create_mesh();
+ php_cairo_throw_exception(cairo_pattern_status(pattern_object->pattern) TSRMLS_CC);
+}
+/* }}} */
+
+/* {{{ proto void cairo_mesh_pattern_begin_patch(CairoMeshPattern object)
+ proto void CairoMeshPattern->beginPatch()
+ Begin a patch in a mesh pattern. */
+PHP_FUNCTION(cairo_mesh_pattern_begin_patch)
+{
+ zval *pattern_zval;
+ cairo_pattern_object *pattern_object;
+
+ PHP_CAIRO_ERROR_HANDLING(TRUE)
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &pattern_zval, cairo_ce_cairopattern) == FAILURE) {
+ PHP_CAIRO_RESTORE_ERRORS(TRUE)
+ return;
+ }
+ PHP_CAIRO_RESTORE_ERRORS(TRUE)
+
+ pattern_object = (cairo_pattern_object *)zend_object_store_get_object(pattern_zval TSRMLS_CC);
+ cairo_mesh_pattern_begin_patch(pattern_object->pattern);
+ php_cairo_throw_exception(cairo_pattern_status(pattern_object->pattern) TSRMLS_CC);
+}
+/* }}} */
+
+/* {{{ proto void cairo_mesh_pattern_end_patch(CairoMeshPattern object)
+ proto void CairoMeshPattern->endPatch()
+ End a patch in a mesh pattern. */
+PHP_FUNCTION(cairo_mesh_pattern_end_patch)
+{
+ zval *pattern_zval;
+ cairo_pattern_object *pattern_object;
+
+ PHP_CAIRO_ERROR_HANDLING(TRUE)
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &pattern_zval, cairo_ce_cairopattern) == FAILURE) {
+ PHP_CAIRO_RESTORE_ERRORS(TRUE)
+ return;
+ }
+ PHP_CAIRO_RESTORE_ERRORS(TRUE)
+
+ pattern_object = (cairo_pattern_object *)zend_object_store_get_object(pattern_zval TSRMLS_CC);
+ cairo_mesh_pattern_end_patch(pattern_object->pattern);
+ php_cairo_throw_exception(cairo_pattern_status(pattern_object->pattern) TSRMLS_CC);
+}
+/* }}} */
+
+/* {{{ proto void cairo_mesh_pattern_move_to(CairoMeshPattern object, float x, float y)
+ proto void CairoMeshPattern->moveTo(float x, float y)
+ Begin a new sub-path. After this call the current point will be (x, y) */
+PHP_FUNCTION(cairo_mesh_pattern_move_to)
+{
+ zval *pattern_zval = NULL;
+ double x = 0.0, y = 0.0;
+ cairo_pattern_object *pattern_object;
+
+ PHP_CAIRO_ERROR_HANDLING(FALSE)
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Odd", &pattern_zval, cairo_ce_cairopattern, &x, &y) == FAILURE) {
+ PHP_CAIRO_RESTORE_ERRORS(FALSE)
+ return;
+ }
+ PHP_CAIRO_RESTORE_ERRORS(FALSE)
+
+ pattern_object = (cairo_pattern_object *)cairo_pattern_object_get(pattern_zval TSRMLS_CC);
+ cairo_mesh_pattern_move_to(pattern_object->pattern, x, y);
+ PHP_CAIRO_ERROR(cairo_pattern_status(pattern_object->pattern));
+}
+/* }}} */
+
+/* {{{ proto void cairo_mesh_pattern_line_to(CairoMeshPattern object, float x, float y)
+ proto void CairoMeshPattern->lineTo(float x, float y)
+ Begin a new sub-path. After this call the current point will be (x, y) */
+PHP_FUNCTION(cairo_mesh_pattern_line_to)
+{
+ zval *pattern_zval = NULL;
+ double x = 0.0, y = 0.0;
+ cairo_pattern_object *pattern_object;
+
+ PHP_CAIRO_ERROR_HANDLING(FALSE)
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Odd", &pattern_zval, cairo_ce_cairopattern, &x, &y) == FAILURE) {
+ PHP_CAIRO_RESTORE_ERRORS(FALSE)
+ return;
+ }
+ PHP_CAIRO_RESTORE_ERRORS(FALSE)
+
+ pattern_object = (cairo_pattern_object *)cairo_pattern_object_get(pattern_zval TSRMLS_CC);
+ cairo_mesh_pattern_line_to(pattern_object->pattern, x, y);
+ PHP_CAIRO_ERROR(cairo_pattern_status(pattern_object->pattern));
+}
+/* }}} */
+
+/* {{{ proto void cairo_mesh_pattern_curve_to(CairoMeshPattern object, float x1, float y1, float x2, float y2, float x3, float y3)
+ proto void CairoMeshPattern->curveTo(float x1, float y1, float x2, float y2, float x3, float y3)
+ Adds a cubic Bézier spline to the current patch */
+PHP_FUNCTION(cairo_mesh_pattern_curve_to)
+{
+ zval *pattern_zval = NULL;
+ double x1 = 0.0, y1 = 0.0, x2 = 0.0, y2 = 0.0, x3 = 0.0, y3 = 0.0;
+ cairo_pattern_object *pattern_object;
+
+ PHP_CAIRO_ERROR_HANDLING(FALSE)
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Odddddd",
+ &pattern_zval, cairo_ce_cairopattern, &x1, &y1, &x2, &y2, &x3, &y3) == FAILURE) {
+ PHP_CAIRO_RESTORE_ERRORS(FALSE)
+ return;
+ }
+ PHP_CAIRO_RESTORE_ERRORS(FALSE)
+
+ pattern_object = (cairo_pattern_object *)cairo_pattern_object_get(pattern_zval TSRMLS_CC);
+ cairo_mesh_pattern_curve_to(pattern_object->pattern, x1, y1, x2, y2, x3, y3);
+ PHP_CAIRO_ERROR(cairo_pattern_status(pattern_object->pattern));
+}
+/* }}} */
+
+/* {{{ proto void cairo_mesh_pattern_set_control_point(CairoMeshPattern object, int point, float x, float y)
+ proto void CairoMeshPattern->setControlPoint(int point, float x, float y)
+ Set an internal control point of the current patch. */
+PHP_FUNCTION(cairo_mesh_pattern_set_control_point)
+{
+ zval *pattern_zval = NULL;
+ double x = 0.0, y = 0.0;
+ long point = 0;
+ cairo_pattern_object *pattern_object;
+
+ PHP_CAIRO_ERROR_HANDLING(FALSE)
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oldd",
+ &pattern_zval, cairo_ce_cairopattern, &point, &x, &y) == FAILURE) {
+ PHP_CAIRO_RESTORE_ERRORS(FALSE)
+ return;
+ }
+ PHP_CAIRO_RESTORE_ERRORS(FALSE)
+
+ pattern_object = (cairo_pattern_object *)cairo_pattern_object_get(pattern_zval TSRMLS_CC);
+ cairo_mesh_pattern_set_control_point(pattern_object->pattern, point, x, y);
+ PHP_CAIRO_ERROR(cairo_pattern_status(pattern_object->pattern));
+}
+/* }}} */
+
+/* {{{ proto void cairo_mesh_pattern_set_corner_color_rgb(CairoMeshPattern object, int point, float r, float g, float b)
+ proto void CairoMeshPattern->setControlPoint(int point, float r, float g, float b)
+ Sets the color of a corner of the current patch in a mesh pattern. */
+PHP_FUNCTION(cairo_mesh_pattern_set_corner_color_rgb)
+{
+ zval *pattern_zval = NULL;
+ double r = 0.0, g = 0.0, b = 0.0;
+ long point = 0;
+ cairo_pattern_object *pattern_object;
+
+ PHP_CAIRO_ERROR_HANDLING(FALSE)
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Olddd",
+ &pattern_zval, cairo_ce_cairopattern, &point, &r, &g, &b) == FAILURE) {
+ PHP_CAIRO_RESTORE_ERRORS(FALSE)
+ return;
+ }
+ PHP_CAIRO_RESTORE_ERRORS(FALSE)
+
+ pattern_object = (cairo_pattern_object *)cairo_pattern_object_get(pattern_zval TSRMLS_CC);
+ cairo_mesh_pattern_set_corner_color_rgb(pattern_object->pattern, point, r, g, b);
+ PHP_CAIRO_ERROR(cairo_pattern_status(pattern_object->pattern));
+}
+/* }}} */
+
+/* {{{ proto void cairo_mesh_pattern_set_corner_color_rgba(CairoMeshPattern object, int point, float r, float g, float b, float a)
+ proto void CairoMeshPattern->setControlPoint(int point, float r, float g, float b, float a)
+ Sets the color of a corner of the current patch in a mesh pattern. */
+PHP_FUNCTION(cairo_mesh_pattern_set_corner_color_rgba)
+{
+ zval *pattern_zval = NULL;
+ double r = 0.0, g = 0.0, b = 0.0, a = 0.0;
+ long point = 0;
+ cairo_pattern_object *pattern_object;
+
+ PHP_CAIRO_ERROR_HANDLING(FALSE)
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oldddd",
+ &pattern_zval, cairo_ce_cairopattern, &point, &r, &g, &b, &a) == FAILURE) {
+ PHP_CAIRO_RESTORE_ERRORS(FALSE)
+ return;
+ }
+ PHP_CAIRO_RESTORE_ERRORS(FALSE)
+
+ pattern_object = (cairo_pattern_object *)cairo_pattern_object_get(pattern_zval TSRMLS_CC);
+ cairo_mesh_pattern_set_corner_color_rgba(pattern_object->pattern, point, r, g, b, a);
+ PHP_CAIRO_ERROR(cairo_pattern_status(pattern_object->pattern));
+}
+/* }}} */
+
+/* {{{ proto void cairo_mesh_pattern_get_patch_count(CairoMeshPattern object)
+ proto void CairoMeshPattern->getPatchCount()
+ Gets the number of patches specified in the given mesh pattern. */
+PHP_FUNCTION(cairo_mesh_pattern_get_patch_count)
+{
+ zval *pattern_zval = NULL;
+ cairo_pattern_object *pattern_object;
+ cairo_status_t status;
+ unsigned int count;
+
+ PHP_CAIRO_ERROR_HANDLING(FALSE)
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &pattern_zval, cairo_ce_cairopattern) == FAILURE) {
+ PHP_CAIRO_RESTORE_ERRORS(FALSE)
+ return;
+ }
+ PHP_CAIRO_RESTORE_ERRORS(FALSE)
+
+ pattern_object = (cairo_pattern_object *)cairo_pattern_object_get(pattern_zval TSRMLS_CC);
+ status = cairo_mesh_pattern_get_patch_count(pattern_object->pattern, &count);
+ PHP_CAIRO_ERROR(status);
+
+ RETURN_LONG(count);
+}
+/* }}} */
+
+/* {{{ proto void cairo_mesh_pattern_get_path(CairoMeshPattern object, int patch_num)
+ proto void CairoMeshPattern->getPath(int patchNum)
+ Gets path defining the patch patch_num for a mesh pattern. */
+PHP_FUNCTION(cairo_mesh_pattern_get_path)
+{
+ zval *pattern_zval = NULL;
+ cairo_pattern_object *pattern_object;
+ cairo_path_object *path_object;
+ long patch_num;
+
+ PHP_CAIRO_ERROR_HANDLING(FALSE)
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol", &pattern_zval, cairo_ce_cairopattern, &patch_num) == FAILURE) {
+ PHP_CAIRO_RESTORE_ERRORS(FALSE)
+ return;
+ }
+ PHP_CAIRO_RESTORE_ERRORS(FALSE)
+
+ pattern_object = (cairo_pattern_object *)cairo_pattern_object_get(pattern_zval TSRMLS_CC);
+ object_init_ex(return_value, php_cairo_get_path_ce());
+ path_object = (cairo_path_object *) zend_object_store_get_object(return_value TSRMLS_CC);
+ path_object->path = cairo_mesh_pattern_get_path(pattern_object->pattern, patch_num);
+ PHP_CAIRO_ERROR(path_object->path->status);
+}
+/* }}} */
+
+/* {{{ proto array cairo_mesh_pattern_get_control_point(CairoPattern object, long patch, long point)
+ proto array CairoMeshPattern->getCornerColorRgba(long patch, long point)
+ Gets the control point point_num of patch patch_num for a mesh pattern. */
+PHP_FUNCTION(cairo_mesh_pattern_get_control_point)
+{
+ long patch_num, corner_num;
+ double offset, x, y;
+ zval *pattern_zval = NULL;
+ cairo_pattern_object *pattern_object;
+
+ PHP_CAIRO_ERROR_HANDLING(FALSE)
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oll", &pattern_zval, cairo_ce_cairomeshpattern, &patch_num, &corner_num) == FAILURE) {
+ PHP_CAIRO_RESTORE_ERRORS(FALSE)
+ return;
+ }
+ PHP_CAIRO_RESTORE_ERRORS(FALSE)
+
+ pattern_object = (cairo_pattern_object *) cairo_pattern_object_get(pattern_zval TSRMLS_CC);
+ cairo_mesh_pattern_get_control_point(pattern_object->pattern, patch_num, corner_num, &x, &y);
+ PHP_CAIRO_ERROR(cairo_pattern_status(pattern_object->pattern));
+
+ array_init(return_value);
+ add_assoc_double(return_value, "x", x);
+ add_assoc_double(return_value, "y", y);
+}
+/* }}} */
+
+/* {{{ proto array cairo_mesh_pattern_get_corner_color_rgba(CairoPattern object)
+ proto array CairoMeshPattern->getCornerColorRgba()
+ Gets the color information in corner corner_num of patch patch_num for a mesh pattern. */
+
+PHP_FUNCTION(cairo_mesh_pattern_get_corner_color_rgba)
+{
+ long patch_num, corner_num;
+ double offset, red, green, blue, alpha;
+ zval *pattern_zval = NULL;
+ cairo_pattern_object *pattern_object;
+
+ PHP_CAIRO_ERROR_HANDLING(FALSE)
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oll", &pattern_zval, cairo_ce_cairomeshpattern, &patch_num, &corner_num) == FAILURE) {
+ PHP_CAIRO_RESTORE_ERRORS(FALSE)
+ return;
+ }
+ PHP_CAIRO_RESTORE_ERRORS(FALSE)
+
+ pattern_object = (cairo_pattern_object *) cairo_pattern_object_get(pattern_zval TSRMLS_CC);
+ cairo_mesh_pattern_get_corner_color_rgba(pattern_object->pattern, patch_num, corner_num, &red, &green, &blue, &alpha);
+ PHP_CAIRO_ERROR(cairo_pattern_status(pattern_object->pattern));
+
+ array_init(return_value);
+ add_assoc_double(return_value, "red", red);
+ add_assoc_double(return_value, "green", green);
+ add_assoc_double(return_value, "blue", blue);
+ add_assoc_double(return_value, "alpha", alpha);
+}
+/* }}} */
+#endif
+
/* }}} */
/* {{{ cairo_radialgradient_methods[] */
@@ -882,6 +1261,27 @@ const zend_function_entry cairo_radialgradient_methods[] = {
};
/* }}} */
+#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 12, 0)
+/* {{{ cairo_meshpattern_methods[] */
+const zend_function_entry cairo_meshpattern_methods[] = {
+ PHP_ME(CairoMeshPattern, __construct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
+ PHP_ME_MAPPING(beginPatch, cairo_mesh_pattern_begin_patch, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME_MAPPING(endPatch, cairo_mesh_pattern_end_patch, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME_MAPPING(moveTo, cairo_mesh_pattern_move_to, CairoMeshPattern_translate_args, ZEND_ACC_PUBLIC)
+ PHP_ME_MAPPING(lineTo, cairo_mesh_pattern_line_to, CairoMeshPattern_translate_args, ZEND_ACC_PUBLIC)
+ PHP_ME_MAPPING(curveTo, cairo_mesh_pattern_curve_to, CairoMeshPattern_curveTo_args, ZEND_ACC_PUBLIC)
+ PHP_ME_MAPPING(setControlPoint, cairo_mesh_pattern_set_control_point, CairoMeshPattern_setControlPoint_args, ZEND_ACC_PUBLIC)
+ PHP_ME_MAPPING(setCornerColorRGB, cairo_mesh_pattern_set_corner_color_rgb, CairoMeshPattern_setCornerColorRGB_args, ZEND_ACC_PUBLIC)
+ PHP_ME_MAPPING(setCornerColorRGBA, cairo_mesh_pattern_set_corner_color_rgba, CairoMeshPattern_setCornerColorRGBA_args, ZEND_ACC_PUBLIC)
+ PHP_ME_MAPPING(getPatchCount, cairo_mesh_pattern_get_patch_count, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME_MAPPING(getPath, cairo_mesh_pattern_get_path, CairoMeshPattern_getPath_args, ZEND_ACC_PUBLIC)
+ PHP_ME_MAPPING(getControlPoint, cairo_mesh_pattern_get_control_point, CairoMeshPattern_getControlPoint_args, ZEND_ACC_PUBLIC)
+ PHP_ME_MAPPING(getCornerColorRgba, cairo_mesh_pattern_get_corner_color_rgba, CairoMeshPattern_getCornerColorRgba_args, ZEND_ACC_PUBLIC)
+ {NULL, NULL, NULL}
+};
+/* }}} */
+#endif
+
PHP_CAIRO_API zend_class_entry* php_cairo_get_pattern_ce(cairo_pattern_t *pattern TSRMLS_DC)
{
zend_class_entry *type;
@@ -900,6 +1300,11 @@ PHP_CAIRO_API zend_class_entry* php_cairo_get_pattern_ce(cairo_pattern_t *patter
case CAIRO_PATTERN_TYPE_RADIAL:
type = cairo_ce_cairoradialgradient;
break;
+#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 12, 0)
+ case CAIRO_PATTERN_TYPE_MESH:
+ type = cairo_ce_cairomeshpattern;
+ break;
+#endif
default:
php_error(E_WARNING, "Unsupported Cairo Surface Type");
return NULL;
@@ -954,7 +1359,7 @@ static zend_object_value cairo_pattern_object_new(zend_class_entry *ce TSRMLS_DC
/* {{{ PHP_MINIT_FUNCTION */
PHP_MINIT_FUNCTION(cairo_pattern)
{
- zend_class_entry ce, gradient_ce, solid_ce, surface_ce, linear_ce, radial_ce, pattern_ce, extend_ce, filter_ce;
+ zend_class_entry ce, gradient_ce, solid_ce, surface_ce, linear_ce, radial_ce, pattern_ce, extend_ce, filter_ce, mesh_ce;
INIT_CLASS_ENTRY(ce, "CairoPattern", cairo_pattern_methods);
cairo_ce_cairopattern = zend_register_internal_class(&ce TSRMLS_CC);
@@ -982,6 +1387,12 @@ PHP_MINIT_FUNCTION(cairo_pattern)
cairo_ce_cairoradialgradient = zend_register_internal_class_ex(&radial_ce, cairo_ce_cairogradientpattern, "CairoGradientPattern" TSRMLS_CC);
cairo_ce_cairoradialgradient->create_object = cairo_pattern_object_new;
+#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 12, 0)
+ INIT_CLASS_ENTRY(mesh_ce, "CairoMeshPattern", cairo_meshpattern_methods);
+ cairo_ce_cairomeshpattern = zend_register_internal_class_ex(&mesh_ce, cairo_ce_cairopattern, "CairoPattern" TSRMLS_CC);
+ cairo_ce_cairomeshpattern->create_object = cairo_pattern_object_new;
+#endif
+
INIT_CLASS_ENTRY(pattern_ce, "CairoPatternType", NULL);
cairo_ce_cairopatterntype = zend_register_internal_class(&pattern_ce TSRMLS_CC);
cairo_ce_cairopatterntype->ce_flags |= ZEND_ACC_EXPLICIT_ABSTRACT_CLASS | ZEND_ACC_FINAL_CLASS;
View
15 php_cairo.h
@@ -351,6 +351,21 @@ PHP_FUNCTION(cairo_pattern_get_color_stop_rgba);
#endif
PHP_FUNCTION(cairo_pattern_create_linear);
PHP_FUNCTION(cairo_pattern_create_radial);
+#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 12, 0)
+PHP_FUNCTION(cairo_pattern_create_mesh);
+PHP_FUNCTION(cairo_mesh_pattern_begin_patch);
+PHP_FUNCTION(cairo_mesh_pattern_end_patch);
+PHP_FUNCTION(cairo_mesh_pattern_move_to);
+PHP_FUNCTION(cairo_mesh_pattern_line_to);
+PHP_FUNCTION(cairo_mesh_pattern_curve_to);
+PHP_FUNCTION(cairo_mesh_pattern_set_control_point);
+PHP_FUNCTION(cairo_mesh_pattern_set_corner_color_rgb);
+PHP_FUNCTION(cairo_mesh_pattern_set_corner_color_rgba);
+PHP_FUNCTION(cairo_mesh_pattern_get_patch_count);
+PHP_FUNCTION(cairo_mesh_pattern_get_path);
+PHP_FUNCTION(cairo_mesh_pattern_get_corner_color_rgba);
+PHP_FUNCTION(cairo_mesh_pattern_get_control_point);
+#endif
/* Matrix Functions */
PHP_FUNCTION(cairo_matrix_init);
Please sign in to comment.
Something went wrong with that request. Please try again.