[cairo-commit] rcairo/src rb_cairo_private.c, 1.1,
1.2 rb_cairo_private.h, 1.1, 1.2 rb_cairo.c, 1.4,
1.5 rb_cairo_constants.c, 1.1, 1.2
Kouhei Sutou
commit at pdx.freedesktop.org
Tue May 1 04:49:52 PDT 2007
Committed by: kou
Update of /cvs/cairo/rcairo/src
In directory kemper:/tmp/cvs-serv29202/src
Modified Files:
rb_cairo_private.c rb_cairo_private.h rb_cairo.c
rb_cairo_constants.c
Log Message:
* src/rb_cairo_private.[ch] (rb_cairo__const_get,
Init_cairo_private): added.
* src/rb_cairo.c: moved Init_* declarations to rb_cairo_private.h.
* src/rb_cairo_constants.c: supported abbrev notation for constant
name. We can write just like
context.antialias = :none
instead of
context.antialias = Cairo::ANTIALIAS_NONE
* src/lib/cairo.rb (Cairo.normalize_const_name): added.
* src/lib/cairo/color.rb: used Cairo.normalize_const_name.
Index: rb_cairo_private.c
===================================================================
RCS file: /cvs/cairo/rcairo/src/rb_cairo_private.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- rb_cairo_private.c 6 Mar 2007 12:17:34 -0000 1.1
+++ rb_cairo_private.c 1 May 2007 11:49:43 -0000 1.2
@@ -12,6 +12,9 @@
*/
#include "rb_cairo.h"
+#include "rb_cairo_private.h"
+
+static ID id_normalize_const_name;
VALUE
rb_cairo__float_array (double *values, unsigned count)
@@ -49,3 +52,29 @@
}
}
+VALUE
+rb_cairo__const_get (VALUE name, const char *prefix)
+{
+ VALUE rb_normalized_name;
+ char *const_name, *normalized_name;
+ size_t prefix_len, normalized_name_len;
+
+ rb_normalized_name = rb_funcall (rb_mCairo, id_normalize_const_name, 1, name);
+ normalized_name = RVAL2CSTR (rb_normalized_name);
+
+ prefix_len = strlen (prefix);
+ normalized_name_len = strlen (normalized_name);
+
+ const_name = ALLOCA_N (char, prefix_len + normalized_name_len + 1);
+ strncpy (const_name, prefix, prefix_len);
+ strncpy (const_name + prefix_len, normalized_name, normalized_name_len);
+ const_name[prefix_len + normalized_name_len] = '\0';
+
+ return rb_const_get (rb_mCairo, rb_intern (const_name));
+}
+
+void
+Init_cairo_private (void)
+{
+ id_normalize_const_name = rb_intern ("normalize_const_name");
+}
Index: rb_cairo_private.h
===================================================================
RCS file: /cvs/cairo/rcairo/src/rb_cairo_private.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- rb_cairo_private.h 6 Mar 2007 12:17:34 -0000 1.1
+++ rb_cairo_private.h 1 May 2007 11:49:43 -0000 1.2
@@ -17,7 +17,28 @@
#define CR_TRUE 1
#define CR_FALSE 0
+#define CSTR2RVAL(str) rb_str_new2(str)
+#define RVAL2CSTR(str) StringValueCStr(str)
+
+extern void Init_cairo_private (void);
+extern void Init_cairo_constants (void);
+
+extern void Init_cairo_context (void);
+extern void Init_cairo_path (void);
+extern void Init_cairo_matrix (void);
+extern void Init_cairo_surface (void);
+extern void Init_cairo_exception (void);
+extern void Init_cairo_font (void);
+extern void Init_cairo_font_extents (void);
+extern void Init_cairo_font_options (void);
+extern void Init_cairo_scaled_font (void);
+extern void Init_cairo_text_extents (void);
+extern void Init_cairo_pattern (void);
+extern void Init_cairo_glyph (void);
+
VALUE rb_cairo__float_array (double *values, unsigned count);
void rb_cairo__glyphs_to_array (VALUE rb_array, cairo_glyph_t **glyphs, int *length);
+VALUE rb_cairo__const_get (VALUE name, const char *prefix);
+
#endif
Index: rb_cairo.c
===================================================================
RCS file: /cvs/cairo/rcairo/src/rb_cairo.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- rb_cairo.c 10 Mar 2007 11:56:46 -0000 1.4
+++ rb_cairo.c 1 May 2007 11:49:43 -0000 1.5
@@ -15,23 +15,10 @@
#include "rb_cairo.h"
+#include "rb_cairo_private.h"
VALUE rb_mCairo;
-extern void Init_cairo_context (void);
-extern void Init_cairo_path (void);
-extern void Init_cairo_matrix (void);
-extern void Init_cairo_surface (void);
-extern void Init_cairo_constants (void);
-extern void Init_cairo_exception (void);
-extern void Init_cairo_font (void);
-extern void Init_cairo_font_extents (void);
-extern void Init_cairo_font_options (void);
-extern void Init_cairo_scaled_font (void);
-extern void Init_cairo_text_extents (void);
-extern void Init_cairo_pattern (void);
-extern void Init_cairo_glyph (void);
-
static ID id__add_one_arg_setter;
void
@@ -73,6 +60,7 @@
rb_ary_new3 (4,
INT2FIX (1), INT2FIX (6), INT2FIX (0), Qnil));
+ Init_cairo_private ();
Init_cairo_constants ();
Init_cairo_context ();
Index: rb_cairo_constants.c
===================================================================
RCS file: /cvs/cairo/rcairo/src/rb_cairo_constants.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- rb_cairo_constants.c 6 Mar 2007 12:17:34 -0000 1.1
+++ rb_cairo_constants.c 1 May 2007 11:49:43 -0000 1.2
@@ -14,6 +14,7 @@
#include "rb_cairo.h"
+#include "rb_cairo_private.h"
#define CAIRO_OPERATOR_MIN CAIRO_OPERATOR_CLEAR
#define CAIRO_OPERATOR_MAX CAIRO_OPERATOR_SATURATE
@@ -63,23 +64,28 @@
#define CAIRO_SVG_VERSION_MIN CAIRO_SVG_VERSION_1_1
#define CAIRO_SVG_VERSION_MAX CAIRO_SVG_VERSION_1_2
-#define DEFINE_RVAL2ENUM(name, const_name) \
-cairo_ ## name ## _t \
-rb_cairo_ ## name ## _from_ruby_object (VALUE rb_ ## name) \
-{ \
- cairo_ ## name ## _t name; \
- name = FIX2INT (rb_ ## name); \
- if (name < CAIRO_ ## const_name ## _MIN || \
- name > CAIRO_ ## const_name ## _MAX) \
- { \
- rb_raise (rb_eArgError, \
- "invalid %s: %d (expect %d <= %s <= %d)", \
- #name, name, \
- CAIRO_ ## const_name ## _MIN, \
- #name, \
- CAIRO_ ## const_name ## _MAX); \
- } \
- return name; \
+#define DEFINE_RVAL2ENUM(name, const_name) \
+cairo_ ## name ## _t \
+rb_cairo_ ## name ## _from_ruby_object (VALUE rb_ ## name) \
+{ \
+ cairo_ ## name ## _t name; \
+ \
+ if (!rb_obj_is_kind_of (rb_ ## name, rb_cNumeric)) \
+ rb_ ## name = rb_cairo__const_get (rb_ ## name, \
+ # const_name "_"); \
+ \
+ name = FIX2INT (rb_ ## name); \
+ if (name < CAIRO_ ## const_name ## _MIN || \
+ name > CAIRO_ ## const_name ## _MAX) \
+ { \
+ rb_raise (rb_eArgError, \
+ "invalid %s: %d (expect %d <= %s <= %d)", \
+ #name, name, \
+ CAIRO_ ## const_name ## _MIN, \
+ #name, \
+ CAIRO_ ## const_name ## _MAX); \
+ } \
+ return name; \
}
DEFINE_RVAL2ENUM(operator, OPERATOR)
More information about the cairo-commit
mailing list