org.jrabbit.base.graphics.font.renderer
Class AngelCodeRenderer

java.lang.Object
  extended by org.jrabbit.base.graphics.font.renderer.AcceleratedFontRenderer
      extended by org.jrabbit.base.graphics.font.renderer.AngelCodeRenderer
All Implemented Interfaces:
Createable, DataController, Destroyable, FontRenderer

public class AngelCodeRenderer
extends AcceleratedFontRenderer

JRabbit uses a couple of resources from the Slick game library (with slight modifications). AngelCodeRenderer is one of these. Basically everything is directly from Slick, so all credit goes there. However, I've made a few changes to A) suit jRabbit's needs more precisely, and to B) slim things down, make the class more OO and have less warnings. A few thoughts on the use of this class: An AngelCodeRenderer should load much faster than a UnicodeRenderer, since everything is pre-calculated and pre-rendered. Additionally, since you can directly edit the source image for the text, you can be as detailed as you like with how the fonts look in-game. However, it's a bit more limited - it only supports 256 characters, and if you want to have a font that's even only slightly different, you essentially need to make another font from the tool.

Author:
Kevin Glass, modified by Chris Molini.

Nested Class Summary
private  class AngelCodeRenderer.CharDef
          The definition of a single character read from an AngelCode font file.
 
Nested classes/interfaces inherited from class org.jrabbit.base.graphics.font.renderer.AcceleratedFontRenderer
AcceleratedFontRenderer.TextDL
 
Field Summary
private  AngelCodeRenderer.CharDef[] chars
          The list of defined characters for rendering.
private  Image image
          AngelCode uses a single image to manage its characters.
private  int lineHeight
          The height of a line of text.
private static int MAX_CHAR
          To streamline font rendering/interpretation, only the first 256 characters (a.k.a.
 
Fields inherited from class org.jrabbit.base.graphics.font.renderer.AcceleratedFontRenderer
accelerate, baseDL, displayLists, eldestDL, eldestDLID, maxDL
 
Constructor Summary
AngelCodeRenderer(java.lang.String fontFilepath, java.lang.String imageFilepath)
          Creates a new font based on a font definition from AngelCode's tool and the image that goes with it.
 
Method Summary
 void destroy()
          Wipes the image and all stored displayLists.
protected  void drawString(java.lang.String text)
          Renders a string of text to the screen.
 float lineHeight()
          Accesses the stored height of the line, as read from the font file.
 float measureString(java.lang.String text)
          Determines the width of a String when rendered.
private  AngelCodeRenderer.CharDef parseChar(java.lang.String line)
          Parse a single character definition from the font file.
private  void parseFontFile(java.io.InputStream fontFilestream)
          Parses the font file.
 void smoothFont(boolean smooth)
          Decides whether or not the font image should have a smoothing filter applied when it is scaled up.
 boolean smoothing()
          Decides whether or not the font image should have a smoothing filter applied when it is scaled up.
 boolean valid()
          Determines whether or not an AngelCodeRenderer is considered valid for use.
 
Methods inherited from class org.jrabbit.base.graphics.font.renderer.AcceleratedFontRenderer
create, render, useAcceleration, widthOf
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

image

private Image image
AngelCode uses a single image to manage its characters. This contains the texture data for the active font, and all stored characters reference it.


MAX_CHAR

private static final int MAX_CHAR
To streamline font rendering/interpretation, only the first 256 characters (a.k.a. the ASCII set) are allowed to be used.

See Also:
Constant Field Values

chars

private AngelCodeRenderer.CharDef[] chars
The list of defined characters for rendering. The numerical value of a character corresponds to its position in the array.


lineHeight

private int lineHeight
The height of a line of text.

Constructor Detail

AngelCodeRenderer

public AngelCodeRenderer(java.lang.String fontFilepath,
                         java.lang.String imageFilepath)
Creates a new font based on a font definition from AngelCode's tool and the image that goes with it.

Parameters:
fontFilepath - The location of the font definition file.
imageFilepath - The location of the font image.
Method Detail

parseFontFile

private void parseFontFile(java.io.InputStream fontFilestream)
Parses the font file. This file contains all information used to map characters to an image.

Parameters:
fontFilestream - The input stream from the font file.

parseChar

private AngelCodeRenderer.CharDef parseChar(java.lang.String line)
Parse a single character definition from the font file.

Parameters:
line - The line of text from the file that contains character information.
Returns:
The character definition from the line.

smoothFont

public void smoothFont(boolean smooth)
Decides whether or not the font image should have a smoothing filter applied when it is scaled up. By default this is true.

Parameters:
smooth - Whether or not to smooth the font when it is scaled.

smoothing

public boolean smoothing()
Decides whether or not the font image should have a smoothing filter applied when it is scaled up. By default this is true.

Parameters:
smooth - Whether or not to smooth the font when it is scaled.

valid

public boolean valid()
Determines whether or not an AngelCodeRenderer is considered valid for use. Since the image that holds character data is bound to the life of the font, this call simply checks to see if that image is intact.

Returns:
Whether or not the AngelCodeRender can render text.

destroy

public void destroy()
Wipes the image and all stored displayLists.


drawString

protected void drawString(java.lang.String text)
Renders a string of text to the screen.

Specified by:
drawString in class AcceleratedFontRenderer
Parameters:
text - The text to be rendered.

lineHeight

public float lineHeight()
Accesses the stored height of the line, as read from the font file.

Returns:
The height of a line of text.

measureString

public float measureString(java.lang.String text)
Determines the width of a String when rendered.

Specified by:
measureString in class AcceleratedFontRenderer
Parameters:
text - The String to measure.
Returns:
The width of the String when rendered.