sdljava.ttf

Class SDLTrueTypeFont

public class SDLTrueTypeFont extends Object

An instance of TTF_Font. All functions which operate on a TTF_Font structure from SDL_ttf may be found in this class.

Note: glyphMetrics() method currently is not working.

Version: $Id: SDLTrueTypeFont.java,v 1.4 2004/12/29 19:11:53 ivan_ganza Exp $

Author: Ivan Z. Ganza

See Also: SDLTTF

Field Summary
Stringpath
intptsize
SWIGTYPE_p__TTF_FontswigTTFFont
static intTTF_STYLE_BOLD
static intTTF_STYLE_ITALIC
static intTTF_STYLE_NORMAL
static intTTF_STYLE_UNDERLINE
Constructor Summary
protected SDLTrueTypeFont(SWIGTYPE_p__TTF_Font swigTTFFont, String path, int ptsize)
Creates a new SDLTrueTypeFont instance.
Method Summary
voidcloseFont()
Free the memory used by font, and free font itself as well.
protected voidfinalize()
intfontAscent()
Get the maximum pixel ascent of all glyphs of the loaded font.
intfontDescent()
Get the maximum pixel descent of all glyphs of the loaded font.
intfontHeight()
Get the maximum pixel height of all glyphs of the loaded font.
intfontLineSkip()
et the reccomended pixel height of a rendered line of text of the loaded font.
intgetFontStyle()
Get the rendering style of the loaded font.
StringgetPath()
Get the path to the font file
intgetPTSize()
Get the pt size
SWIGTYPE_p__TTF_FontgetSwigTTFFont()
Gets the value of swigTTFFont
GlyphMetricsglyphMetrics(char c)
Gets the glyph metrics from the font file.
SDLSurfacerenderTextBlended(String text, SDLColor fg)
Create a 32-bit ARGB surface and render the given glyph at high quality, using alpha blending to dither the font with the given color.
SDLSurfacerenderTextShaded(String text, SDLColor fg, SDLColor bg)
Create an 8-bit palettized surface and render the given text at fast quality with the given font and color.
SDLSurfacerenderTextSolid(String text, SDLColor fg)
Create an 8-bit palettized surface and render the given text at fast quality with the given font and color.
voidsetFontStyle(int style)
Set the rendering style of the loaded font.
voidsetSwigTTFFont(SWIGTYPE_p__TTF_Font argSwigTTFFont)
Sets the value of swigTTFFont
StringtoString()
Return a string represenation of this object

Field Detail

path

String path

ptsize

int ptsize

swigTTFFont

SWIGTYPE_p__TTF_Font swigTTFFont

TTF_STYLE_BOLD

public static final int TTF_STYLE_BOLD

TTF_STYLE_ITALIC

public static final int TTF_STYLE_ITALIC

TTF_STYLE_NORMAL

public static final int TTF_STYLE_NORMAL

TTF_STYLE_UNDERLINE

public static final int TTF_STYLE_UNDERLINE

Constructor Detail

SDLTrueTypeFont

protected SDLTrueTypeFont(SWIGTYPE_p__TTF_Font swigTTFFont, String path, int ptsize)
Creates a new SDLTrueTypeFont instance.

Parameters: swigTTFFont a SWIGTYPE_p__TTF_Font value

Method Detail

closeFont

public void closeFont()
Free the memory used by font, and free font itself as well. Do not use font after this without loading a new font to it.

Parameters: font The font to free

Throws: SDLException if an error occurs

finalize

protected void finalize()

fontAscent

public int fontAscent()
Get the maximum pixel ascent of all glyphs of the loaded font. This can also be interpreted as the distance from the top of the font to the baseline. It could be used when drawing an individual glyph relative to a top point, by combining it with the glyph's maxy metric to resolve the top of the rectangle used when blitting the glyph on the screen.

rect.y = top + TTF_FontAscent(font) - glyph_metric.maxy;

Returns: The maximum pixel ascent of all glyphs in the font.

fontDescent

public int fontDescent()
Get the maximum pixel descent of all glyphs of the loaded font. This can also be interpreted as the distance from the baseline to the bottom of the font. It could be used when drawing an individual glyph relative to a bottom point, by combining it with the glyph's maxy metric to resolve the top of the rectangle used when blitting the glyph on the screen.

rect.y = bottom - TTF_FontDescent(font) - glyph_metric.maxy;

Returns: The maximum pixel height of all glyphs in the font.

fontHeight

public int fontHeight()
Get the maximum pixel height of all glyphs of the loaded font. 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.

Returns: The maximum pixel height of all glyphs in the font.

fontLineSkip

public int fontLineSkip()
et the reccomended pixel height of a rendered line of text of the loaded font. This is usually larger than the TTF_FontHeight of the font.

Returns: The maximum pixel height of all glyphs in the font.

getFontStyle

public int getFontStyle()
Get the rendering style of the loaded font.

Returns: The style as a bitmask composed of the TTF_* defines

Throws: SDLException if an error occurs

getPath

public String getPath()
Get the path to the font file

Returns: the path to the font file

getPTSize

public int getPTSize()
Get the pt size

Returns: the pt size

getSwigTTFFont

public SWIGTYPE_p__TTF_Font getSwigTTFFont()
Gets the value of swigTTFFont

Returns: the value of swigTTFFont

glyphMetrics

public GlyphMetrics glyphMetrics(char c)
Gets the glyph metrics from the font file.

Parameters: c a char value

Returns: the glyph metrics from the font file as a GlyphMetrics value

Throws: SDLException if an error occurs

renderTextBlended

public SDLSurface renderTextBlended(String text, SDLColor fg)
Create a 32-bit ARGB surface and render the given glyph at high quality, using alpha blending to dither the font with the given color. The glyph is rendered without any padding or centering in the X direction, and aligned normally in the Y direction.

Parameters: text The text to render fg The foreground color

Returns: a SDLSurface with the rendered text

Throws: SDLException if an error occurs

renderTextShaded

public SDLSurface renderTextShaded(String text, SDLColor fg, SDLColor bg)
Create an 8-bit palettized surface and render the given text at fast quality with the given font and color. The 0 pixel is the colorkey, giving a transparent background, and the 1 pixel is set to the text color.

Parameters: text a String value fg a SDLColor value bg a SDLColor value

Returns: a SDLSurface value

Throws: SDLException if an error occurs

renderTextSolid

public SDLSurface renderTextSolid(String text, SDLColor fg)
Create an 8-bit palettized surface and render the given text at fast quality with the given font and color. The 0 pixel is the colorkey, giving a transparent background, and the 1 pixel is set to the text color.

Parameters: text The text to render fg The foreground color

Returns: a SDLSurface with the rendered text

Throws: SDLException if an error occurs

setFontStyle

public void setFontStyle(int style)
Set the rendering style of the loaded font.

NOTE: This will flush the internal cache of previously rendered glyphs, even if there is no change in style, so it may be best to check the current style using TTF_GetFontStyle first.

NOTE: I've seen that combining TTF_STYLE_UNDERLINE with anything can cause a segfault, other combinations may also do this. Some brave soul may find the cause of this and fix it...

NOTE: Rendered text formatted with TTF_STYLE_BOLD is hollow on the inside (wireframe like) for some reason when you use TTF_?RenderSolid. It displayed ok if you use TTF_?RenderBlended.

Parameters: style A bitmask of the desired style composed from the TTF_STYLE_* defined values.

Throws: SDLException if an error occurs

setSwigTTFFont

public void setSwigTTFFont(SWIGTYPE_p__TTF_Font argSwigTTFFont)
Sets the value of swigTTFFont

Parameters: argSwigTTFFont Value to assign to this.swigTTFFont

toString

public String toString()
Return a string represenation of this object

Returns: a String represenation of this object