com.gif4j
Class TextPainter

java.lang.Object
  extended bycom.gif4j.TextPainter

public class TextPainter
extends java.lang.Object

TextPainter instances can be used to draw text across the single or multiple lines on BufferedImage(s).


Constructor Summary
TextPainter(java.awt.Font font)
          Constructs TextPainter object with the specified Font and set by default foreground Paint attribute to Color.BLACK, outline Paint attribute to Color.WHITE, background Color attribute to full-transparent Color and anti-aliased to 'TRUE'.
TextPainter(java.awt.Font font, boolean antialiased)
          Constructs TextPainter object with the specified Font and the specified anti-aliased attribute.
TextPainter(java.awt.Font font, java.awt.Paint foregroundPaint, java.awt.Paint outlinePaint, java.awt.Color backgroundColor, boolean antialiased)
          Constructs TextPainter object with the specified Font attribute, foreground Paint attribute, outline Paint attribute, background Color attribute and anti-aliased attribute.
 
Method Summary
 java.awt.Color getBackgroundColor()
          Returns the current background Color of the TextPainter context.
 java.awt.Font getFont()
          Gets the current font.
 java.awt.Paint getForegroundPaint()
          Returns the current foreground Paint of the TextPainter context.
 java.awt.Paint getOutlinePaint()
          Returns the current outline Paint of the TextPainter context.
 boolean isAntialiased()
          Gets the current antialiased attribute
 java.awt.image.BufferedImage renderString(java.lang.String str)
          Renders single string using the specified attributes from the TextPainter context.
 java.awt.image.BufferedImage renderString(java.lang.String str, boolean outline)
          Renders single string using the specified attributes from the TextPainter context.
 java.awt.image.BufferedImage renderText(java.lang.String text, int width, boolean outline, boolean centralized)
          Renders line-wraped to the specified width text using the specified attributes from the TextPainter context.
 void setAntialiased(boolean antialiased)
          Sets this painter context's antialiased attribute to the specified value.
 void setBackgroundColor(java.awt.Color backgroundColor)
          Sets the background Color attribute for the TextPainter context.
 void setFont(java.awt.Font font)
          Sets this painter context's font to the specified font.
 void setForegroundPaint(java.awt.Paint foregroundPaint)
          Sets the foreground Paint attribute for the TextPainter context.
 void setOutlinePaint(java.awt.Paint outlinePaint)
          Sets the outline Paint attribute for the TextPainter context.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TextPainter

public TextPainter(java.awt.Font font)
Constructs TextPainter object with the specified Font and set by default foreground Paint attribute to Color.BLACK, outline Paint attribute to Color.WHITE, background Color attribute to full-transparent Color and anti-aliased to 'TRUE'.

Parameters:
font - this painter context's font
Throws:
java.lang.NullPointerException - If font is null
See Also:
Font

TextPainter

public TextPainter(java.awt.Font font,
                   boolean antialiased)
Constructs TextPainter object with the specified Font and the specified anti-aliased attribute. Set by default foreground Paint attribute to Color.BLACK, outline Paint attribute to Color.WHITE, background Color attribute to full-transparent Color.

Parameters:
font - this painter context's font
antialiased - if true then render anti-aliased text
Throws:
java.lang.NullPointerException - If font is null
See Also:
Font

TextPainter

public TextPainter(java.awt.Font font,
                   java.awt.Paint foregroundPaint,
                   java.awt.Paint outlinePaint,
                   java.awt.Color backgroundColor,
                   boolean antialiased)
Constructs TextPainter object with the specified Font attribute, foreground Paint attribute, outline Paint attribute, background Color attribute and anti-aliased attribute.

Parameters:
font - this painter context's font
foregroundPaint - the Paint object to be used to generate color or pattern during the text rendering process, or null
outlinePaint - the Paint object to be used to generate color or pattern during the outline rendering process, or null
backgroundColor - the Color object to be used to generate color during the background rendering process, or null
antialiased - if true then render anti-aliased text
Throws:
java.lang.NullPointerException - If font is null
See Also:
Font, Paint
Method Detail

getFont

public java.awt.Font getFont()
Gets the current font.

Returns:
this painter context's Font

isAntialiased

public boolean isAntialiased()
Gets the current antialiased attribute

Returns:
the current antialiased attribute

setFont

public void setFont(java.awt.Font font)
Sets this painter context's font to the specified font.

Parameters:
font - Font to render
See Also:
Font

setAntialiased

public void setAntialiased(boolean antialiased)
Sets this painter context's antialiased attribute to the specified value.

Parameters:
antialiased -

getForegroundPaint

public java.awt.Paint getForegroundPaint()
Returns the current foreground Paint of the TextPainter context.

Returns:
the current foreground Paint, which defines a color or pattern.
See Also:
Paint

setForegroundPaint

public void setForegroundPaint(java.awt.Paint foregroundPaint)
Sets the foreground Paint attribute for the TextPainter context. Calling this method with a null Paint object does not have any effect on the current foreground Paint attribute of this TextPainter.

Parameters:
foregroundPaint - the Paint object to be used to generate color during the rendering process, or null
See Also:
getForegroundPaint(), Paint

getBackgroundColor

public java.awt.Color getBackgroundColor()
Returns the current background Color of the TextPainter context.

Returns:
the current background Color.
See Also:
Color

setBackgroundColor

public void setBackgroundColor(java.awt.Color backgroundColor)
Sets the background Color attribute for the TextPainter context. Calling this method with a null Color object does not have any effect on the current background Color attribute of this TextPainter.

Parameters:
backgroundColor - the Color object to be used to generate color during the rendering process, or null
See Also:
getBackgroundColor(), Color

getOutlinePaint

public java.awt.Paint getOutlinePaint()
Returns the current outline Paint of the TextPainter context.

Returns:
the current outline Paint, which defines a color or pattern.
See Also:
Paint

setOutlinePaint

public void setOutlinePaint(java.awt.Paint outlinePaint)
Sets the outline Paint attribute for the TextPainter context. Calling this method with a null Paint object does not have any effect on the current outline Paint attribute of this TextPainter.

Parameters:
outlinePaint - the Paint object to be used to generate color during the rendering process, or null
See Also:
getOutlinePaint(), Paint

renderString

public java.awt.image.BufferedImage renderString(java.lang.String str)
Renders single string using the specified attributes from the TextPainter context. Outline Paint attribute is ignored. Size of the returned BufferedImage object is equal to visual bounds of the rendered string.

Parameters:
str - string to render
Returns:
BufferedImage object which contains the specified rendered string
Throws:
java.lang.NullPointerException - If string to render is null
See Also:
setFont(java.awt.Font), setForegroundPaint(java.awt.Paint), setAntialiased(boolean), setBackgroundColor(java.awt.Color)

renderString

public java.awt.image.BufferedImage renderString(java.lang.String str,
                                                 boolean outline)
Renders single string using the specified attributes from the TextPainter context. Size of the returned BufferedImage object is equal to visual bounds of the specified string to render.

Parameters:
str - string to render
outline - if true then render the string outlined
Returns:
BufferedImage object which contains the specified rendered string
Throws:
java.lang.NullPointerException - If string to render is null
See Also:
setFont(java.awt.Font), setForegroundPaint(java.awt.Paint), setOutlinePaint(java.awt.Paint), setAntialiased(boolean), setBackgroundColor(java.awt.Color)

renderText

public java.awt.image.BufferedImage renderText(java.lang.String text,
                                               int width,
                                               boolean outline,
                                               boolean centralized)
Renders line-wraped to the specified width text using the specified attributes from the TextPainter context. Width of the returned BufferedImage object is equal to the specified width. Height is automatically extended to contain all text lines.

Parameters:
text - text to render
width - the specified width to line-wrap text
outline - if true then render the string outlined
centralized - if true then the specified text is centralized
Returns:
BufferedImage object which contains the specified rendered text
Throws:
java.lang.NullPointerException - If text to render is null
See Also:
setFont(java.awt.Font), setForegroundPaint(java.awt.Paint), setOutlinePaint(java.awt.Paint), setAntialiased(boolean), setBackgroundColor(java.awt.Color)