[cairo-commit] rcairo/packages/cairo/ext cairo.def, 1.1,
1.2 rb_cairo.c, 1.6, 1.7 rb_cairo.h, 1.7,
1.8 rb_cairo_font_options.c, NONE, 1.1 rb_cairo_surface.c, 1.9, 1.10
Kouhei Sutou
commit at pdx.freedesktop.org
Fri Oct 7 08:11:28 PDT 2005
Committed by: kou
Update of /cvs/cairo/rcairo/packages/cairo/ext
In directory gabe:/tmp/cvs-serv28507/packages/cairo/ext
Modified Files:
cairo.def rb_cairo.c rb_cairo.h rb_cairo_surface.c
Added Files:
rb_cairo_font_options.c
Log Message:
* packages/cairo/ext/rb_cairo_font_options.c: Implemented
cairo_font_options_t.
* packages/cairo/ext/rb_cairo_surface.c: ditto.
* packages/cairo/ext/rb_cairo.c: ditto.
* packages/cairo/ext/rb_cairo.h: ditto.
* packages/cairo/ext/cairo.def: ditto.
* packages/cairo/lib/cairo.rb: ditto.
Index: cairo.def
===================================================================
RCS file: /cvs/cairo/rcairo/packages/cairo/ext/cairo.def,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- cairo.def 4 Oct 2005 03:08:41 -0000 1.1
+++ cairo.def 7 Oct 2005 15:11:26 -0000 1.2
@@ -6,6 +6,7 @@
rb_cCairo_Pattern DATA
rb_cCairo_FontFace DATA
rb_cCairo_FontExtents DATA
+ rb_cCairo_FontOptions DATA
rb_cCairo_TextExtents DATA
rb_cCairo_Glyph DATA
rb_cCairo_Surface DATA
@@ -18,6 +19,8 @@
rb_cairo_font_face_from_ruby_object
rb_cairo_font_face_to_ruby_object
rb_cairo_font_extents_from_ruby_object
+ rb_cairo_font_options_to_ruby_object
+ rb_cairo_font_options_from_ruby_object
rb_cairo_font_extents_to_ruby_object
rb_cairo_text_extents_from_ruby_object
rb_cairo_text_extents_to_ruby_object
Index: rb_cairo.c
===================================================================
RCS file: /cvs/cairo/rcairo/packages/cairo/ext/rb_cairo.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- rb_cairo.c 7 Oct 2005 14:08:13 -0000 1.6
+++ rb_cairo.c 7 Oct 2005 15:11:26 -0000 1.7
@@ -22,6 +22,7 @@
extern void Init_cairo_font (void);
extern void Init_cairo_text_extents (void);
extern void Init_cairo_font_extents (void);
+extern void Init_cairo_font_options (void);
extern void Init_cairo_pattern (void);
extern void Init_cairo_glyph (void);
@@ -36,8 +37,9 @@
Init_cairo_constants ();
Init_cairo_exception ();
Init_cairo_font ();
- Init_cairo_text_extents ();
Init_cairo_font_extents ();
+ Init_cairo_font_options ();
+ Init_cairo_text_extents ();
Init_cairo_pattern ();
Init_cairo_glyph ();
}
Index: rb_cairo.h
===================================================================
RCS file: /cvs/cairo/rcairo/packages/cairo/ext/rb_cairo.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- rb_cairo.h 7 Oct 2005 14:08:13 -0000 1.7
+++ rb_cairo.h 7 Oct 2005 15:11:26 -0000 1.8
@@ -13,7 +13,6 @@
#ifndef RB_CAIRO_H
#define RB_CAIRO_H
-#include <cairo-features.h>
#include <cairo.h>
#include "ruby.h"
@@ -34,6 +33,7 @@
RUBY_CAIRO_VAR VALUE rb_cCairo_Pattern;
RUBY_CAIRO_VAR VALUE rb_cCairo_FontFace;
RUBY_CAIRO_VAR VALUE rb_cCairo_FontExtents;
+RUBY_CAIRO_VAR VALUE rb_cCairo_FontOptions;
RUBY_CAIRO_VAR VALUE rb_cCairo_TextExtents;
RUBY_CAIRO_VAR VALUE rb_cCairo_Glyph;
RUBY_CAIRO_VAR VALUE rb_cCairo_Surface;
@@ -53,6 +53,9 @@
#define RVAL2CRFONTEXTENTS(obj) (rb_cairo_font_extents_from_ruby_object(obj))
#define CRFONTEXTENTS2RVAL(ext) (rb_cairo_font_extents_to_ruby_object(ext))
+#define RVAL2CRFONTOPTIONS(obj) (rb_cairo_font_options_from_ruby_object(obj))
+#define CRFONTOPTIONS2RVAL(ext) (rb_cairo_font_options_to_ruby_object(ext))
+
#define RVAL2CRTEXTEXTENTS(obj) (rb_cairo_text_extents_from_ruby_object(obj))
#define CRTEXTEXTENTS2RVAL(ext) (rb_cairo_text_extents_to_ruby_object(ext))
@@ -77,6 +80,9 @@
cairo_font_extents_t *rb_cairo_font_extents_from_ruby_object (VALUE obj);
VALUE rb_cairo_font_extents_to_ruby_object (cairo_font_extents_t *extents);
+cairo_font_options_t *rb_cairo_font_options_from_ruby_object (VALUE obj);
+VALUE rb_cairo_font_options_to_ruby_object (cairo_font_options_t *options);
+
cairo_text_extents_t *rb_cairo_text_extents_from_ruby_object (VALUE obj);
VALUE rb_cairo_text_extents_to_ruby_object (cairo_text_extents_t *extents);
--- NEW FILE: rb_cairo_font_options.c ---
/* -*- c-file-style: "gnu"; indent-tabs-mode: nil -*- */
/*
* Ruby Cairo Binding
*
* Copyright 2005 Kouhei Sutou <kou at cozmixng.org>
*
* This file is made available under the same terms as Ruby
*
*/
#include "rb_cairo.h"
#define _SELF(self) (RVAL2CRFONTOPTIONS(self))
VALUE rb_cCairo_FontOptions;
static inline void
cr_options_check_status (cairo_font_options_t *options)
{
rb_cairo_raise_exception (cairo_font_options_status (options));
}
cairo_font_options_t *
rb_cairo_font_options_from_ruby_object (VALUE obj)
{
cairo_font_options_t *options;
if (!RTEST (rb_obj_is_kind_of (obj, rb_cCairo_FontOptions)))
{
rb_raise (rb_eTypeError, "not a cairo font options");
}
Data_Get_Struct (obj, cairo_font_options_t, options);
return options;
}
static void
cr_options_free (void *ptr)
{
if (ptr)
{
cairo_font_options_destroy ((cairo_font_options_t *) ptr);
}
}
VALUE
rb_cairo_options_to_ruby_object (cairo_font_options_t *options)
{
if (options)
{
return Data_Wrap_Struct (rb_cCairo_FontOptions, NULL,
cr_options_free, options);
}
else
{
return Qnil;
}
}
static VALUE
cr_options_allocate (VALUE klass)
{
return Data_Wrap_Struct (klass, NULL, cr_options_free, NULL);
}
static VALUE
cr_options_create (VALUE self)
{
cairo_font_options_t *options;
options = cairo_font_options_create ();
cr_options_check_status (options);
DATA_PTR (self) = options;
return Qnil;
}
static VALUE
cr_options_copy (VALUE self)
{
cairo_font_options_t *options;
options = cairo_font_options_copy (_SELF (self));
cr_options_check_status (options);
return CRFONTOPTIONS2RVAL (options);
}
static VALUE
cr_options_merge (VALUE self, VALUE other)
{
cairo_font_options_merge (_SELF (self), _SELF (other));
return self;
}
static VALUE
cr_options_equal (VALUE self, VALUE other)
{
return cairo_font_options_equal (_SELF (self), _SELF (other)) ? Qtrue : Qfalse;
}
static VALUE
cr_options_hash (VALUE self)
{
return INT2NUM (cairo_font_options_hash (_SELF (self)));
}
static VALUE
cr_options_set_antialias (VALUE self, VALUE rb_antialias)
{
cairo_antialias_t antialias;
antialias = NUM2INT (rb_antialias);
if (antialias < CAIRO_ANTIALIAS_DEFAULT ||
antialias > CAIRO_ANTIALIAS_SUBPIXEL)
{
rb_raise (rb_eArgError, "invalid antialias");
}
cairo_font_options_set_antialias (_SELF (self), antialias);
return self;
}
static VALUE
cr_options_get_antialias (VALUE self)
{
return INT2NUM (cairo_font_options_get_antialias (_SELF (self)));
}
static VALUE
cr_options_set_subpixel_order (VALUE self, VALUE rb_subpixel_order)
{
cairo_subpixel_order_t subpixel_order;
subpixel_order = NUM2INT (rb_subpixel_order);
if (subpixel_order < CAIRO_SUBPIXEL_ORDER_DEFAULT ||
subpixel_order > CAIRO_SUBPIXEL_ORDER_VBGR)
{
rb_raise (rb_eArgError, "invalid subpixel order");
}
cairo_font_options_set_subpixel_order (_SELF (self), subpixel_order);
return self;
}
static VALUE
cr_options_get_subpixel_order (VALUE self)
{
return INT2NUM (cairo_font_options_get_subpixel_order (_SELF (self)));
}
static VALUE
cr_options_set_hint_style (VALUE self, VALUE rb_hint_style)
{
cairo_hint_style_t hint_style;
hint_style = NUM2INT (rb_hint_style);
if (hint_style < CAIRO_HINT_STYLE_DEFAULT ||
hint_style > CAIRO_HINT_STYLE_FULL)
{
rb_raise (rb_eArgError, "invalid hint style");
}
cairo_font_options_set_hint_style (_SELF (self), hint_style);
return self;
}
static VALUE
cr_options_get_hint_style (VALUE self)
{
return INT2NUM (cairo_font_options_get_hint_style (_SELF (self)));
}
static VALUE
cr_options_set_hint_metrics (VALUE self, VALUE rb_hint_metrics)
{
cairo_hint_metrics_t hint_metrics;
hint_metrics = NUM2INT (rb_hint_metrics);
if (hint_metrics < CAIRO_HINT_METRICS_DEFAULT ||
hint_metrics > CAIRO_HINT_METRICS_ON)
{
rb_raise (rb_eArgError, "invalid hint metrics");
}
cairo_font_options_set_hint_metrics (_SELF (self), hint_metrics);
return self;
}
static VALUE
cr_options_get_hint_metrics (VALUE self)
{
return INT2NUM (cairo_font_options_get_hint_metrics (_SELF (self)));
}
void
Init_cairo_font_options (void)
{
rb_cCairo_FontOptions =
rb_define_class_under (rb_mCairo, "FontOptions", rb_cObject);
rb_define_alloc_func (rb_cCairo_FontOptions, cr_options_allocate);
rb_define_method (rb_cCairo_FontOptions, "initialize", cr_options_create, 0);
rb_define_method (rb_cCairo_FontOptions, "dup", cr_options_copy, 0);
rb_define_method (rb_cCairo_FontOptions, "merge", cr_options_merge, 1);
rb_define_method (rb_cCairo_FontOptions, "eql?", cr_options_equal, 1);
rb_define_method (rb_cCairo_FontOptions, "hash", cr_options_hash, 0);
rb_define_method (rb_cCairo_FontOptions, "set_antialias",
cr_options_set_antialias, 1);
rb_define_method (rb_cCairo_FontOptions, "antialias",
cr_options_get_antialias, 0);
rb_define_method (rb_cCairo_FontOptions, "set_subpixel_order",
cr_options_set_subpixel_order, 1);
rb_define_method (rb_cCairo_FontOptions, "subpixel_order",
cr_options_get_subpixel_order, 0);
rb_define_method (rb_cCairo_FontOptions, "set_hint_style",
cr_options_set_hint_style, 1);
rb_define_method (rb_cCairo_FontOptions, "hint_style",
cr_options_get_hint_style, 0);
rb_define_method (rb_cCairo_FontOptions, "set_hint_metrics",
cr_options_set_hint_metrics, 1);
rb_define_method (rb_cCairo_FontOptions, "hint_metrics",
cr_options_get_hint_metrics, 0);
}
Index: rb_cairo_surface.c
===================================================================
RCS file: /cvs/cairo/rcairo/packages/cairo/ext/rb_cairo_surface.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- rb_cairo_surface.c 7 Oct 2005 14:08:13 -0000 1.9
+++ rb_cairo_surface.c 7 Oct 2005 15:11:26 -0000 1.10
@@ -213,14 +213,12 @@
static VALUE
cr_surface_get_font_options (VALUE self)
{
-#if 0
-/* XXX: after implement Cairo::FontOptions */
- cairo_font_options_t *options = cairo_font_options_create();
- cairo_surface_get_font_options (_SELF, &options);
+ cairo_font_options_t *options = NULL;
+ cairo_surface_get_font_options (_SELF, options);
cr_surface_check_status (_SELF);
- return CRFONTOPTIONS2RVAL (cairo_font_options_copy (options)); /* check status!*/
-#endif
- return Qnil;
+ options = cairo_font_options_copy (options);
+ rb_cairo_raise_exception (cairo_font_options_status (options));
+ return CRFONTOPTIONS2RVAL (options);
}
static VALUE
More information about the cairo-commit
mailing list