info.magnolia.cms.taglibs.util
Class Text2PngFactory

java.lang.Object
  extended by info.magnolia.cms.taglibs.util.Text2PngFactory

public class Text2PngFactory
extends Object

Class to generate PNG images from TrueType font strings. Originally by Philip McCarthy - http://chimpen.com http://chimpen.com/things/archives/001139.php

Author:
Philip McCarthy, Patrick Janssen

Constructor Summary
Text2PngFactory()
          Construct factory without setting font.
Text2PngFactory(String fontname, int fontsize)
          Construct factory with given font face and size.
Text2PngFactory(String fontname, int fontsize, String text)
          Construct factory with given font face and size.
 
Method Summary
 RenderedImage createImage()
          Renders the current text in the current font fontname, fontsize and color.
 void createPngFile(File location)
          Renders the current text to a .png file.
 void createPngFile(String location)
          Renders the current text to a .png file.
 void setBackgroundRGB(int r, int g, int b)
          Set 8-bit RGB values for background colour.
 void setFontFace(String fontname)
          Set the TrueType font to render with.
 void setFontSize(int fontsize)
          Set the point size of the font.
 void setText(String text)
          Set the text to be rendered by the Txt2PngFactory.
 void setTextRGB(int r, int g, int b)
          Set 8-bit RGB values for text colour.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Text2PngFactory

public Text2PngFactory()
Construct factory without setting font.


Text2PngFactory

public Text2PngFactory(String fontname,
                       int fontsize)
                throws IOException,
                       FontFormatException
Construct factory with given font face and size.

Parameters:
fontname - Name of TrueType font
fontsize - Point size of font
Throws:
IOException - if font can't be loaded
FontFormatException - if font is not a valid TTF

Text2PngFactory

public Text2PngFactory(String fontname,
                       int fontsize,
                       String text)
                throws IOException,
                       FontFormatException
Construct factory with given font face and size.

Parameters:
fontname - Name of TrueType font
fontsize - Point size of font
text - The text to render
Throws:
IOException - if font can't be loaded
FontFormatException - if font is not a valid TTF
Method Detail

createPngFile

public void createPngFile(String location)
                   throws IOException
Renders the current text to a .png file.

Parameters:
location - Location to write the file out to
Throws:
IOException - if file cannot be created

createPngFile

public void createPngFile(File location)
                   throws IOException
Renders the current text to a .png file.

Parameters:
location - Location to write the file out to
Throws:
IOException - if file cannot be created

createImage

public RenderedImage createImage()
                          throws IOException
Renders the current text in the current font fontname, fontsize and color.

Returns:
Image containing rendered text
Throws:
IOException - if no font name has been specified yet

setText

public void setText(String text)
Set the text to be rendered by the Txt2PngFactory.

Parameters:
text - The text to render

setTextRGB

public void setTextRGB(int r,
                       int g,
                       int b)
Set 8-bit RGB values for text colour.

Parameters:
r - Red component (0-255)
g - Green component (0-255)
b - Blue component (0-255)

setBackgroundRGB

public void setBackgroundRGB(int r,
                             int g,
                             int b)
Set 8-bit RGB values for background colour.

Parameters:
r - Red component (0-255)
g - Green component (0-255)
b - Blue component (0-255)

setFontFace

public void setFontFace(String fontname)
                 throws IOException,
                        FontFormatException
Set the TrueType font to render with.

Parameters:
fontname - The name of the font to use
Throws:
IOException
FontFormatException

setFontSize

public void setFontSize(int fontsize)
Set the point size of the font.

Parameters:
fontsize - The point size of the font

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2003-2011 Magnolia International Ltd.. All Rights Reserved.