示例#1
0
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, "03", &rb_family, &rb_slant, &rb_weight);

  if (NIL_P (rb_family))
    {
      family = "";
    }
  else 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 nil, 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;
}
示例#2
0
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: %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;
}
示例#3
0
static VALUE
cr_s_wrap (VALUE self, VALUE pointer)
{
  VALUE result;
  VALUE rb_cr;
  cairo_t *cr;

  if (NIL_P (rb_cairo__cFFIPointer))
    {
      rb_raise (rb_eNotImpError,
                "%s: FFI::Pointer is required",
                rb_id2name (rb_frame_this_func ()));
    }

  if (!RTEST (rb_obj_is_kind_of (pointer, rb_cairo__cFFIPointer)))
    {
      rb_raise (rb_eArgError,
                "must be FFI::Pointer: %s",
                rb_cairo__inspect (pointer));
    }

  {
    VALUE rb_cr_address;
    rb_cr_address = rb_funcall (pointer, rb_intern ("address"), 0);
    cr = NUM2PTR (rb_cr_address);
    cr_check_status (cr);
  }

  rb_cr = rb_obj_alloc (self);
  cairo_reference (cr);
  DATA_PTR (rb_cr) = cr;
  rb_ivar_set (rb_cr, cr_id_surface, Qnil);

  if (rb_block_given_p ())
    {
      result = rb_ensure (rb_yield, rb_cr, cr_destroy_with_destroy_check, rb_cr);
    }
  else
    {
      result = rb_cr;
    }

  return result;
}