Class: Ray::Font

Inherits:
Object
  • Object
show all
Extended by:
ResourceSet
Includes:
TextHelper
Defined in:
lib/ray/font.rb,
ext/font.c

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ResourceSet

[], add_set, clear, missing_pattern, reject!, select!, set_hash

Methods included from TextHelper

#convert, #internal_string

Constructor Details

#initialize(filename) ⇒ Object #initialize(io) ⇒ Object

Overloads:

  • #initialize(filename) ⇒ Object

    Parameters:

    • filename (String)

      Name of the file to load the font from.

  • #initialize(io) ⇒ Object

    Parameters:

    • io (#read)

      IO object to read the font from.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'ext/font.c', line 36

static
VALUE ray_font_init(VALUE self, VALUE arg) {
  say_font *font = ray_rb2font(self);

  if (rb_respond_to(arg, RAY_METH("read"))) {
    arg = rb_funcall(arg, RAY_METH("read"), 0);
    if (!say_font_load_from_memory(font, StringValuePtr(arg),
                                   RSTRING_LEN(arg))) {
      rb_raise(rb_eRuntimeError, "%s", say_error_get_last());
    }
  }
  else if (rb_respond_to(arg, RAY_METH("to_str"))) {
    if (!say_font_load_from_file(font, StringValuePtr(arg))) {
      rb_raise(rb_eRuntimeError, "%s", say_error_get_last());
    }
  }
  else {
    rb_raise(rb_eTypeError, "Can't convert %s into String",
             RAY_OBJ_CLASSNAME(arg));
  }

  return self;
}

Class Method Details

.defaultRay::Font

Returns Default font.

Returns:



24
25
26
27
28
# File 'ext/font.c', line 24

static
VALUE ray_font_default(VALUE self) {
  say_font *font = say_font_default();
  return Data_Wrap_Struct(self, NULL, NULL, font);
}

Instance Method Details

#kerning(size, a, b) ⇒ Integer

Returns Size there should be between the two characters. Most of the time, just 0, but can also be a negative number.

Parameters:

  • size (Integer)

    Size of the font.

  • a (Integer)

    Codepoint of the first character.

  • b (Integer)

    Codepoint of the second character.

Returns:

  • (Integer)

    Size there should be between the two characters. Most of the time, just 0, but can also be a negative number.



69
70
71
72
73
74
75
76
# File 'ext/font.c', line 69

static
VALUE ray_font_kerning(VALUE self, VALUE size, VALUE a, VALUE b) {
  say_font *font = ray_rb2font(self);
  size_t kern = say_font_get_kerning(font, NUM2ULONG(a), NUM2ULONG(b),
                                     NUM2ULONG(size));

  return INT2FIX(kern);
}

#line_height(size) ⇒ Integer

Returns Height of a line.

Parameters:

  • size (Integer)

    Size of the font

Returns:

  • (Integer)

    Height of a line



83
84
85
86
# File 'ext/font.c', line 83

static
VALUE ray_font_line_height(VALUE self, VALUE size) {
  return INT2FIX(say_font_get_line_height(ray_rb2font(self), NUM2ULONG(size)));
}