Example #1
0
static SeedValue
seed_cairo_pattern_add_color_stop_rgba (SeedContext ctx,
				       SeedObject function,
				       SeedObject this_object,
				       gsize argument_count,
				       const SeedValue arguments[],
				       SeedException *exception)
{
  gdouble offset, r, g, b, a;
  cairo_pattern_t *pat;
  CHECK_THIS();
  if (argument_count != 5)
    {
      EXPECTED_EXCEPTION("add_color_stop_rgba", "5 arguments");
    }

  pat = seed_object_get_private (this_object);
  offset = seed_value_to_double (ctx, arguments[0], exception);
  r = seed_value_to_double (ctx, arguments[1], exception);
  g = seed_value_to_double (ctx, arguments[2], exception);
  b = seed_value_to_double (ctx, arguments[3], exception);
  a = seed_value_to_double (ctx, arguments[4], exception);

  cairo_pattern_add_color_stop_rgba (pat, offset, r, g, b, a);

  return seed_make_undefined (ctx);
}
Example #2
0
static SeedValue
seed_cairo_matrix_transform_point (SeedContext ctx,
				      SeedObject function,
				      SeedObject this_object,
				      gsize argument_count,
				      const SeedValue arguments[],
				      SeedException *exception)
{
  SeedValue ret[2];
  gdouble x, y;
  cairo_matrix_t m;

  if (argument_count != 3)
    {
      EXPECTED_EXCEPTION("transform_point", "3 arguments");
    }

  if (!seed_value_to_cairo_matrix (ctx, arguments[0], &m, exception))
    {
      seed_make_exception (ctx, exception, "ArgumentError", "transform_point needs an array [xx, yx, xy, yy, x0, y0]");
    }
  x = seed_value_to_double (ctx, arguments[1], exception);
  y = seed_value_to_double (ctx, arguments[2], exception);

  cairo_matrix_transform_point (&m, &x, &y);

  ret[0] = seed_value_from_double (ctx, x, exception);
  ret[1] = seed_value_from_double (ctx, y, exception);

  return seed_make_array (ctx, ret, 2, exception);
}
Example #3
0
static SeedValue
seed_cairo_matrix_scale (SeedContext ctx,
				  SeedObject function,
				  SeedObject this_object,
				  gsize argument_count,
				  const SeedValue arguments[],
				  SeedException *exception)
{
  gdouble x, y;
  cairo_matrix_t m;

  if (argument_count != 3)
    {
      EXPECTED_EXCEPTION("scale", "3 arguments");
    }

  if (!seed_value_to_cairo_matrix (ctx, arguments[0], &m, exception))
    {
      seed_make_exception (ctx, exception, "ArgumentError", "scale needs an array [xx, yx, xy, yy, x0, y0]");
    }
  x = seed_value_to_double (ctx, arguments[1], exception);
  y = seed_value_to_double (ctx, arguments[2], exception);

  cairo_matrix_scale (&m, x, y);

  return seed_value_from_cairo_matrix (ctx, &m, exception);
}
Example #4
0
static gboolean
seed_cairo_surface_set_fallback_resolution(SeedContext ctx,
					   SeedObject this_object,
					   SeedString property_name,
					   SeedValue value,
					   SeedException *exception)
{
  cairo_surface_t *surf;
  gdouble x, y;
  SeedValue jsx, jsy;
  CHECK_THIS_BOOL();

  if (!seed_value_is_object (ctx, value))
    {
      seed_make_exception(ctx, exception, "ArgumentError", "Cairo.Surface.fallback_resolution must be an array [x,y]");
      return FALSE;
    }

  jsx = seed_object_get_property_at_index (ctx, (SeedObject) value, 0, exception);
  jsy = seed_object_get_property_at_index (ctx, (SeedObject) value, 1, exception);

  surf = seed_object_to_cairo_surface (ctx, this_object, exception);
  x = seed_value_to_double (ctx, jsx, exception);
  y = seed_value_to_double (ctx, jsy, exception);

  cairo_surface_set_fallback_resolution (surf, x, y);
  return TRUE;
}
Example #5
0
SeedValue seed_mpfr_sub (SeedContext ctx,
                         SeedObject function,
                         SeedObject this_object,
                         gsize argument_count,
                         const SeedValue args[],
                         SeedException *exception)
{
    mpfr_rnd_t rnd;
    mpfr_ptr rop, op1, op2;
    gdouble dop1, dop2;
    gint ret;
    seed_mpfr_t argt1, argt2;
    /* only want 1 double argument. alternatively, could accept 2,
       add those, and set from the result*/

    CHECK_ARG_COUNT("mpfr.sub", 3);

    rop = seed_object_get_private(this_object);
    rnd = seed_value_to_mpfr_rnd_t(ctx, args[2], exception);

    argt1 = seed_mpfr_arg_type(ctx, args[0], exception);
    argt2 = seed_mpfr_arg_type(ctx, args[1], exception);

    if ( (argt1 & argt2) == SEED_MPFR_MPFR )
    {
        /* both mpfr_t */
        op1 = seed_object_get_private(args[0]);
        op2 = seed_object_get_private(args[1]);
        ret = mpfr_sub(rop, op1, op2, rnd);
    }
    else if ( (argt1 | argt2) == (SEED_MPFR_MPFR | SEED_MPFR_DOUBLE) )
    {
        /* a double and an mpfr_t. Figure out the order */
        if ( argt1 == SEED_MPFR_MPFR )
        {
            op1 = seed_object_get_private(args[0]);
            dop2 = seed_value_to_double(ctx, args[1], exception);
            mpfr_sub_d(rop, op1, dop2, rnd);
        }
        else
        {
            dop1 = seed_value_to_double(ctx, args[0], exception);
            op2 = seed_object_get_private(args[1]);
            mpfr_d_sub(rop, dop1, op2, rnd);
        }
    }
    else if ( (argt1 & argt2) == SEED_MPFR_DOUBLE )
    {
        /* 2 doubles. hopefully doesn't happen */
        dop1 = seed_value_to_double(ctx, args[0], exception);
        dop2 = seed_value_to_double(ctx, args[1], exception);
        ret = mpfr_set_d(rop, dop1 - dop2, rnd);
    }
    else
    {
        TYPE_EXCEPTION("mpfr.sub", "double or mpfr_t");
    }

    return seed_value_from_int(ctx, ret, exception);
}
Example #6
0
SeedValue seed_mpfr_cmp (SeedContext ctx,
                          SeedObject function,
                          SeedObject this_object,
                          gsize argument_count,
                          const SeedValue args[],
                          SeedException *exception)
{
    mpfr_ptr rop, op;
    gdouble dop;
    gint ret;

    CHECK_ARG_COUNT("mpfr.cmp", 1);

    rop = seed_object_get_private(this_object);

    if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
    {
        op = seed_object_get_private(args[0]);
        ret = mpfr_cmp(rop, op);
    }
    else if ( seed_value_is_number(ctx, args[0]))
    {
        dop = seed_value_to_double(ctx, args[0], exception);
        ret = mpfr_cmp_d(rop, dop);
    }
    else
    {
        TYPE_EXCEPTION("mpfr.cmp", "mpfr_t or double");
    }


    return seed_value_from_int(ctx, ret, exception);
}
Example #7
0
static SeedObject
seed_cairo_construct_linear_gradient (SeedContext ctx,
				      SeedObject constructor,
				      size_t argument_count,
				      const SeedValue arguments[],
				      SeedException * exception)
{
  gdouble x0,y0,x1,y1;

  if (argument_count != 4)
    {
      EXPECTED_EXCEPTION("LinearGradient constructor", "4 arguments");
    }

  x0 = seed_value_to_double (ctx, arguments[0], exception);
  y0 = seed_value_to_double (ctx, arguments[1], exception);
  x1 = seed_value_to_double (ctx, arguments[2], exception);
  y1 = seed_value_to_double (ctx, arguments[3], exception);

  return seed_object_from_cairo_pattern (ctx, cairo_pattern_create_linear (x0, y0, x1, y1));
}
Example #8
0
static SeedValue
seed_cairo_matrix_init_translate (SeedContext ctx,
				  SeedObject function,
				  SeedObject this_object,
				  gsize argument_count,
				  const SeedValue arguments[],
				  SeedException *exception)
{
  gdouble x, y;
  cairo_matrix_t m;

  if (argument_count != 2)
    {
      EXPECTED_EXCEPTION("init_translate", "2 arguments");
    }

  x = seed_value_to_double (ctx, arguments[0], exception);
  y = seed_value_to_double (ctx, arguments[1], exception);

  cairo_matrix_init_translate (&m, x, y);

  return seed_value_from_cairo_matrix (ctx, &m, exception);
}
static SeedObject
seed_cairo_construct_pdf_surface (SeedContext ctx,
				    SeedObject constructor,
				    size_t argument_count,
				    const SeedValue arguments[],
				    SeedException * exception)
{
  cairo_surface_t *ret;
  gchar *filename = NULL;
  gdouble width, height;
  if (argument_count != 3)
    {
      EXPECTED_EXCEPTION("PDFSurface", "3 arguments");
    }

  if (!seed_value_is_null (ctx, arguments[0]))
    filename  = seed_value_to_string (ctx, arguments[0], exception);
  width = seed_value_to_double (ctx, arguments[1], exception);
  height = seed_value_to_double (ctx, arguments[2], exception);
  ret = cairo_pdf_surface_create (filename, width, height);

  return seed_object_from_cairo_pdf_surface (ctx, ret);
}
Example #10
0
static SeedValue
seed_cairo_pdf_surface_set_size (SeedContext ctx,
				 SeedObject function,
				 SeedObject this_object,
				 gsize argument_count,
				 const SeedValue arguments[],
				 SeedException *exception)
{
  cairo_surface_t *surf;
  gdouble x, y;

  CHECK_THIS();
  if (argument_count != 2)
    {
      EXPECTED_EXCEPTION("set_size", "2 arguments");
    }
  surf = seed_object_get_private (this_object);
  x = seed_value_to_double (ctx, arguments[0], exception);
  y = seed_value_to_double (ctx, arguments[1], exception);

  cairo_pdf_surface_set_size (surf, x, y);

  return seed_make_undefined (ctx);
}
Example #11
0
static SeedValue
seed_cairo_matrix_init_rotate (SeedContext ctx,
				  SeedObject function,
				  SeedObject this_object,
				  gsize argument_count,
				  const SeedValue arguments[],
				  SeedException *exception)
{
  gdouble angle;
  cairo_matrix_t m;

  if (argument_count != 1)
    {
      EXPECTED_EXCEPTION("init_rotate", "1 arguments");
    }

  angle = seed_value_to_double (ctx, arguments[0], exception);
  cairo_matrix_init_rotate (&m, angle);

  return seed_value_from_cairo_matrix (ctx, &m, exception);
}
Example #12
0
void
js_signal_from_c(TestSimpleFixture* fixture, gconstpointer _data)
{
    TestSharedState* state = (TestSharedState*) _data;

    SeedValue* val = seed_simple_evaluate(
      state->eng->context,
      "Gtk = imports.gi.Gtk;"
      "GObject = imports.gi.GObject;"
      "Gtk.init(null, null);"
      "HelloWindowType = {"
      "    parent: Gtk.Window.type,"
      "    name: \"HelloWindow\","
      "    class_init: function(klass, prototype)"
      "    {"
      "	var HelloSignalDefinition = {name: \"hello\","
      "								 "
      "parameters: [GObject.TYPE_INT,"
      "									"
      "		  GObject.TYPE_STRING],"
      "								 "
      "return_type: GObject.TYPE_DOUBLE};"
      "	hello_signal_id = klass.install_signal(HelloSignalDefinition);"
      "    },"
      "    init: function(instance)"
      "    {"
      "    }};"
      "HelloWindow = new GType(HelloWindowType);"
      "w = new HelloWindow();",
      NULL);

    GObject* obj = seed_value_to_object(state->eng->context, val, NULL);

    g_signal_connect(obj, "hello", G_CALLBACK(hello_cb), NULL);

    val = seed_simple_evaluate(state->eng->context,
                               "g = w.signal.hello.emit(2,'Test')", NULL);

    g_assert(seed_value_to_double(state->eng->context, val, NULL) == 5.12);
}
Example #13
0
gboolean
seed_value_to_cairo_matrix (SeedContext ctx,
			    SeedValue value,
			    cairo_matrix_t *matrix,
			    SeedException *exception)
{
  if (!seed_value_is_object (ctx, value))
    return FALSE;

  matrix->xx = seed_value_to_double (ctx, seed_object_get_property_at_index (ctx, (SeedObject) value, 0, exception), exception);
  matrix->yx = seed_value_to_double (ctx, seed_object_get_property_at_index (ctx, (SeedObject) value, 1, exception), exception);
  matrix->xy = seed_value_to_double (ctx, seed_object_get_property_at_index (ctx, (SeedObject) value, 2, exception), exception);
  matrix->yy = seed_value_to_double (ctx, seed_object_get_property_at_index (ctx, (SeedObject) value, 3, exception), exception);
  matrix->x0 = seed_value_to_double (ctx, seed_object_get_property_at_index (ctx, (SeedObject) value, 4, exception), exception);
  matrix->y0 = seed_value_to_double (ctx, seed_object_get_property_at_index (ctx, (SeedObject) value, 5, exception), exception);

  return TRUE;
}
Example #14
0
static SeedObject
seed_cairo_construct_radial_gradient (SeedContext ctx,
				      SeedObject constructor,
				      size_t argument_count,
				      const SeedValue arguments[],
				      SeedException * exception)
{
  gdouble cx0, cy0, r0, cx1, cy1, r1;

  if (argument_count != 6)
    {
      EXPECTED_EXCEPTION("RadialGradient constructor", "6 arguments");
    }

  cx0 = seed_value_to_double (ctx, arguments[0], exception);
  cy0 = seed_value_to_double (ctx, arguments[1], exception);
  r0 = seed_value_to_double (ctx, arguments[2], exception);
  cx1 = seed_value_to_double (ctx, arguments[3], exception);
  cy1 = seed_value_to_double (ctx, arguments[4], exception);
  r1 = seed_value_to_double (ctx, arguments[5], exception);


  return seed_object_from_cairo_pattern (ctx, cairo_pattern_create_radial (cx0, cy0, r0, cx1, cy1, r1));
}
Example #15
0
static ffi_type *
gtype_to_ffi_type (SeedContext ctx, 
		   SeedValue value,
		   GType otype,
		   GArgument *garg,
		   gpointer *arg,
		   SeedException *exception)
{
  ffi_type *return_type;
  GType type = g_type_fundamental (otype);
  g_assert (type != G_TYPE_INVALID);

  switch (type)
    {
    case G_TYPE_BOOLEAN:
    case G_TYPE_CHAR:
    case G_TYPE_INT:
      return_type = &ffi_type_sint;
      garg->v_int = seed_value_to_int (ctx, value, exception);
      *arg = (gpointer)garg;
      break;
    case G_TYPE_UCHAR:
    case G_TYPE_UINT:
      return_type = &ffi_type_uint;
      garg->v_uint = seed_value_to_uint (ctx, value, exception);
      *arg = (gpointer)garg;
      break;
    case G_TYPE_STRING:
      return_type = &ffi_type_pointer;
      garg->v_pointer = seed_value_to_string (ctx, value, exception);
      *arg = (gpointer)garg;
      break;
    case G_TYPE_OBJECT:
      //    case G_TYPE_BOXED:
    case G_TYPE_POINTER:
      return_type = &ffi_type_pointer;
      garg->v_pointer = seed_pointer_get_pointer (ctx, value);
      *arg = (gpointer)garg;
      break;
    case G_TYPE_FLOAT:
      return_type = &ffi_type_float;
      garg->v_float = seed_value_to_float (ctx, value, exception);
      *arg = (gpointer)garg;
      break;
    case G_TYPE_DOUBLE:
      return_type = &ffi_type_double;
      garg->v_double = seed_value_to_double (ctx, value, exception);
      *arg = (gpointer)garg;
      break;
    case G_TYPE_LONG:
      return_type = &ffi_type_slong;
      garg->v_uint = seed_value_to_uint (ctx, value, exception);
      *arg = (gpointer)garg;
      break;
    case G_TYPE_ULONG:
      return_type = &ffi_type_ulong;
      garg->v_ulong = seed_value_to_ulong (ctx, value, exception);
      *arg = (gpointer)garg;
      break;
    case G_TYPE_INT64:
      return_type = &ffi_type_sint64;
      garg->v_int64 = seed_value_to_int64 (ctx, value, exception);
      *arg = (gpointer)garg;
      break;
    case G_TYPE_UINT64:
      return_type = &ffi_type_uint64;
      garg->v_uint64 = seed_value_to_uint64 (ctx, value, exception);
      *arg = (gpointer)garg;
      break;
    default:
      g_warning ("Unsupported fundamental in type: %s", g_type_name (type));
      return_type = &ffi_type_pointer;
      garg->v_pointer = NULL;
      *arg = (garg->v_pointer);
      break;
    }
  return return_type;
}
Example #16
0
void basic_types(TestSimpleFixture * fixture, gconstpointer _data)
{
	// bool to/from JS equality

	gboolean bool_test_in = TRUE;
	SeedValue *bool_test = seed_value_from_boolean(fixture->context,
												   bool_test_in, NULL);
	gboolean bool_test_out = seed_value_to_boolean(fixture->context,
												   bool_test, NULL);

	g_assert(bool_test_in == bool_test_out);

	// uint to/from JS equality

	guint uint_test_in = 2946623;
	SeedValue *uint_test = seed_value_from_uint(fixture->context,
												uint_test_in, NULL);
	guint uint_test_out = seed_value_to_uint(fixture->context,
											 uint_test, NULL);

	g_assert(uint_test_in == uint_test_out);

	// int to/from JS equality

	gint int_test_in = -54374;
	SeedValue *int_test = seed_value_from_int(fixture->context,
											  int_test_in, NULL);
	gint int_test_out = seed_value_to_int(fixture->context,
										  int_test, NULL);

	g_assert(int_test_in == int_test_out);

	// char to/from JS equality

	gchar char_test_in = -126;
	SeedValue *char_test = seed_value_from_char(fixture->context,
												char_test_in, NULL);
	gchar char_test_out = seed_value_to_char(fixture->context,
											 char_test, NULL);

	g_assert(char_test_in == char_test_out);

	// uchar to/from JS equality

	guchar uchar_test_in = 250;
	SeedValue *uchar_test = seed_value_from_uchar(fixture->context,
												  uchar_test_in, NULL);
	guchar uchar_test_out = seed_value_to_uchar(fixture->context,
												uchar_test, NULL);

	g_assert(uchar_test_in == uchar_test_out);

	// long to/from JS equality

	glong long_test_in = -454250;
	SeedValue *long_test = seed_value_from_long(fixture->context,
												long_test_in, NULL);
	glong long_test_out = seed_value_to_long(fixture->context,
											 long_test, NULL);

	g_assert(long_test_in == long_test_out);

	// ulong to/from JS equality

	gulong ulong_test_in = 250;
	SeedValue *ulong_test = seed_value_from_ulong(fixture->context,
												  ulong_test_in, NULL);
	gulong ulong_test_out = seed_value_to_ulong(fixture->context,
												ulong_test, NULL);

	g_assert(ulong_test_in == ulong_test_out);

	// int64 to/from JS equality

	gint64 int64_test_in = -54374;
	SeedValue *int64_test = seed_value_from_int64(fixture->context,
												  int64_test_in, NULL);
	gint64 int64_test_out = seed_value_to_int64(fixture->context,
												int64_test, NULL);

	g_assert(int64_test_in == int64_test_out);

	// uint64 to/from JS equality

	guint64 uint64_test_in = 2946623;
	SeedValue *uint64_test = seed_value_from_uint64(fixture->context,
													uint64_test_in, NULL);
	guint64 uint64_test_out = seed_value_to_uint64(fixture->context,
												   uint64_test, NULL);

	g_assert(uint64_test_in == uint64_test_out);

	// float to/from JS equality

	gfloat float_test_in = 1.618;
	SeedValue *float_test = seed_value_from_float(fixture->context,
												  float_test_in, NULL);
	gfloat float_test_out = seed_value_to_float(fixture->context,
												float_test, NULL);

	g_assert(float_test_in == float_test_out);

	// double to/from JS equality

	gdouble double_test_in = 1.6134857638;
	SeedValue *double_test = seed_value_from_double(fixture->context,
													double_test_in, NULL);
	gdouble double_test_out = seed_value_to_double(fixture->context,
												   double_test, NULL);

	g_assert(double_test_in == double_test_out);

	// string to/from JS equality

	gchar *string_test_in = "Hello, world!";
	SeedValue *string_test = seed_value_from_string(fixture->context,
													string_test_in, NULL);
	gchar *string_test_out = seed_value_to_string(fixture->context,
												  string_test, NULL);

	g_assert(strncmp(string_test_in, string_test_out,
					 strlen(string_test_in)) == 0);

	// filename to/from JS equality

	gchar *filename_test_in = "/bin";
	SeedValue *filename_test = seed_value_from_filename(fixture->context,
														filename_test_in,
														NULL);
	gchar *filename_test_out = seed_value_to_filename(fixture->context,
													  filename_test, NULL);

	g_assert(strncmp(filename_test_in, filename_test_out,
					 strlen(filename_test_in)) == 0);
	SeedValue si[2];
	si[0] = seed_value_from_string (fixture->context, "Hi", NULL);
	si[1] = seed_value_from_int (fixture->context, 1, NULL);
	gint ni;
	gchar *ns;

	seed_value_to_format (fixture->context, "si", si, NULL, &ns, &ni, NULL);
	g_assert (ni == 1);
	g_assert (!strcmp(ns, "Hi"));


}