sdljava.ttf
Class SDLTrueTypeFont

java.lang.Object
  extended by sdljava.ttf.SDLTrueTypeFont

public class SDLTrueTypeFont
extends java.lang.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
(package private)  java.lang.String path
           
(package private)  int ptsize
           
(package private)  SWIGTYPE_p__TTF_Font swigTTFFont
           
static int TTF_STYLE_BOLD
           
static int TTF_STYLE_ITALIC
           
static int TTF_STYLE_NORMAL
           
static int TTF_STYLE_UNDERLINE
           
 
Constructor Summary
protected SDLTrueTypeFont(SWIGTYPE_p__TTF_Font swigTTFFont, java.lang.String path, int ptsize)
          Creates a new SDLTrueTypeFont instance.
 
Method Summary
 void closeFont()
          Free the memory used by font, and free font itself as well.
protected  void finalize()
           
 int fontAscent()
          Get the maximum pixel ascent of all glyphs of the loaded font.
 int fontDescent()
          Get the maximum pixel descent of all glyphs of the loaded font.
 int fontHeight()
          Get the maximum pixel height of all glyphs of the loaded font.
 int fontLineSkip()
          et the reccomended pixel height of a rendered line of text of the loaded font.
 int getFontStyle()
          Get the rendering style of the loaded font.
 java.lang.String getPath()
          Get the path to the font file
 int getPTSize()
          Get the pt size
 SWIGTYPE_p__TTF_Font getSwigTTFFont()
          Gets the value of swigTTFFont
 GlyphMetrics glyphMetrics(char c)
          Gets the glyph metrics from the font file.
 SDLSurface renderTextBlended(java.lang.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.
 SDLSurface renderTextShaded(java.lang.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.
 SDLSurface renderTextSolid(java.lang.String text, SDLColor fg)
          Create an 8-bit palettized surface and render the given text at fast quality with the given font and color.
 void setFontStyle(int style)
          Set the rendering style of the loaded font.
 void setSwigTTFFont(SWIGTYPE_p__TTF_Font argSwigTTFFont)
          Sets the value of swigTTFFont
 java.lang.String toString()
          Return a string represenation of this object
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TTF_STYLE_NORMAL

public static final int TTF_STYLE_NORMAL
See Also:
Constant Field Values

TTF_STYLE_BOLD

public static final int TTF_STYLE_BOLD
See Also:
Constant Field Values

TTF_STYLE_ITALIC

public static final int TTF_STYLE_ITALIC
See Also:
Constant Field Values

TTF_STYLE_UNDERLINE

public static final int TTF_STYLE_UNDERLINE
See Also:
Constant Field Values

swigTTFFont

SWIGTYPE_p__TTF_Font swigTTFFont

path

java.lang.String path

ptsize

int ptsize
Constructor Detail

SDLTrueTypeFont

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

Parameters:
swigTTFFont - a SWIGTYPE_p__TTF_Font value
Method Detail

getSwigTTFFont

public SWIGTYPE_p__TTF_Font getSwigTTFFont()
Gets the value of swigTTFFont

Returns:
the value of swigTTFFont

setSwigTTFFont

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

Parameters:
argSwigTTFFont - Value to assign to this.swigTTFFont

getPath

public java.lang.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

renderTextSolid

public SDLSurface renderTextSolid(java.lang.String text,
                                  SDLColor fg)
                           throws SDLException
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

renderTextShaded

public SDLSurface renderTextShaded(java.lang.String text,
                                   SDLColor fg,
                                   SDLColor bg)
                            throws SDLException
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

renderTextBlended

public SDLSurface renderTextBlended(java.lang.String text,
                                    SDLColor fg)
                             throws SDLException
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

setFontStyle

public void setFontStyle(int style)
                  throws SDLException
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

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

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.

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.

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.

glyphMetrics

public GlyphMetrics glyphMetrics(char c)
                          throws SDLException
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

closeFont

public void closeFont()
               throws SDLException
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

toString

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

Overrides:
toString in class java.lang.Object
Returns:
a String represenation of this object

finalize

protected void finalize()
Overrides:
finalize in class java.lang.Object