info.magnolia.cms.taglibs.util
Class TextToImageTag

java.lang.Object
  extended by javax.servlet.jsp.tagext.SimpleTagSupport
      extended by info.magnolia.cms.taglibs.util.BaseImageTag
          extended by info.magnolia.cms.taglibs.util.TextToImageTag
All Implemented Interfaces:
javax.servlet.jsp.tagext.JspTag, javax.servlet.jsp.tagext.SimpleTag

public class TextToImageTag
extends BaseImageTag

Tag that converts text into PNG images, and outputs a div element containing a set of img elements. The font face, text color, text size and background color can be set via the tag attributes.

The images are saved under the node specified by the attribute parentContentNodeName. Under this parent node, a new node is created, with the name specified by the attribute imageContentNodeName. Under this node, each image will have it own node. The names of the image node are based on the text that they contain. (Special characters such as &, /, chinese characters, etc. are replaces by codes to ensure that these names are legal.)

If the images for the specified text do not exist in the repository under the specified parent node, then the this tag will create the images and save them. If the images for the text already exist, then they will not be recreated.

The text to be converted into images can be split in three ways. If the attribute textSplit is null or is set to TEXT_SPLIT_NONE, then a single image will be created of the text on one line. If textSplit is set to TEXT_SPLIT_WORDS, then the text is plit into words (i.e. wherever there is a space). Finally, if textSplit is set to TEXT_SPLIT_CHARACTERS, then a seperate image is created for each letter.

The tag outputs a div that contains one or more img's. The CSS class applied to the div is specified by the divCSS attribute. The CSS applied to the images depends on how the text was split. For text that was not split, the CSS applied is set to CSS_TEXT_IMAGE, for words it is CSS_WORD_IMAGE, and for characters it is CSS_CHARACTER_IMAGE. Any spacing that is required between images will need to be set in your css stylesheet.

The textFontFace attribute may either be a font name of a font installed on the server, or it may be a path to a TTF file. The class to generate PNG images from TrueType font strings is originally by Philip McCarthy - http://chimpen.com (http://chimpen.com/things/archives/001139.php). I have made a couple of small changes.

Version:
1.0
Author:
Patrick Janssen, Fabrizio Giustina

Field Summary
 
Fields inherited from class info.magnolia.cms.taglibs.util.BaseImageTag
imageContentNodeName, parentContentNodeName, PROPERTIES_CONTENTTYPE_VALUE, PROPERTIES_EXTENSION_VALUE
 
Constructor Summary
TextToImageTag()
           
 
Method Summary
 void cleanUp()
          Set objects to null.
 void doTag()
           
protected  String getFilename()
           
 void setDivCSS(String divCSS)
          The CSS class that will be applied to the div that contains these text images.
 void setImageContentNodeName(String imageContentNodeName)
          The name of the new contentNode to create, under which all image nodes will be saved.
 void setParentContentNodeName(String parentContentNodeName)
          The name of the parent of the new contentNode.
 void setText(String text)
          The text to be converted.
 void setTextBackColor(String textBackColor)
          The color of the background in hexadecimal format, e.g.
 void setTextFontColor(String textFontColor)
          The color of the text in hexadecimal format, e.g.
 void setTextFontFace(String textFontFace)
          The font face of the text, e.g.
 void setTextFontSize(int textFontSize)
          The size of the text, in points, e.g.
 void setTextSplit(String textSplit)
          The method used to split the text into sub-strings: 'none', 'words', or 'characters'.
 void setUp()
          Initialize settings.
 
Methods inherited from class info.magnolia.cms.taglibs.util.BaseImageTag
convertHexToColor, convertHexToRGB, convertToSimpleString, createImageNode, getImageContentNode, getRequest
 
Methods inherited from class javax.servlet.jsp.tagext.SimpleTagSupport
findAncestorWithClass, getJspBody, getJspContext, getParent, setJspBody, setJspContext, setParent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TextToImageTag

public TextToImageTag()
Method Detail

setText

public void setText(String text)
The text to be converted.


setImageContentNodeName

public void setImageContentNodeName(String imageContentNodeName)
The name of the new contentNode to create, under which all image nodes will be saved.

Overrides:
setImageContentNodeName in class BaseImageTag

setParentContentNodeName

public void setParentContentNodeName(String parentContentNodeName)
The name of the parent of the new contentNode.

Overrides:
setParentContentNodeName in class BaseImageTag

setTextFontFace

public void setTextFontFace(String textFontFace)
The font face of the text, e.g. 'Helvetica'. Default is 'Helvetica'.


setTextFontSize

public void setTextFontSize(int textFontSize)
The size of the text, in points, e.g. 12. Default is '12'.


setTextFontColor

public void setTextFontColor(String textFontColor)
The color of the text in hexadecimal format, e.g. 'ff0044'. Default is '000000' (black).


setTextBackColor

public void setTextBackColor(String textBackColor)
The color of the background in hexadecimal format, e.g. 'ff0044'. Default is 'ffffff' (white).


setTextSplit

public void setTextSplit(String textSplit)
The method used to split the text into sub-strings: 'none', 'words', or 'characters'. Default is 'none'.


setDivCSS

public void setDivCSS(String divCSS)
The CSS class that will be applied to the div that contains these text images. Defaults to "text-box".


getFilename

protected String getFilename()
Specified by:
getFilename in class BaseImageTag
See Also:
BaseImageTag.getFilename()

setUp

public void setUp()
Initialize settings.


doTag

public void doTag()
           throws javax.servlet.jsp.JspException
Specified by:
doTag in interface javax.servlet.jsp.tagext.SimpleTag
Overrides:
doTag in class javax.servlet.jsp.tagext.SimpleTagSupport
Throws:
javax.servlet.jsp.JspException

cleanUp

public void cleanUp()
Set objects to null.



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