Class: SDL2::TTF
- Inherits:
-
Object
- Object
- SDL2::TTF
- Defined in:
- ttf.c,
ttf.c
Overview
This class represents font information.
You can render TrueType fonts using SDL_ttf and this class.
Defined Under Namespace
Instance Attribute Summary collapse
-
#ascent ⇒ Integer
readonly
The maximum pixel ascent of all glyphs of the font.
-
#descent ⇒ Integer
readonly
The maximum pixel descent of all glyphs of the font.
-
#face_family_name ⇒ String
readonly
The current font face family name of the font.
-
#face_style_name ⇒ String
readonly
The current font face style name of the font.
-
#height ⇒ Integer
readonly
The maximum pixel height of all glyphs of the font.
-
#hinting ⇒ Integer
Font hinting.
-
#kerning ⇒ Booelan
True if kerning is enabled.
-
#line_skip ⇒ Integer
readonly
The recommended pixel height of rendered line of text of the font.
-
#num_faces ⇒ Integer
readonly
The number of faces available in the font.
-
#outline ⇒ Integer
The outline pixel width of the font.
-
#style ⇒ Integer
Font style.
Class Method Summary collapse
-
.init ⇒ nil
Initialize TrueType font rendering submodule.
-
.open(fname, ptsize, index = 0) ⇒ SDL2::TTF
Open a font data from file.
Instance Method Summary collapse
-
#destroy ⇒ nil
Destroy the font data and release memory.
-
#destroy? ⇒ Boolean
Return true if the font is destroyed by #destroy.
-
#face_is_fixed_width? ⇒ Boolean
Return true if the font is fixed width.
-
#render_blended(text, fg) ⇒ SDL2::Surface
Render text using the font with fg color on a new surface, using Blended mode.
-
#render_shaded(text, fg, bg) ⇒ SDL2::Surface
Render text using the font with fg color on a new surface, using Shaded mode.
-
#render_solid(text, fg) ⇒ SDL2::Surface
Render text using the font with fg color on a new surface, using Solid mode.
-
#size_text(text) ⇒ [Integer, Integer]
Calculate the size of rendered surface of text using the font.
Instance Attribute Details
#ascent ⇒ Integer (readonly)
The maximum pixel ascent of all glyphs of the font. The distance from the top of the font to the baseline.
#descent ⇒ Integer (readonly)
The maximum pixel descent of all glyphs of the font. The distance from the bottom of the font to the baseline.
#face_family_name ⇒ String (readonly)
The current font face family name of the font.
#face_style_name ⇒ String (readonly)
The current font face style name of the font.
#height ⇒ Integer (readonly)
The maximum pixel height of all glyphs of the font. You can use this height to render text as close together vertically as possible.
#hinting ⇒ Integer
Font hinting. One of the constants of Hinting.
#kerning ⇒ Booelan
True if kerning is enabled.
#line_skip ⇒ Integer (readonly)
The recommended pixel height of rendered line of text of the font. Normally, this value is larger than #height.
#num_faces ⇒ Integer (readonly)
The number of faces available in the font.
#outline ⇒ Integer
The outline pixel width of the font.
#style ⇒ Integer
Font style. The OR’d bits of the constants of Style.
Class Method Details
.init ⇒ nil
Initialize TrueType font rendering submodule.
This function must be called before calling other methods/class methods of SDL2::TTF.
127 128 129 130 131 |
# File 'ttf.c', line 127
static VALUE TTF_s_init(VALUE self)
{
HANDLE_TTF_ERROR(TTF_Init());
return Qnil;
}
|
.open(fname, ptsize, index = 0) ⇒ SDL2::TTF
Open a font data from file.
149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'ttf.c', line 149
static VALUE TTF_s_open(int argc, VALUE* argv, VALUE self)
{
TTF_Font* font;
VALUE fname, ptsize, index;
rb_scan_args(argc, argv, "21", &fname, &ptsize, &index);
font = TTF_OpenFontIndex(StringValueCStr(fname), NUM2INT(ptsize),
index == Qnil ? 0 : NUM2LONG(index));
if (!font)
TTF_ERROR();
return TTF_new(font);
}
|
Instance Method Details
#destroy ⇒ nil
Destroy the font data and release memory.
168 169 170 171 172 173 174 175 |
# File 'ttf.c', line 168
static VALUE TTF_destroy(VALUE self)
{
TTF* f = Get_TTF(self);
if (f->font)
TTF_CloseFont(f->font);
f->font = NULL;
return Qnil;
}
|
#destroy? ⇒ Boolean
Return true if the font is destroyed by #destroy.
#face_is_fixed_width? ⇒ Boolean
Return true if the font is fixed width.
#render_blended(text, fg) ⇒ SDL2::Surface
291 292 293 294 |
# File 'ttf.c', line 291
static VALUE TTF_render_blended(VALUE self, VALUE text, VALUE fg)
{
return render(render_blended, self, text, fg, Qnil);
}
|
#render_shaded(text, fg, bg) ⇒ SDL2::Surface
270 271 272 273 |
# File 'ttf.c', line 270
static VALUE TTF_render_shaded(VALUE self, VALUE text, VALUE fg, VALUE bg)
{
return render(TTF_RenderUTF8_Shaded, self, text, fg, bg);
}
|
#render_solid(text, fg) ⇒ SDL2::Surface
247 248 249 250 |
# File 'ttf.c', line 247
static VALUE TTF_render_solid(VALUE self, VALUE text, VALUE fg)
{
return render(render_solid, self, text, fg, Qnil);
}
|
#size_text(text) ⇒ [Integer, Integer]
Returns a pair of width and height of the rendered surface
201 202 203 204 205 206 207 |
# File 'ttf.c', line 201
static VALUE TTF_size_text(VALUE self, VALUE text)
{
int w, h;
text = rb_str_export_to_enc(text, rb_utf8_encoding());
HANDLE_TTF_ERROR(TTF_SizeUTF8(Get_TTF_Font(self), StringValueCStr(text), &w, &h));
return rb_ary_new3(2, INT2NUM(w), INT2NUM(h));
}
|