[gjs: 33/45] [cairo] Return the correct pattern type
- From: Johan Dahlin <johan src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs: 33/45] [cairo] Return the correct pattern type
- Date: Tue, 2 Mar 2010 18:54:50 +0000 (UTC)
commit b07cccc83d9b801c1036ace7d51338f379595ba6
Author: Johan Dahlin <johan gnome org>
Date: Tue Mar 2 11:49:14 2010 -0300
[cairo] Return the correct pattern type
modules/cairo-linear-gradient.c | 22 ++++++++++++++++++++++
modules/cairo-pattern.c | 19 ++++++++++++++-----
modules/cairo-private.h | 10 ++++++++--
modules/cairo-radial-gradient.c | 22 ++++++++++++++++++++++
modules/cairo-surface-pattern.c | 22 ++++++++++++++++++++++
5 files changed, 88 insertions(+), 7 deletions(-)
---
diff --git a/modules/cairo-linear-gradient.c b/modules/cairo-linear-gradient.c
index 6b3271f..3595185 100644
--- a/modules/cairo-linear-gradient.c
+++ b/modules/cairo-linear-gradient.c
@@ -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;
+}
+
diff --git a/modules/cairo-pattern.c b/modules/cairo-pattern.c
index 444772b..a3adb52 100644
--- a/modules/cairo-pattern.c
+++ b/modules/cairo-pattern.c
@@ -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;
}
diff --git a/modules/cairo-private.h b/modules/cairo-private.h
index 5371152..d5f3789 100644
--- a/modules/cairo-private.h
+++ b/modules/cairo-private.h
@@ -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__ */
diff --git a/modules/cairo-radial-gradient.c b/modules/cairo-radial-gradient.c
index fdfad23..9a4325e 100644
--- a/modules/cairo-radial-gradient.c
+++ b/modules/cairo-radial-gradient.c
@@ -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;
+}
+
diff --git a/modules/cairo-surface-pattern.c b/modules/cairo-surface-pattern.c
index c679137..f9c9df7 100644
--- a/modules/cairo-surface-pattern.c
+++ b/modules/cairo-surface-pattern.c
@@ -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;
+}
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]