[cairo-commit] rcairo/packages/cairo/ext cairo.def, 1.5, 1.6 rb_cairo.c, 1.8, 1.9 rb_cairo.h, 1.11, 1.12 rb_cairo_context.c, 1.14, 1.15 rb_cairo_font_extents.c, 1.5, 1.6 rb_cairo_matrix.c, 1.10, 1.11 rb_cairo_private.c, NONE, 1.1 rb_cairo_private.h, NONE, 1.1 rb_cairo_scaled_font.c, NONE, 1.1

Kouhei Sutou commit at pdx.freedesktop.org
Sun Oct 9 07:49:41 PDT 2005


Committed by: kou

Update of /cvs/cairo/rcairo/packages/cairo/ext
In directory gabe:/tmp/cvs-serv16084/packages/cairo/ext

Modified Files:
	cairo.def rb_cairo.c rb_cairo.h rb_cairo_context.c 
	rb_cairo_font_extents.c rb_cairo_matrix.c 
Added Files:
	rb_cairo_private.c rb_cairo_private.h rb_cairo_scaled_font.c 
Log Message:
* packages/cairo/ext/rb_cairo_context.c,
  packages/cairo/ext/rb_cairo_matrix.c: Moved duplicated
  functions to ...
* packages/cairo/ext/rb_cairo_private.h: ... here.
* packages/cairo/ext/rb_cairo_private.c: ditto.

* packages/cairo/ext/rb_cairo_scaled_font.c: Implemented
  cairo_scaled_font_t.
* packages/cairo/ext/cairo.def: ditto.
* packages/cairo/ext/rb_cairo.c: ditto.
* packages/cairo/ext/rb_cairo.h: ditto.



Index: cairo.def
===================================================================
RCS file: /cvs/cairo/rcairo/packages/cairo/ext/cairo.def,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- cairo.def	9 Oct 2005 07:04:40 -0000	1.5
+++ cairo.def	9 Oct 2005 14:49:39 -0000	1.6
@@ -13,6 +13,7 @@
     rb_cCairo_FontFace        DATA
     rb_cCairo_FontExtents     DATA
     rb_cCairo_FontOptions     DATA
+    rb_cCairo_ScaledFont      DATA
     rb_cCairo_TextExtents     DATA
     rb_cCairo_Glyph           DATA
     rb_cCairo_Surface         DATA
@@ -27,9 +28,11 @@
     rb_cairo_font_face_from_ruby_object
     rb_cairo_font_face_to_ruby_object
     rb_cairo_font_extents_from_ruby_object
+    rb_cairo_font_extents_to_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_scaled_font_to_ruby_object
+    rb_cairo_scaled_font_from_ruby_object
     rb_cairo_text_extents_from_ruby_object
     rb_cairo_text_extents_to_ruby_object
     rb_cairo_glyph_from_ruby_object

Index: rb_cairo.c
===================================================================
RCS file: /cvs/cairo/rcairo/packages/cairo/ext/rb_cairo.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- rb_cairo.c	8 Oct 2005 14:01:42 -0000	1.8
+++ rb_cairo.c	9 Oct 2005 14:49:39 -0000	1.9
@@ -21,9 +21,10 @@
 extern void Init_cairo_constants (void);
 extern void Init_cairo_exception (void);
 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_scaled_font (void);
+extern void Init_cairo_text_extents (void);
 extern void Init_cairo_pattern (void);
 extern void Init_cairo_glyph (void);
 
@@ -41,6 +42,7 @@
   Init_cairo_font ();
   Init_cairo_font_extents ();
   Init_cairo_font_options ();
+  Init_cairo_scaled_font ();
   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.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- rb_cairo.h	9 Oct 2005 07:04:40 -0000	1.11
+++ rb_cairo.h	9 Oct 2005 14:49:39 -0000	1.12
@@ -40,6 +40,7 @@
 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_ScaledFont;
 RUBY_CAIRO_VAR VALUE rb_cCairo_TextExtents;
 RUBY_CAIRO_VAR VALUE rb_cCairo_Glyph;
 RUBY_CAIRO_VAR VALUE rb_cCairo_Surface;
@@ -65,6 +66,9 @@
 #define RVAL2CRFONTOPTIONS(obj) (rb_cairo_font_options_from_ruby_object(obj))
 #define CRFONTOPTIONS2RVAL(ext) (rb_cairo_font_options_to_ruby_object(ext))
 
+#define RVAL2CRSCALEDFONT(obj) (rb_cairo_scaled_font_from_ruby_object(obj))
+#define CRSCALEDFONT2RVAL(ext) (rb_cairo_scaled_font_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))
 
@@ -95,6 +99,9 @@
 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_scaled_font_t  *rb_cairo_scaled_font_from_ruby_object (VALUE obj);
+VALUE                 rb_cairo_scaled_font_to_ruby_object   (cairo_scaled_font_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);
 

Index: rb_cairo_context.c
===================================================================
RCS file: /cvs/cairo/rcairo/packages/cairo/ext/rb_cairo_context.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- rb_cairo_context.c	9 Oct 2005 07:04:40 -0000	1.14
+++ rb_cairo_context.c	9 Oct 2005 14:49:39 -0000	1.15
@@ -10,6 +10,7 @@
 */
 
 #include "rb_cairo.h"
+#include "rb_cairo_private.h"
 
 VALUE rb_cCairo_Context;
 
@@ -17,42 +18,6 @@
 
 #define _SELF  (RVAL2CRCONTEXT(self))
 
-static VALUE
-float_array (double *values, unsigned count)
-{
-  VALUE result;
-  int i;
-
-  result = rb_ary_new2 (count);
-  for (i = 0; i < count; i++)
-    {
-      rb_ary_push (result, rb_float_new (values[i]));
-    }
-  return result;
-}
-
-static void
-glyphs_to_array (VALUE rb_array, cairo_glyph_t **glyphs, int *length)
-{
-  int i;
-  
-  if (!rb_obj_is_kind_of (rb_array, rb_cArray))
-     rb_raise (rb_eTypeError, "expected array");
-
-  *length = RARRAY(rb_array)->len;
-  *glyphs = ALLOCA_N (cairo_glyph_t, *length);
-
-  if (!*glyphs)
-    rb_cairo_check_status (CAIRO_STATUS_NO_MEMORY);
-
-  for (i = 0; i < *length; i++)
-    {
-      memcpy ((char *) &(*glyphs)[i],
-              (char *) RVAL2CRGLYPH (rb_ary_entry (rb_array, i)),
-              sizeof (cairo_glyph_t));
-    }
-}
-
 static inline void
 cr_check_status (cairo_t *context)
 {
@@ -442,7 +407,7 @@
   pair[1] = NUM2DBL (y);
   cairo_user_to_device (_SELF, pair, pair + 1);
   cr_check_status (_SELF);
-  return float_array (pair, 2);
+  return cr__float_array (pair, 2);
 }
 
 static VALUE
@@ -453,7 +418,7 @@
   pair[1] = NUM2DBL (dy);
   cairo_user_to_device_distance (_SELF, pair, pair + 1);
   cr_check_status (_SELF);
-  return float_array (pair, 2);
+  return cr__float_array (pair, 2);
 }
 
 static VALUE
@@ -464,7 +429,7 @@
   pair[1] = NUM2DBL (y);
   cairo_device_to_user (_SELF, pair, pair + 1);
   cr_check_status (_SELF);
-  return float_array (pair, 2);
+  return cr__float_array (pair, 2);
 }
 
 static VALUE
@@ -475,7 +440,7 @@
   pair[1] = NUM2DBL (dy);
   cairo_device_to_user_distance (_SELF, pair, pair + 1);
   cr_check_status (_SELF);
-  return float_array (pair, 2);
+  return cr__float_array (pair, 2);
 }
 
 
@@ -760,7 +725,7 @@
       rb_yield (self);
     }
   cairo_stroke_extents (_SELF, extents, extents + 1, extents + 2, extents + 3);
-  return float_array (extents, 4);
+  return cr__float_array (extents, 4);
 }
 
 static VALUE
@@ -773,7 +738,7 @@
       rb_yield (self);
     }
   cairo_fill_extents (_SELF, extents, extents + 1, extents + 2, extents + 3);
-  return float_array (extents, 4);
+  return cr__float_array (extents, 4);
 }
 
 /* Clipping */
@@ -885,7 +850,7 @@
   if (!rb_obj_is_kind_of (rb_glyphs, rb_cArray))
      rb_raise (rb_eTypeError, "expected array");
     
-  glyphs_to_array (rb_glyphs, &glyphs, &count);
+  cr__glyphs_to_array (rb_glyphs, &glyphs, &count);
   cairo_show_glyphs (_SELF, glyphs, count);
   cr_check_status (_SELF);
   return self;
@@ -934,7 +899,7 @@
   cairo_glyph_t *glyphs;
   int length;
 
-  glyphs_to_array (rb_glyphs, &glyphs, &length);
+  cr__glyphs_to_array (rb_glyphs, &glyphs, &length);
   cairo_glyph_extents (_SELF, glyphs, length, &extents);
   cr_check_status (_SELF);
   return CRTEXTEXTENTS2RVAL (&extents);
@@ -954,7 +919,7 @@
   int count;
   cairo_glyph_t *glyphs;
 
-  glyphs_to_array (rb_glyphs, &glyphs, &count);
+  cr__glyphs_to_array (rb_glyphs, &glyphs, &count);
   cairo_glyph_path (_SELF, glyphs, count);
   cr_check_status (_SELF);
   
@@ -1000,7 +965,7 @@
 {
   double point[2];
   cairo_get_current_point (_SELF, point, point + 1);
-  return float_array (point, 2);
+  return cr__float_array (point, 2);
 }
 
 static VALUE

Index: rb_cairo_font_extents.c
===================================================================
RCS file: /cvs/cairo/rcairo/packages/cairo/ext/rb_cairo_font_extents.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- rb_cairo_font_extents.c	7 Oct 2005 14:08:13 -0000	1.5
+++ rb_cairo_font_extents.c	9 Oct 2005 14:49:39 -0000	1.6
@@ -9,7 +9,6 @@
  *
  */
 
-
 #include "rb_cairo.h"
 
 VALUE rb_cCairo_FontExtents;

Index: rb_cairo_matrix.c
===================================================================
RCS file: /cvs/cairo/rcairo/packages/cairo/ext/rb_cairo_matrix.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- rb_cairo_matrix.c	9 Oct 2005 07:04:40 -0000	1.10
+++ rb_cairo_matrix.c	9 Oct 2005 14:49:39 -0000	1.11
@@ -11,6 +11,7 @@
 
 
 #include "rb_cairo.h"
+#include "rb_cairo_private.h"
 
 VALUE rb_cCairo_Matrix;
 
@@ -44,22 +45,6 @@
 }  
 
 
-static VALUE
-float_array (double   *values,
-             unsigned  count)
-{
-  VALUE     result;
-  unsigned  i;
-
-  result = rb_ary_new2 (count);
-  for (i = 0; i < count; i++)
-    {
-      rb_ary_push (result, rb_float_new (values[i]));
-    }
-  return result;
-}
-
-
 /*
  * methods
  */
@@ -121,7 +106,7 @@
   affine[3] = matrix->yy;
   affine[4] = matrix->x0;
   affine[5] = matrix->y0;
-  return float_array (affine, 6);
+  return cr__float_array (affine, 6);
 }
 
 static    VALUE
@@ -178,7 +163,7 @@
   pair[1] = NUM2DBL (dy);
   cairo_matrix_transform_distance (_SELF,
                                    pair, pair + 1);
-  return float_array (pair, 2);
+  return cr__float_array (pair, 2);
 }
 
 static    VALUE
@@ -190,7 +175,7 @@
   pair[1] = NUM2DBL (y);
   cairo_matrix_transform_point (_SELF,
                                 pair, pair + 1);
-  return float_array (pair, 2);
+  return cr__float_array (pair, 2);
 }
 
 

--- NEW FILE: rb_cairo_private.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"

VALUE
cr__float_array (double *values, unsigned count)
{
  VALUE result;
  int i;

  result = rb_ary_new2 (count);
  for (i = 0; i < count; i++)
    {
      rb_ary_push (result, rb_float_new (values[i]));
    }
  return result;
}

void
cr__glyphs_to_array (VALUE rb_array, cairo_glyph_t **glyphs, int *length)
{
  int i;
  
  if (!rb_obj_is_kind_of (rb_array, rb_cArray))
     rb_raise (rb_eTypeError, "expected array");

  *length = RARRAY(rb_array)->len;
  *glyphs = ALLOCA_N (cairo_glyph_t, *length);

  if (!*glyphs)
    rb_cairo_check_status (CAIRO_STATUS_NO_MEMORY);

  for (i = 0; i < *length; i++)
    {
      memcpy ((char *) &(*glyphs)[i],
              (char *) RVAL2CRGLYPH (rb_ary_entry (rb_array, i)),
              sizeof (cairo_glyph_t));
    }
}


--- NEW FILE: rb_cairo_private.h ---
/* -*- 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
 *
*/

#ifndef RB_CAIRO_PRIVATE_H
#define RB_CAIRO_PRIVATE_H

VALUE cr__float_array (double *values, unsigned count);
void cr__glyphs_to_array (VALUE rb_array, cairo_glyph_t **glyphs, int *length);

#endif

--- NEW FILE: rb_cairo_scaled_font.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"
#include "rb_cairo_private.h"

VALUE rb_cCairo_ScaledFont;

#define _SELF(self)  (RVAL2CRSCALEDFONT(self))

static inline void
cr_scaled_font_check_status (cairo_scaled_font_t *font)
{
  rb_cairo_check_status (cairo_scaled_font_status (font));
}

cairo_scaled_font_t *
rb_cairo_scaled_font_from_ruby_object (VALUE obj)
{
  cairo_scaled_font_t *font;
  if (!RTEST (rb_obj_is_kind_of (obj, rb_cCairo_ScaledFont)))
    {
      rb_raise (rb_eTypeError, "not a cairo scaled font");
    }
  Data_Get_Struct (obj, cairo_scaled_font_t, font);
  return font;
}

static void
cr_scaled_font_free (void *ptr)
{
  if (ptr)
    {
      cairo_scaled_font_destroy ((cairo_scaled_font_t *) ptr);
    }
}

VALUE
rb_cairo_scaled_font_to_ruby_object (cairo_scaled_font_t *font)
{
  if (font)
    {
      cairo_scaled_font_reference (font);
      return Data_Wrap_Struct (rb_cCairo_FontFace, NULL,
                               cr_scaled_font_free, font);
    }
  else
    {
      return Qnil;
    }
}

static VALUE
cr_scaled_font_allocate (VALUE klass)
{
  return Data_Wrap_Struct (klass, NULL, cr_scaled_font_free, NULL);
}

static VALUE
cr_scaled_font_initialize (VALUE self, VALUE face, VALUE matrix,
                           VALUE ctm, VALUE options)
{
  cairo_scaled_font_t *font;

  font = cairo_scaled_font_create (RVAL2CRFONTFACE (face),
                                   RVAL2CRMATRIX (matrix),
                                   RVAL2CRMATRIX (ctm),
                                   RVAL2CRFONTOPTIONS (options));
  cr_scaled_font_check_status (font);
  DATA_PTR (self) = font;
  return Qnil;
}

static VALUE
cr_scaled_font_extents (VALUE self)
{
  cairo_font_extents_t extents;
  cairo_scaled_font_extents (_SELF (self), &extents);
  cr_scaled_font_check_status (_SELF (self));
  return CRFONTEXTENTS2RVAL (&extents);
}

static VALUE
cr_scaled_font_glyph_extents (VALUE self, VALUE rb_glyphs)
{
  cairo_text_extents_t extents;
  cairo_glyph_t *glyphs;
  int count;

  cr__glyphs_to_array (rb_glyphs, &glyphs, &count);
  cairo_scaled_font_glyph_extents (_SELF (self), glyphs, count, &extents);
  cr_scaled_font_check_status (_SELF (self));
  return CRTEXTEXTENTS2RVAL (&extents);
}

void
Init_cairo_scaled_font (void)
{
  rb_cCairo_ScaledFont =
    rb_define_class_under (rb_mCairo, "ScaledFont", rb_cObject);

  rb_define_alloc_func (rb_cCairo_ScaledFont, cr_scaled_font_allocate);

  rb_define_method (rb_cCairo_ScaledFont, "initialize",
                    cr_scaled_font_initialize, 4);

  rb_define_method (rb_cCairo_ScaledFont, "extents",
                    cr_scaled_font_extents, 0);
  rb_define_method (rb_cCairo_ScaledFont, "glyph_extents",
                    cr_scaled_font_glyph_extents, 1);
}



More information about the cairo-commit mailing list