Class: SFML::Font
- Inherits:
-
Object
- Object
- SFML::Font
- Defined in:
- ext/graphics/font.c,
ext/graphics/font.c
Overview
A font face used to render text, loaded from a file, memory buffer or stream. Glyphs are rasterized and cached lazily per character size.
Class Method Summary collapse
-
.from_file(path) ⇒ Font
Loads a font from the font file at
filename. -
.from_memory(data) ⇒ Font
Loads a font from an in-memory font file buffer.
-
.from_stream(stream) ⇒ Font
streamis any object responding to the InputStream protocol (see InputStream).
Instance Method Summary collapse
-
#bold_kerning(first, second, size) ⇒ Float
Returns the kerning of the bold variant between two code points.
-
#copy ⇒ Font
Returns a deep copy of the object.
-
#glyph(codepoint, size, bold = false, outline_thickness = 0) ⇒ Glyph
Returns the glyph for
codepointat the givencharacter_size. -
#has_glyph?(codepoint) ⇒ Boolean
Returns
trueif the font contains a glyph forcodepoint. -
#info ⇒ String
Returns the font's family name.
-
#kerning(first, second, size) ⇒ Float
Returns the kerning between two code points at the given size.
-
#line_spacing(size) ⇒ Float
Returns the line spacing for the given character size.
-
#smooth=(value) ⇒ Boolean
Enables or disables smooth rendering.
-
#smooth? ⇒ Boolean
Returns
trueif smooth rendering is enabled. -
#texture(size) ⇒ Texture
Returns the texture atlas holding rendered glyphs for the given size.
-
#underline_position(size) ⇒ Float
Returns the position of the underline for the given size.
-
#underline_thickness(size) ⇒ Float
Returns the thickness of the underline for the given size.
Class Method Details
.from_file(path) ⇒ Font
Loads a font from the font file at filename.
38 39 40 |
# File 'ext/graphics/font.c', line 38
static VALUE Font_from_file(VALUE klass, VALUE rb_path) {
return Font_wrap(klass, sfFont_createFromFile(StringValueCStr(rb_path)));
}
|
.from_memory(data) ⇒ Font
Loads a font from an in-memory font file buffer.
50 51 52 53 54 55 |
# File 'ext/graphics/font.c', line 50
static VALUE Font_from_memory(VALUE klass, VALUE rb_data) {
StringValue(rb_data);
return Font_wrap(klass,
sfFont_createFromMemory(RSTRING_PTR(rb_data), (size_t)RSTRING_LEN(rb_data)));
}
|
.from_stream(stream) ⇒ Font
stream is any object responding to the InputStream protocol (see
InputStream).
66 67 68 69 70 71 72 73 |
# File 'ext/graphics/font.c', line 66
static VALUE Font_from_stream(VALUE klass, VALUE rb_stream) {
VALUE holder = Qnil;
sfInputStream* stream = input_stream_from_rb(rb_stream, &holder);
(void)holder;
return Font_wrap(klass, sfFont_createFromStream(stream));
}
|
Instance Method Details
#bold_kerning(first, second, size) ⇒ Float
Returns the kerning of the bold variant between two code points.
142 143 144 145 146 |
# File 'ext/graphics/font.c', line 142
static VALUE Font_get_bold_kerning(VALUE self, VALUE rb_first, VALUE rb_second, VALUE rb_size) {
return DBL2NUM(sfFont_getBoldKerning(Get_Font_Struct(self), (uint32_t)NUM2UINT(rb_first),
(uint32_t)NUM2UINT(rb_second),
(unsigned int)NUM2UINT(rb_size)));
}
|
#copy ⇒ Font
Returns a deep copy of the object.
81 82 83 |
# File 'ext/graphics/font.c', line 81 static VALUE Font_copy(VALUE self) { return Font_wrap(Get_Klass_Font(), sfFont_copy(Get_Font_Struct(self))); } |
#glyph(codepoint, size, bold = false, outline_thickness = 0) ⇒ Glyph
Returns the glyph for codepoint at the given character_size.
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'ext/graphics/font.c', line 92
static VALUE Font_get_glyph(int argc, VALUE* argv, VALUE self) {
VALUE rb_codepoint, rb_size, rb_bold, rb_outline;
bool bold = false;
float outline = 0;
rb_scan_args(argc, argv, "22", &rb_codepoint, &rb_size, &rb_bold, &rb_outline);
if (!NIL_P(rb_bold)) {
bold = RTEST(rb_bold);
}
if (!NIL_P(rb_outline)) {
outline = NUM2DBL(rb_outline);
}
return glyph_from_c(sfFont_getGlyph(Get_Font_Struct(self), (uint32_t)NUM2UINT(rb_codepoint),
(unsigned int)NUM2UINT(rb_size), bold, outline));
}
|
#has_glyph?(codepoint) ⇒ Boolean
Returns true if the font contains a glyph for codepoint.
118 119 120 |
# File 'ext/graphics/font.c', line 118
static VALUE Font_has_glyph(VALUE self, VALUE rb_codepoint) {
return BOOL2RB(sfFont_hasGlyph(Get_Font_Struct(self), (uint32_t)NUM2UINT(rb_codepoint)));
}
|
#info ⇒ String
Returns the font's family name.
222 223 224 225 226 |
# File 'ext/graphics/font.c', line 222 static VALUE Font_get_info(VALUE self) { sfFontInfo info = sfFont_getInfo(Get_Font_Struct(self)); return rb_str_new_cstr(info.family != NULL ? info.family : ""); } |
#kerning(first, second, size) ⇒ Float
Returns the kerning between two code points at the given size.
129 130 131 132 133 |
# File 'ext/graphics/font.c', line 129
static VALUE Font_get_kerning(VALUE self, VALUE rb_first, VALUE rb_second, VALUE rb_size) {
return DBL2NUM(sfFont_getKerning(Get_Font_Struct(self), (uint32_t)NUM2UINT(rb_first),
(uint32_t)NUM2UINT(rb_second),
(unsigned int)NUM2UINT(rb_size)));
}
|
#line_spacing(size) ⇒ Float
Returns the line spacing for the given character size.
155 156 157 |
# File 'ext/graphics/font.c', line 155
static VALUE Font_get_line_spacing(VALUE self, VALUE rb_size) {
return DBL2NUM(sfFont_getLineSpacing(Get_Font_Struct(self), (unsigned int)NUM2UINT(rb_size)));
}
|
#smooth=(value) ⇒ Boolean
Enables or disables smooth rendering.
201 202 203 204 |
# File 'ext/graphics/font.c', line 201
static VALUE Font_set_smooth(VALUE self, VALUE rb_smooth) {
sfFont_setSmooth((sfFont*)Get_Font_Struct(self), RTEST(rb_smooth));
return rb_smooth;
}
|
#smooth? ⇒ Boolean
Returns true if smooth rendering is enabled.
212 213 214 |
# File 'ext/graphics/font.c', line 212 static VALUE Font_is_smooth(VALUE self) { return BOOL2RB(sfFont_isSmooth(Get_Font_Struct(self))); } |
#texture(size) ⇒ Texture
Returns the texture atlas holding rendered glyphs for the given size.
189 190 191 192 |
# File 'ext/graphics/font.c', line 189
static VALUE Font_get_texture(VALUE self, VALUE rb_size) {
return texture_from_borrowed(
sfFont_getTexture((sfFont*)Get_Font_Struct(self), (unsigned int)NUM2UINT(rb_size)));
}
|
#underline_position(size) ⇒ Float
Returns the position of the underline for the given size.
166 167 168 169 |
# File 'ext/graphics/font.c', line 166
static VALUE Font_get_underline_position(VALUE self, VALUE rb_size) {
return DBL2NUM(
sfFont_getUnderlinePosition(Get_Font_Struct(self), (unsigned int)NUM2UINT(rb_size)));
}
|
#underline_thickness(size) ⇒ Float
Returns the thickness of the underline for the given size.
177 178 179 180 |
# File 'ext/graphics/font.c', line 177
static VALUE Font_get_underline_thickness(VALUE self, VALUE rb_size) {
return DBL2NUM(
sfFont_getUnderlineThickness(Get_Font_Struct(self), (unsigned int)NUM2UINT(rb_size)));
}
|