[cairo-commit] rcairo/src cairo.def, 1.14, 1.15 rb_cairo.h, 1.19, 1.20 rb_cairo_font_face.c, 1.4, 1.5 rb_cairo_private.c, 1.5, 1.6 rb_cairo_private.h, 1.8, 1.9
Kouhei Sutou
commit at pdx.freedesktop.org
Thu Aug 14 01:11:17 PDT 2008
Committed by: kou
Update of /cvs/cairo/rcairo/src
In directory kemper:/tmp/cvs-serv8684/src
Modified Files:
cairo.def rb_cairo.h rb_cairo_font_face.c rb_cairo_private.c
rb_cairo_private.h
Log Message:
* test/test_context.rb (ContextTest#test_font_face): add a test
for Cairo::Context#font_face{,=}.
* src/rb_cairo_private.[ch] (rb_cairo__inspect): add.
* test/test_font_face.rb: add.
* src/rb_cairo_font_face.c: support Cairo::ToyFontFace.
* src/cairo.def, src/rb_cairo.h: add rb_cCairo_ToyFontFace and
rb_cCairo_UserFontFace.
Index: cairo.def
===================================================================
RCS file: /cvs/cairo/rcairo/src/cairo.def,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- cairo.def 13 Aug 2008 12:27:39 -0000 1.14
+++ cairo.def 14 Aug 2008 08:11:10 -0000 1.15
@@ -16,6 +16,8 @@
rb_cCairo_LinearPattern DATA
rb_cCairo_RadialPattern DATA
rb_cCairo_FontFace DATA
+ rb_cCairo_ToyFontFace DATA
+ rb_cCairo_UserFontFace DATA
rb_cCairo_FontExtents DATA
rb_cCairo_FontOptions DATA
rb_cCairo_ScaledFont DATA
Index: rb_cairo.h
===================================================================
RCS file: /cvs/cairo/rcairo/src/rb_cairo.h,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- rb_cairo.h 13 Aug 2008 12:27:39 -0000 1.19
+++ rb_cairo.h 14 Aug 2008 08:11:11 -0000 1.20
@@ -84,6 +84,8 @@
RB_CAIRO_VAR VALUE rb_cCairo_LinearPattern;
RB_CAIRO_VAR VALUE rb_cCairo_RadialPattern;
RB_CAIRO_VAR VALUE rb_cCairo_FontFace;
+RB_CAIRO_VAR VALUE rb_cCairo_ToyFontFace;
+RB_CAIRO_VAR VALUE rb_cCairo_UserFontFace;
RB_CAIRO_VAR VALUE rb_cCairo_FontExtents;
RB_CAIRO_VAR VALUE rb_cCairo_FontOptions;
RB_CAIRO_VAR VALUE rb_cCairo_ScaledFont;
Index: rb_cairo_font_face.c
===================================================================
RCS file: /cvs/cairo/rcairo/src/rb_cairo_font_face.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- rb_cairo_font_face.c 20 May 2007 09:25:37 -0000 1.4
+++ rb_cairo_font_face.c 14 Aug 2008 08:11:12 -0000 1.5
@@ -17,29 +17,66 @@
#include "rb_cairo_private.h"
VALUE rb_cCairo_FontFace;
+VALUE rb_cCairo_ToyFontFace = Qnil;
+VALUE rb_cCairo_UserFontFace = Qnil;
#define _SELF (RVAL2CRFONTFACE(self))
+static inline void
+cr_font_face_check_status (cairo_font_face_t *face)
+{
+ rb_cairo_check_status (cairo_font_face_status (face));
+}
+
cairo_font_face_t *
rb_cairo_font_face_from_ruby_object (VALUE obj)
{
cairo_font_face_t *face;
+
if (!rb_cairo__is_kind_of (obj, rb_cCairo_FontFace))
{
- rb_raise (rb_eTypeError, "not a cairo font face");
+ rb_raise (rb_eTypeError,
+ "not a cairo font face: %s",
+ rb_cairo__inspect (obj));
}
Data_Get_Struct (obj, cairo_font_face_t, face);
+ if (!face)
+ rb_cairo_check_status (CAIRO_STATUS_NULL_POINTER);
+ cr_font_face_check_status (face);
return face;
}
+static void
+cr_font_face_free (void *ptr)
+{
+ if (ptr)
+ {
+ cairo_font_face_t *face = ptr;
+ cairo_font_face_destroy (face);
+ }
+}
+
VALUE
rb_cairo_font_face_to_ruby_object (cairo_font_face_t *face)
{
if (face)
{
+ VALUE klass;
+
+ switch (cairo_font_face_get_type (face))
+ {
+ case CAIRO_FONT_TYPE_TOY:
+ klass = rb_cCairo_ToyFontFace;
+ break;
+ case CAIRO_FONT_TYPE_USER:
+ klass = rb_cCairo_UserFontFace;
+ break;
+ default:
+ klass = rb_cCairo_FontFace;
+ break;
+ }
cairo_font_face_reference (face);
- return Data_Wrap_Struct (rb_cCairo_FontFace, NULL,
- cairo_font_face_destroy, face);
+ return Data_Wrap_Struct (klass, NULL, cr_font_face_free, face);
}
else
{
@@ -47,10 +84,96 @@
}
}
+static VALUE
+cr_font_face_allocate (VALUE klass)
+{
+ return Data_Wrap_Struct (klass, NULL, cr_font_face_free, NULL);
+}
+
+static VALUE
+cr_toy_font_face_initialize (int argc, VALUE *argv, VALUE self)
+{
+ cairo_font_face_t *face;
+ VALUE rb_family, rb_slant, rb_weight;
+ const char *family;
+ cairo_font_slant_t slant;
+ cairo_font_weight_t weight;
+
+ rb_scan_args (argc, argv, "12", &rb_family, &rb_slant, &rb_weight);
+
+ if (rb_cairo__is_kind_of (rb_family, rb_cString))
+ {
+ family = RSTRING_PTR (rb_family);
+ }
+ else if (rb_cairo__is_kind_of (rb_family, rb_cSymbol))
+ {
+ family = rb_id2name (SYM2ID (rb_family));
+ }
+ else
+ {
+ rb_raise (rb_eArgError,
+ "family name should be String or Symbol: %s",
+ rb_cairo__inspect (rb_family));
+ }
+
+ if (NIL_P (rb_slant))
+ slant = CAIRO_FONT_SLANT_NORMAL;
+ else
+ slant = RVAL2CRFONTSLANT (rb_slant);
+
+ if (NIL_P (rb_weight))
+ weight = CAIRO_FONT_WEIGHT_NORMAL;
+ else
+ weight = RVAL2CRFONTWEIGHT (rb_weight);
+
+ face = cairo_toy_font_face_create (family, slant, weight);
+ cr_font_face_check_status (face);
+ DATA_PTR (self) = face;
+
+ return Qnil;
+}
+
+static VALUE
+cr_toy_font_face_get_family (VALUE self)
+{
+ return CSTR2RVAL (cairo_toy_font_face_get_family (_SELF));
+}
+
+static VALUE
+cr_toy_font_face_get_slant (VALUE self)
+{
+ return INT2NUM (cairo_toy_font_face_get_slant (_SELF));
+}
+
+static VALUE
+cr_toy_font_face_get_weight (VALUE self)
+{
+ return INT2NUM (cairo_toy_font_face_get_weight (_SELF));
+}
+
void
Init_cairo_font (void)
{
rb_cCairo_FontFace =
rb_define_class_under (rb_mCairo, "FontFace", rb_cObject);
+ rb_define_alloc_func (rb_cCairo_FontFace, cr_font_face_allocate);
+
+#if CAIRO_CHECK_VERSION(1, 7, 2)
+ rb_cCairo_ToyFontFace =
+ rb_define_class_under (rb_mCairo, "ToyFontFace", rb_cCairo_FontFace);
+
+ rb_define_method (rb_cCairo_ToyFontFace, "initialize",
+ cr_toy_font_face_initialize, -1);
+
+ rb_define_method (rb_cCairo_ToyFontFace, "family",
+ cr_toy_font_face_get_family, 0);
+ rb_define_method (rb_cCairo_ToyFontFace, "slant",
+ cr_toy_font_face_get_slant, 0);
+ rb_define_method (rb_cCairo_ToyFontFace, "weight",
+ cr_toy_font_face_get_weight, 0);
+
+ rb_cCairo_UserFontFace =
+ rb_define_class_under (rb_mCairo, "UserFontFace", rb_cCairo_FontFace);
+#endif
}
Index: rb_cairo_private.c
===================================================================
RCS file: /cvs/cairo/rcairo/src/rb_cairo_private.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- rb_cairo_private.c 11 Aug 2008 12:53:33 -0000 1.5
+++ rb_cairo_private.c 14 Aug 2008 08:11:13 -0000 1.6
@@ -5,7 +5,7 @@
* $Author$
* $Date$
*
- * Copyright 2005 Kouhei Sutou <kou at cozmixng.org>
+ * Copyright 2005-2008 Kouhei Sutou <kou at cozmixng.org>
*
* This file is made available under the same terms as Ruby
*
@@ -17,6 +17,7 @@
static ID cr_id_normalize_const_name;
static ID cr_id_objects;
static ID cr_id_dup;
+static ID cr_id_inspect;
VALUE
rb_cairo__float_array (double *values, unsigned count)
@@ -119,10 +120,20 @@
return rb_funcall (rb_ivar_get (klass, cr_id_objects), cr_id_dup, 0);
}
+const char *
+rb_cairo__inspect (VALUE object)
+{
+ VALUE inspected;
+
+ inspected = rb_funcall (object, cr_id_inspect, 0);
+ return RSTRING_PTR (inspected);
+}
+
void
Init_cairo_private (void)
{
cr_id_normalize_const_name = rb_intern ("normalize_const_name");
cr_id_objects = rb_intern ("objects");
cr_id_dup = rb_intern ("dup");
+ cr_id_inspect = rb_intern ("inspect");
}
Index: rb_cairo_private.h
===================================================================
RCS file: /cvs/cairo/rcairo/src/rb_cairo_private.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- rb_cairo_private.h 11 Aug 2008 12:53:33 -0000 1.8
+++ rb_cairo_private.h 14 Aug 2008 08:11:14 -0000 1.9
@@ -5,7 +5,7 @@
* $Author$
* $Date$
*
- * Copyright 2005 Kouhei Sutou <kou at cozmixng.org>
+ * Copyright 2005-2008 Kouhei Sutou <kou at cozmixng.org>
*
* This file is made available under the same terms as Ruby
*
@@ -90,4 +90,6 @@
void rb_cairo__gc_guard_remove (VALUE klass, VALUE object);
VALUE rb_cairo__gc_guarded_objects (VALUE klass);
+const char *rb_cairo__inspect (VALUE object);
+
#endif
More information about the cairo-commit
mailing list