[cairo-commit] rcairo/src cairo.def, 1.11, 1.12 rb_cairo.c, 1.9, 1.10 rb_cairo.h, 1.14, 1.15 rb_cairo_surface.c, 1.25, 1.26
Kouhei Sutou
commit at pdx.freedesktop.org
Thu Apr 10 19:56:47 PDT 2008
Committed by: kou
Update of /cvs/cairo/rcairo/src
In directory kemper:/tmp/cvs-serv16533/src
Modified Files:
cairo.def rb_cairo.c rb_cairo.h rb_cairo_surface.c
Log Message:
* src/cairo.def, src/rb_cairo.c, src/rb_cairo.h, src/lib/cairo.rb,
src/rb_cairo_surface.c: Cairo::PSSurface.new,
Cairo::PDFSurface.new, Cairo::SVGSurface.new,
Cairo::PSSurface#set_size and Cairo::PDFSurface#set_size accept
paper description that can be parsed by Cairo::Paper.parse as page size.
Index: cairo.def
===================================================================
RCS file: /cvs/cairo/rcairo/src/cairo.def,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- cairo.def 11 Apr 2008 01:40:26 -0000 1.11
+++ cairo.def 11 Apr 2008 03:01:33 -0000 1.12
@@ -51,6 +51,7 @@
rb_mCairo_Color DATA
rb_cCairo_Color_Base DATA
+ rb_cCairo_Paper DATA
rb_cairo_context_from_ruby_object
rb_cairo_context_to_ruby_object
Index: rb_cairo.c
===================================================================
RCS file: /cvs/cairo/rcairo/src/rb_cairo.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- rb_cairo.c 11 Jan 2008 13:20:19 -0000 1.9
+++ rb_cairo.c 11 Apr 2008 03:01:33 -0000 1.10
@@ -17,7 +17,7 @@
#include "rb_cairo.h"
#include "rb_cairo_private.h"
-VALUE rb_mCairo, rb_mCairo_Color, rb_cCairo_Color_Base;
+VALUE rb_mCairo, rb_mCairo_Color, rb_cCairo_Color_Base, rb_cCairo_Paper;
static ID id__add_one_arg_setter;
@@ -62,6 +62,7 @@
rb_mCairo_Color = rb_const_get (rb_mCairo, rb_intern ("Color"));
rb_cCairo_Color_Base = rb_const_get (rb_mCairo_Color, rb_intern ("Base"));
+ rb_cCairo_Paper = rb_const_get (rb_mCairo, rb_intern ("Paper"));
Init_cairo_private ();
Init_cairo_constants ();
Index: rb_cairo.h
===================================================================
RCS file: /cvs/cairo/rcairo/src/rb_cairo.h,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- rb_cairo.h 11 Apr 2008 01:40:25 -0000 1.14
+++ rb_cairo.h 11 Apr 2008 03:01:33 -0000 1.15
@@ -131,6 +131,7 @@
RB_CAIRO_VAR VALUE rb_mCairo_SVGVersion;
RB_CAIRO_VAR VALUE rb_mCairo_Color;
RB_CAIRO_VAR VALUE rb_cCairo_Color_Base;
+RB_CAIRO_VAR VALUE rb_cCairo_Paper;
#define RVAL2CRCONTEXT(obj) (rb_cairo_context_from_ruby_object(obj))
Index: rb_cairo_surface.c
===================================================================
RCS file: /cvs/cairo/rcairo/src/rb_cairo_surface.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- rb_cairo_surface.c 11 Apr 2008 01:40:26 -0000 1.25
+++ rb_cairo_surface.c 11 Apr 2008 03:01:33 -0000 1.26
@@ -38,10 +38,31 @@
static ID cr_id_read;
static ID cr_id_write;
static ID cr_id_inspect;
+static ID cr_id_parse;
+static ID cr_id_size;
+static ID cr_id_set_unit;
static cairo_user_data_key_t cr_closure_key;
#define _SELF (RVAL2CRSURFACE(self))
+static VALUE
+cr_paper_parse (VALUE paper_description)
+{
+ return rb_funcall (rb_cCairo_Paper, cr_id_parse, 2, paper_description, Qtrue);
+}
+
+static void
+cr_paper_to_size_in_points (VALUE paper_description, VALUE *width, VALUE *height)
+{
+ VALUE paper, size;
+
+ paper = cr_paper_parse (paper_description);
+ rb_funcall (paper, cr_id_set_unit, 1, rb_str_new2 ("pt"));
+ size = rb_funcall (paper, cr_id_size, 0);
+ *width = RARRAY_PTR (size)[0];
+ *height = RARRAY_PTR (size)[1];
+}
+
static inline void
cr_surface_check_status (cairo_surface_t *surface)
{
@@ -312,8 +333,7 @@
}
static VALUE
-cr_surface_create_similar (VALUE self, VALUE content,
- VALUE width, VALUE height)
+cr_surface_create_similar (VALUE self, VALUE content, VALUE width, VALUE height)
{
cairo_surface_t *surface;
@@ -634,13 +654,29 @@
/* Printing surfaces */
#define DEFINE_SURFACE(type) \
static VALUE \
-cr_ ## type ## _surface_initialize (VALUE self, VALUE target, \
- VALUE rb_width_in_points, \
- VALUE rb_height_in_points) \
+cr_ ## type ## _surface_initialize (int argc, VALUE *argv, VALUE self) \
{ \
+ VALUE target, rb_width_in_points, rb_height_in_points; \
+ VALUE arg2, arg3; \
cairo_surface_t *surface; \
double width_in_points, height_in_points; \
\
+ rb_scan_args (argc, argv, "21", &target, &arg2, &arg3); \
+ if (argc == 2) \
+ { \
+ VALUE paper; \
+ \
+ paper = arg2; \
+ cr_paper_to_size_in_points (paper, \
+ &rb_width_in_points, \
+ &rb_height_in_points); \
+ } \
+ else \
+ { \
+ rb_width_in_points = arg2; \
+ rb_height_in_points = arg3; \
+ } \
+ \
width_in_points = NUM2DBL (rb_width_in_points); \
height_in_points = NUM2DBL (rb_height_in_points); \
\
@@ -682,22 +718,40 @@
return Qnil; \
}
+#define DEFINE_SURFACE_SET_SIZE(type) \
+static VALUE \
+cr_ ## type ## _surface_set_size (int argc, VALUE *argv, VALUE self) \
+{ \
+ VALUE arg1, arg2; \
+ VALUE width_in_points, height_in_points; \
+ \
+ rb_scan_args(argc, argv, "11", &arg1, &arg2); \
+ if (argc == 1) \
+ { \
+ VALUE paper; \
+ \
+ paper = arg1; \
+ cr_paper_to_size_in_points (paper, \
+ &width_in_points, \
+ &height_in_points); \
+ } \
+ else \
+ { \
+ width_in_points = arg1; \
+ height_in_points = arg2; \
+ } \
+ \
+ cairo_ ## type ## _surface_set_size (_SELF, \
+ NUM2DBL (width_in_points), \
+ NUM2DBL (height_in_points)); \
+ cr_surface_check_status (_SELF); \
+ return Qnil; \
+}
#if CAIRO_HAS_PS_SURFACE
/* PS-surface functions */
DEFINE_SURFACE(ps)
-
-static VALUE
-cr_ps_surface_set_size (VALUE self,
- VALUE width_in_points,
- VALUE height_in_points)
-{
- cairo_ps_surface_set_size (_SELF,
- NUM2DBL (width_in_points),
- NUM2DBL (height_in_points));
- cr_surface_check_status (_SELF);
- return Qnil;
-}
+DEFINE_SURFACE_SET_SIZE(ps)
static VALUE
cr_ps_surface_dsc_comment (VALUE self, VALUE comment)
@@ -751,18 +805,7 @@
#if CAIRO_HAS_PDF_SURFACE
/* PDF-surface functions */
DEFINE_SURFACE(pdf)
-
-static VALUE
-cr_pdf_surface_set_size (VALUE self,
- VALUE width_in_points,
- VALUE height_in_points)
-{
- cairo_pdf_surface_set_size (_SELF,
- NUM2DBL (width_in_points),
- NUM2DBL (height_in_points));
- cr_surface_check_status (_SELF);
- return Qnil;
-}
+DEFINE_SURFACE_SET_SIZE(pdf)
#endif
#if CAIRO_HAS_SVG_SURFACE
@@ -1043,6 +1086,9 @@
cr_id_read = rb_intern ("read");
cr_id_write = rb_intern ("write");
cr_id_inspect = rb_intern ("inspect");
+ cr_id_parse = rb_intern ("parse");
+ cr_id_size = rb_intern ("size");
+ cr_id_set_unit = rb_intern ("unit=");
rb_cCairo_Surface =
rb_define_class_under (rb_mCairo, "Surface", rb_cObject);
@@ -1106,13 +1152,13 @@
rb_cCairo_Surface); \
\
rb_define_method (rb_cCairo_ ## name ## Surface, "initialize", \
- cr_ ## type ## _surface_initialize, 3);
+ cr_ ## type ## _surface_initialize, -1);
#if CAIRO_HAS_PS_SURFACE
/* PS-surface */
INIT_SURFACE(ps, PS)
- rb_define_method (rb_cCairo_PSSurface, "set_size", cr_ps_surface_set_size, 2);
+ rb_define_method (rb_cCairo_PSSurface, "set_size", cr_ps_surface_set_size, -1);
rb_define_method (rb_cCairo_PSSurface, "dsc_comment",
cr_ps_surface_dsc_comment, 1);
rb_define_method (rb_cCairo_PSSurface, "dsc_begin_setup",
@@ -1135,7 +1181,7 @@
INIT_SURFACE(pdf, PDF)
rb_define_method (rb_cCairo_PDFSurface, "set_size",
- cr_pdf_surface_set_size, 2);
+ cr_pdf_surface_set_size, -1);
RB_CAIRO_DEF_SETTERS (rb_cCairo_PDFSurface);
#endif
More information about the cairo-commit
mailing list