Commit b07cccc8 authored by Johan Dahlin's avatar Johan Dahlin

[cairo] Return the correct pattern type

parent 7086b514
......@@ -74,3 +74,25 @@ static JSFunctionSpec gjs_cairo_linear_gradient_proto_funcs[] = {
// getLinearPoints
{ NULL }
};
JSObject *
gjs_cairo_linear_gradient_from_pattern(JSContext *context,
cairo_pattern_t *pattern)
{
JSObject *object;
g_return_val_if_fail(context != NULL, NULL);
g_return_val_if_fail(pattern != NULL, NULL);
g_return_val_if_fail(cairo_pattern_get_type(pattern) == CAIRO_PATTERN_TYPE_LINEAR, NULL);
object = JS_NewObject(context, &gjs_cairo_linear_gradient_class, NULL, NULL);
if (!object) {
gjs_throw(context, "failed to create linear gradient pattern");
return NULL;
}
gjs_cairo_pattern_construct(context, object, pattern);
return object;
}
......@@ -160,13 +160,22 @@ gjs_cairo_pattern_from_pattern(JSContext *context,
g_return_val_if_fail(context != NULL, NULL);
g_return_val_if_fail(pattern != NULL, NULL);
object = JS_NewObject(context, &gjs_cairo_pattern_class, NULL, NULL);
if (!object) {
gjs_throw(context, "failed to create surface");
return NULL;
switch (cairo_pattern_get_type(pattern)) {
// case CAIRO_PATTERN_TYPE_SOLID:
// return gjs_cairo_solid_pattern_from_pattern(context, pattern);
case CAIRO_PATTERN_TYPE_SURFACE:
return gjs_cairo_surface_pattern_from_pattern(context, pattern);
case CAIRO_PATTERN_TYPE_LINEAR:
return gjs_cairo_linear_gradient_from_pattern(context, pattern);
case CAIRO_PATTERN_TYPE_RADIAL:
return gjs_cairo_radial_gradient_from_pattern(context, pattern);
default:
break;
}
gjs_cairo_pattern_construct(context, object, pattern);
gjs_throw(context, "failed to create pattern, unsupported pattern type %d",
cairo_pattern_get_type(pattern));
return NULL;
return object;
}
......
......@@ -122,18 +122,24 @@ jsval gjs_cairo_linear_gradient_create_proto (JSContext *contex
JSObject *module,
const char *proto_name,
JSObject *parent);
JSObject * gjs_cairo_linear_gradient_from_pattern (JSContext *context,
cairo_pattern_t *pattern);
/* radial gradient */
jsval gjs_cairo_radial_gradient_create_proto(JSContext *context,
jsval gjs_cairo_radial_gradient_create_proto (JSContext *context,
JSObject *module,
const char *proto_name,
JSObject *parent);
JSObject * gjs_cairo_radial_gradient_from_pattern (JSContext *context,
cairo_pattern_t *pattern);
/* surface pattern */
jsval gjs_cairo_surface_pattern_create_proto(JSContext *context,
jsval gjs_cairo_surface_pattern_create_proto (JSContext *context,
JSObject *module,
const char *proto_name,
JSObject *parent);
JSObject * gjs_cairo_surface_pattern_from_pattern (JSContext *context,
cairo_pattern_t *pattern);
#endif /* __CAIRO_PRIVATE_H__ */
......@@ -76,3 +76,25 @@ static JSFunctionSpec gjs_cairo_radial_gradient_proto_funcs[] = {
// getRadialCircles
{ NULL }
};
JSObject *
gjs_cairo_radial_gradient_from_pattern(JSContext *context,
cairo_pattern_t *pattern)
{
JSObject *object;
g_return_val_if_fail(context != NULL, NULL);
g_return_val_if_fail(pattern != NULL, NULL);
g_return_val_if_fail(cairo_pattern_get_type(pattern) == CAIRO_PATTERN_TYPE_RADIAL, NULL);
object = JS_NewObject(context, &gjs_cairo_radial_gradient_class, NULL, NULL);
if (!object) {
gjs_throw(context, "failed to create radial gradient pattern");
return NULL;
}
gjs_cairo_pattern_construct(context, object, pattern);
return object;
}
......@@ -181,3 +181,25 @@ static JSFunctionSpec gjs_cairo_surface_pattern_proto_funcs[] = {
{ "getFilter", getFilter_func, 0, 0 },
{ NULL }
};
JSObject *
gjs_cairo_surface_pattern_from_pattern(JSContext *context,
cairo_pattern_t *pattern)
{
JSObject *object;
g_return_val_if_fail(context != NULL, NULL);
g_return_val_if_fail(pattern != NULL, NULL);
g_return_val_if_fail(cairo_pattern_get_type(pattern) == CAIRO_PATTERN_TYPE_SURFACE, NULL);
object = JS_NewObject(context, &gjs_cairo_surface_pattern_class, NULL, NULL);
if (!object) {
gjs_throw(context, "failed to create linear gradient pattern");
return NULL;
}
gjs_cairo_pattern_construct(context, object, pattern);
return object;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment