Class | Rubygame::TTF
In: | lib/rubygame/ttf.rb
Parent: | Object

IMPORTANT: this class only exists if SDL_ttf is available! Your code should check "defined?(Rubygame::TTF) != nil" to see if you can use this class, or be prepared to rescue from NameError.

TTF provides an interface to SDL_ttf, allowing TrueType Font files to be loaded and used to render text to Surfaces.

The TTF class must be initialized with the setup method before any TTF objects can be created or used.

### Methods

_render ascent bold bold= bold? descent height italic italic= italic? line_skip new quit render render_unicode render_utf8 setup size_text size_unicode size_utf8 underline underline= underline?

### Public Class methods

new( file, size )

Create a new TTF object, which can render text to a Surface with a particular font style and size.

file: | filename of the TrueType font to use. Should be a TTF or FON file.
size: | point size (based on 72DPI). (That means the height in pixels from the bottom of the descent to the top of the ascent.)

quit()

Clean up and quit SDL_ttf, making the TTF class unusable as a result (until it is setup again). This does not need to be called before Rubygame exits, as it will be done automatically.

setup()

Attempt to setup the TTF class for use by initializing SDL_ttf. This must be called before the TTF class can be used. Raises SDLError if there is a problem initializing SDL_ttf.

### Public Instance methods

_render( text, smooth, color, back, shaded, blended, solid )

Does the heavy lifting for the render methods.

ascent()

Return the biggest ascent (baseline to top; in pixels) of all glyphs in the font.

bold()

Alias for bold?

bold=( enabled )

Enable or disable bold mode for this font. Returns the old value.

bold?()

True if bold mode is enabled for this font.

descent()

Return the biggest descent (baseline to bottom; in pixels) of all glyphs in the font.

height()

Return the biggest height (bottom to top; in pixels) of all glyphs in the font.

italic()

Alias for italic?

italic=( enabled )

Enable or disable italic mode for this font. Returns the old value.

italic?()

True if italic mode is enabled for this font.

line_skip()

Return the recommended distance (in pixels) from a point on a line of text to the same point on the line of text below it.

render( text, smooth, color, back=nil )

Renders a string to a Surface with the font‘s style and the given color(s).

text: | the text string to render
smooth: | Use anti-aliasing if true. Enabling this makes the text look much nicer (smooth curves), but is much slower.
color: | the color to render the text, in the form [r,g,b]
back: | the color to use as a background for the text. This option can be omitted to have a transparent background.

render_unicode( text, smooth, color, back=nil )

Renders a Unicode string to a Surface with the font‘s style and the given color(s).

text: | the text string to render
smooth: | Use anti-aliasing if true. Enabling this makes the text look much nicer (smooth curves), but is much slower.
color: | the color to render the text, in the form [r,g,b]
back: | the color to use as a background for the text. This option can be omitted to have a transparent background.

render_utf8( text, smooth, color, back=nil )

Renders a UTF-8 string to a Surface with the font‘s style and the given color(s).

text: | the text string to render
smooth: | Use anti-aliasing if true. Enabling this makes the text look much nicer (smooth curves), but is much slower.
color: | the color to render the text, in the form [r,g,b]
back: | the color to use as a background for the text. This option can be omitted to have a transparent background.

size_text( text )

The width and height the text would be if it were rendered, without the overhead of actually rendering it.

size_unicode( text )

The width and height the Unicode text would be if it were rendered, without the overhead of actually rendering it.

size_utf8( text )

The width and height the UTF-8 encoded text would be if it were rendered, without the overhead of actually rendering it.

underline()

Alias for underline?

underline=( enabled )

Enable or disable underline mode for this font. Returns the old value.

underline?()

True if underline mode is enabled for this font.

[Validate]