18.17.2Class TTFFont

Font representation of SDL TTF Class.

Class TTFFont

This class encapsulates all the font-specific methods and accessros that are provided by th SDL_ttf library.

Note: This class is private; it cannot be directly instantiated, it must be created through TTF.OpenFont

Methods
FontAscentGet the maximum pixel ascent of all glyphs of the loaded font.
FontDescentGet the maximum pixel descent of all glyphs of the loaded font.
FontFaceFamilyNameDetermine the family name of this font.
FontFaceIsFixedWidthDetermines wether this font has fixed width or not.
FontFaceStyleNameDetermine the face style name of this font.
FontFacesGet the number of faces ("sub-fonts") available in the loaded font.
FontHeightGet the maximum pixel height of all glyphs of the loaded font.
FontLineSkipGet the recommended pixel height of a rendered line of text of the loaded font.
GetFontStyleGet font render style
GlyphMetricsReturns the metrics of a determined gliph in this font.
Render_BlendedRenders text on a final SDLSurface instance (medium).
Render_ShadedRenders text on a final SDLSurface instance (medium).
Render_SolidRenders text on a final SDLSurface instance (fast).
SetFontStyleSet the rendering style of the loaded font.
SizeTextDetermine rendering size of a text as it would be rendere on ttf.

Methods

FontAscent

Get the maximum pixel ascent of all glyphs of the loaded font.

TTFFont.FontAscent()
ReturnHeight of the ascent, in pixels.

FontDescent

Get the maximum pixel descent of all glyphs of the loaded font.

TTFFont.FontDescent()
ReturnHeight of the descent, in pixels.

FontFaceFamilyName

Determine the family name of this font.

TTFFont.FontFaceFamilyName()
ReturnA string containing the family name of this font.

FontFaceIsFixedWidth

Determines wether this font has fixed width or not.

TTFFont.FontFaceIsFixedWidth()
ReturnTrue if the font is fixed width, false otherise.

FontFaceStyleName

Determine the face style name of this font.

TTFFont.FontFaceStyleName()
ReturnA string containing the style name, or nil if not available.

FontFaces

Get the number of faces ("sub-fonts") available in the loaded font.

TTFFont.FontFaces()
ReturnNumber of faces stored in this font.

FontHeight

Get the maximum pixel height of all glyphs of the loaded font.

TTFFont.FontHeight()
ReturnHeight of the font, in pixels.

You may use this height for rendering text as close together vertically as possible, though adding at least one pixel height to it will space it so they can't touch. Remember that SDL_ttf doesn't handle multiline printing, so you are responsible for line spacing, see the TTF_FontLineSkip as well.

FontLineSkip

Get the recommended pixel height of a rendered line of text of the loaded font.

TTFFont.FontLineSkip()
ReturnRecommended height, in pixels.

GetFontStyle

Get font render style

TTFFont.GetFontStyle()
ReturnStyle currently active on this font.

Returned style can be TTF.STYLE_NORMAL or a bitfield or'd combination of the following:

- TTF.STYLE_BOLD

GlyphMetrics

Returns the metrics of a determined gliph in this font.

TTFFont.GlyphMetrics( charId, [metrics] )
charId the ID of the caracter of which the gliph are required.
metrics An instance of class TTFMetrics (or providing the same properties).
ReturnAn instance of class TTFMetrics or nil.

This method stores the glyph metrics of character determined by the given charId into the minx, maxx, miny, maxy and advance properties of the object given as second parameter. If that object is not given, this method creates an instance of the TTFMetrics class and returns it. It is advisable to use repeatedly such instance to avoid useless garbage generation.

The function may fail if the charId is not found.

IF a fitting instace is provided as a parameter, then that value is returned. On failure, nil is returned.

Note: as object are always evaluated to true, the fact that this function returns an object can be used to determine if it was succesful or not.

Render_Blended

Renders text on a final SDLSurface instance (medium).

TTFFont.Render_Blended( string, color )
string A string or a character to be rendered.
color an SDLColor instance containing the color of the string.
Returnan SDLSurface containing the rendered string.
Raise
SDLError on failure.

The first parameter may be a string or a numeric value, which will be interpreted as a single glyph to be rendered.

The color parameter may be any object providing r, g and b properties.

The function may fail if the some of the characters in the string cannot be represented with by this font.

Note: This function translates the input string in an UTF-8 string and then feeds it into TTF_RenderUTF_Solid as this is guaranteed to work with every character known by falcon and across any platform.

Render_Shaded

Renders text on a final SDLSurface instance (medium).

TTFFont.Render_Shaded( string, color, bgcolor )
string A string or a character to be rendered.
color an SDLColor instance containing the color of the string.
bgcolor an SDLColor instance containing the color of the background.
Returnan SDLSurface containing the rendered string.
Raise
SDLError on failure.

The first parameter may be a string or a numeric value, which will be interpreted as a single glyph to be rendered.

The color parameter may be any object providing r, g and b properties.

The function may fail if the some of the characters in the string cannot be represented with by this font.

Note: This function translates the input string in an UTF-8 string and then feeds it into TTF_RenderUTF_Solid as this is guaranteed to work with every character known by falcon and across any platform.

Render_Solid

Renders text on a final SDLSurface instance (fast).

TTFFont.Render_Solid( string, color )
string A string or a character to be rendered.
color an SDLColor instance containing the color of the string.
Returnan SDLSurface containing the rendered string.
Raise
SDLError on failure.

The first parameter may be a string or a numeric value, which will be interpreted as a single glyph to be rendered.

The color parameter may be any object providing r, g and b properties.

The function may fail if the some of the characters in the string cannot be represented with by this font.

Note: This function translates the input string in an UTF-8 string and then feeds it into TTF_RenderUTF_Solid as this is guaranteed to work with every character known by falcon and across any platform.

SetFontStyle

Set the rendering style of the loaded font.

TTFFont.SetFontStyle( style )
style Render style of this font.

The parameter can be TTF.STYLE_NORMAL or a bitfield or'd combination of the following:

- TTF.STYLE_BOLD

SizeText

Determine rendering size of a text as it would be rendere on ttf.

TTFFont.SizeText( string, [metrics] )
string A string to be rendered.
metrics An instance of class TTFMetrics (or providing the same properties).
ReturnAn instance of class TTFMetrics.

This method stores the width and height of the rendered string on the properties w and h of a given object.

The function may fail if the some of the characters in the string cannot be represented with by this font.

Note: This function translates the input string in an UTF-8 string and then feeds it into TTF_SizeUTF8 as this is guaranteed to work with every character known by falcon and across any platform.

IF a fitting instace is provided as a parameter, then that value is returned. On failure, nil is returned.

Note: as object are always evaluated to true, the fact that this function returns an object can be used to determine if it was succesful or not.

Made with http://www.falconpl.org