com.threerings.opengl.gui.text
Class StringTextFactory

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

public class StringTextFactory
extends TextFactory

Formats text by using the AWT to render runs of text into a bitmap and then texturing a quad with the result. This text factory handles a simple styled text syntax:

 @=b(this text would be bold)
 @=i(this text would be italic)
 @=s(this text would be striked-through)
 @=u(this text would be underlined)
 @=bi(this text would be bold and italic)
 @=bi#FFCC99(this text would be bold, italic and pink)
 


Nested Class Summary
protected static class StringTextFactory.GlowKey
           
protected static class StringTextFactory.StyleRun
           
 
Field Summary
protected  boolean _antialias
           
protected  Map<TextAttribute,Font> _attrs
           
protected  Map<StringTextFactory.GlowKey,BufferedImage> _cachedGlowBGs
           
protected  Map<StringTextFactory.GlowKey,BufferedImage> _cachedGlowFGs
           
protected  StringTextFactory.GlowKey _gkey
           
protected  int _height
           
protected static boolean _isMacOS
           
protected  BufferedImage _stub
           
protected static char BOLD
           
protected static char COLOR
           
protected static char ITALIC
           
protected static char NONE
           
protected static char STRIKE
           
protected static char UNDERLINE
           
 
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
StringTextFactory(Font font, boolean antialias)
          Creates a string text factory with the supplied font.
 
Method Summary
protected  int computeWidth(char c)
          Helper function.
 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  Text createText(String origText, TextLayout layout, Color4f color, int effect, int effectSize, Color4f effectColor, int length, boolean useAdvance)
          Helper function.
protected  BufferedImage getGlowBackground(char c, int height, Color4f color, int effectSize)
          Helper function.
protected  BufferedImage getGlowForeground(char c, int height, Color4f color, int effectSize)
          Helper function.
 int getHeight()
          Returns the height of our text.
protected  AttributedString parseStyledText(String text, Map<TextAttribute,Font> attrs, String[] bare, boolean style)
          Parses our simple styled text formatting codes and creates an attributed string to render them.
 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

_antialias

protected boolean _antialias

_height

protected int _height

_stub

protected BufferedImage _stub

_attrs

protected Map<TextAttribute,Font> _attrs

_cachedGlowBGs

protected Map<StringTextFactory.GlowKey,BufferedImage> _cachedGlowBGs

_cachedGlowFGs

protected Map<StringTextFactory.GlowKey,BufferedImage> _cachedGlowFGs

_gkey

protected StringTextFactory.GlowKey _gkey

_isMacOS

protected static boolean _isMacOS

NONE

protected static final char NONE
See Also:
Constant Field Values

BOLD

protected static final char BOLD
See Also:
Constant Field Values

ITALIC

protected static final char ITALIC
See Also:
Constant Field Values

UNDERLINE

protected static final char UNDERLINE
See Also:
Constant Field Values

STRIKE

protected static final char STRIKE
See Also:
Constant Field Values

COLOR

protected static final char COLOR
See Also:
Constant Field Values
Constructor Detail

StringTextFactory

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

Method Detail

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

createText

protected Text createText(String origText,
                          TextLayout layout,
                          Color4f color,
                          int effect,
                          int effectSize,
                          Color4f effectColor,
                          int length,
                          boolean useAdvance)
Helper function.


getGlowBackground

protected BufferedImage getGlowBackground(char c,
                                          int height,
                                          Color4f color,
                                          int effectSize)
Helper function.


getGlowForeground

protected BufferedImage getGlowForeground(char c,
                                          int height,
                                          Color4f color,
                                          int effectSize)
Helper function.


computeWidth

protected int computeWidth(char c)
Helper function.


parseStyledText

protected AttributedString parseStyledText(String text,
                                           Map<TextAttribute,Font> attrs,
                                           String[] bare,
                                           boolean style)
Parses our simple styled text formatting codes and creates an attributed string to render them.