com.threerings.opengl.gui.text
Class CharacterTextFactory

java.lang.Object
  extended by com.threerings.opengl.gui.text.TextFactory
      extended by com.threerings.opengl.gui.text.CharacterTextFactory
All Implemented Interfaces:
UIConstants

public class CharacterTextFactory
extends TextFactory
implements UIConstants

Formats text by rendering individual characters into a set of shared textures, then returning Text instances that render groups of quads, one for each character.


Nested Class Summary
protected  class CharacterTextFactory.Glyph
          A single glyph.
protected  class CharacterTextFactory.GlyphTexture
          A shared texture.
 
Field Summary
protected  Font _font
          The font being rendered by this factory.
protected  HashIntMap<CharacterTextFactory.Glyph> _glyphs
          Cached glyphs.
protected  Graphics2D _graphics
           
protected static HashMap<Tuple<Font,Boolean>,CharacterTextFactory> _instances
          Shared instances.
protected  FontMetrics _metrics
          The font metrics.
protected  BufferedImage _scratch
          A scratchpad image and its graphics context.
protected  CharacterTextFactory.GlyphTexture _texture
          The glyph texture currently being populated.
protected static int TEXTURE_SIZE
          The width/height of the glyph textures.
 
Fields inherited from interface com.threerings.opengl.gui.UIConstants
BOTTOM, CENTER, DEFAULT_SIZE, DEFAULT_SPACING, GLOW, HORIZONTAL, LEFT, NORMAL, OUTLINE, OVERLAPPING, PLAIN, RIGHT, SHADOW, TOP, VERTICAL
 
Constructor Summary
CharacterTextFactory(Font font, boolean antialias)
          Creates a character text factory with the supplied font.
 
Method Summary
protected  TextureUnit[] addGlyphToTexture(Renderer renderer, int width, int height, float[] tcoords)
          Inserts the glyph image in the scratch pad into the current texture (creating a new texture if there is no current texture or the current texture doesn't have enough room), returns the texture unit data, and populates the supplied array with the texture coordinates.
 Text createText(String text, Color4f color, int effect, int effectSize, Color4f effectColor, boolean useAdvance)
          Creates a text instance using our the font configuration associated with this text factory and the foreground color, text effect and text effect color specified.
protected  IntTuple getBreakSpan(StringBuilder buf)
          Searches for an appropriate break span: the last region of whitespace preceeded by a non-whitespace character.
protected  CharacterTextFactory.Glyph getGlyph(char c)
          Returns the normal glyph for the given character.
protected  CharacterTextFactory.Glyph getGlyph(char c, int effect, int size)
          Returns the glyph for the given character with the given effect and effect size.
 int getHeight()
          Returns the height of our text.
static CharacterTextFactory getInstance(Font font, boolean antialias)
          Returns a shared factory instance.
 void render(Renderer renderer, String text, int x, int y, Color4f color)
          Renders a string directly, without creating a text object.
 Text[] wrapText(String text, Color4f color, int effect, int effectSize, Color4f effectColor, int maxWidth)
          Wraps a string into a set of text objects that do not exceed the specified width.
 
Methods inherited from class com.threerings.opengl.gui.text.TextFactory
createText
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_font

protected Font _font
The font being rendered by this factory.


_scratch

protected BufferedImage _scratch
A scratchpad image and its graphics context.


_graphics

protected Graphics2D _graphics

_metrics

protected FontMetrics _metrics
The font metrics.


_glyphs

protected HashIntMap<CharacterTextFactory.Glyph> _glyphs
Cached glyphs.


_texture

protected CharacterTextFactory.GlyphTexture _texture
The glyph texture currently being populated.


_instances

protected static HashMap<Tuple<Font,Boolean>,CharacterTextFactory> _instances
Shared instances.


TEXTURE_SIZE

protected static final int TEXTURE_SIZE
The width/height of the glyph textures.

See Also:
Constant Field Values
Constructor Detail

CharacterTextFactory

public CharacterTextFactory(Font font,
                            boolean antialias)
Creates a character text factory with the supplied font.

Method Detail

getInstance

public static CharacterTextFactory getInstance(Font font,
                                               boolean antialias)
Returns a shared factory instance.


render

public void render(Renderer renderer,
                   String text,
                   int x,
                   int y,
                   Color4f color)
Renders a string directly, without creating a text object.


getHeight

public int getHeight()
Description copied from class: TextFactory
Returns the height of our text.

Specified by:
getHeight in class TextFactory

createText

public Text createText(String text,
                       Color4f color,
                       int effect,
                       int effectSize,
                       Color4f effectColor,
                       boolean useAdvance)
Description copied from class: TextFactory
Creates a text instance using our the font configuration associated with this text factory and the foreground color, text effect and text effect color specified.

Specified by:
createText in class TextFactory
useAdvance - if true, the advance to the next insertion point will be included in the bounds of the created text (this is needed by editable text displays).

wrapText

public Text[] wrapText(String text,
                       Color4f color,
                       int effect,
                       int effectSize,
                       Color4f effectColor,
                       int maxWidth)
Description copied from class: TextFactory
Wraps a string into a set of text objects that do not exceed the specified width.

Specified by:
wrapText in class TextFactory

getGlyph

protected CharacterTextFactory.Glyph getGlyph(char c)
Returns the normal glyph for the given character.


getGlyph

protected CharacterTextFactory.Glyph getGlyph(char c,
                                              int effect,
                                              int size)
Returns the glyph for the given character with the given effect and effect size.


getBreakSpan

protected IntTuple getBreakSpan(StringBuilder buf)
Searches for an appropriate break span: the last region of whitespace preceeded by a non-whitespace character.

Returns:
the start and end indices of the span (inclusive), or null if no span was found.

addGlyphToTexture

protected TextureUnit[] addGlyphToTexture(Renderer renderer,
                                          int width,
                                          int height,
                                          float[] tcoords)
Inserts the glyph image in the scratch pad into the current texture (creating a new texture if there is no current texture or the current texture doesn't have enough room), returns the texture unit data, and populates the supplied array with the texture coordinates.