net.nexttext
Class TextObjectGlyph

java.lang.Object
  extended by net.nexttext.TextObject
      extended by net.nexttext.TextObjectGlyph
All Implemented Interfaces:
Locatable

public class TextObjectGlyph
extends TextObject

TextObjectGlyph represents an individual glyph and its vectorial outline in a data structure that is understood by the Renderer.

A Glyph's outline is represented by a list of control points forming a hull (vertices) around the glyph. The outline can be drawn using successive quads where anchors are being interpolated from each set of 3 adjacent control points. This allows for continuous curves even when the control points are being displaced.

Glyphs are built out of one or more contours. Contours are represented by a list of hull points forming continuous quadratic curves. The coordinates for each of these hull points are stored in the Control Points list. Because some glyphs are represented by more than one shape (holes, dot on the i, etc.), each shape is defined as an array of indices into the Control Points list. These shape arrays are stored in a list called Contours. This list should not be modified to distort the glyph. Instead, the behaviours will alter the Control Points directly without affecting the order in which they are drawn.

TextObjectGlyph objects also have two "special" properties, glyph and font, which are not accessed using the standard getProperty mechanism. The reason for this is that the list of vertices and contours forming a glyph is dependent on them, and must be rebuilt if these properties are changed. Therefore, we provided specific get/set methods to access and modify them.

The glyph's ColorProperty is inherited by default.

See Also:
TextObject

Field Summary
 java.util.Vector contours
          A vector containing int[] arrays with indices to the Control Points property list.
 java.lang.Object rendererCache
          This object can be used by Renderers to cache information about TextObjectGlyphs.
 
Constructor Summary
TextObjectGlyph(java.lang.String glyph, processing.core.PFont pfont, float size)
          Default constructor.
TextObjectGlyph(java.lang.String glyph, processing.core.PFont pfont, float size, java.util.Map<java.lang.String,Property> props, processing.core.PVector pos)
          Constructor with extra properties and a specific position.
TextObjectGlyph(java.lang.String glyph, processing.core.PFont pfont, float size, processing.core.PVector position)
          Constructor with a specific position.
TextObjectGlyph(TextObjectGlyph glyph)
          Copy Constructor.
 
Method Summary
 PVectorListProperty getControlPoints()
          Convenience accessor for the control points.
 processing.core.PFont getFont()
          Returns this TextObjectGlyph's font attribute.
 java.lang.String getGlyph()
          Get the glyph of this object as a string of length 1.
 int getHeight()
          Get the greatest number of layers between this TextObject and the leaves of the tree.
 java.awt.Polygon getLocalBoundingPolygon()
          See TextObject's getLocalBoundingPolygon() description for details.
 java.awt.geom.Rectangle2D getLogicalBounds()
          Returns this glyph's logical bounds information used for spacing.
 java.awt.geom.GeneralPath getOutline()
          Get the outline of the glyph.
 java.awt.geom.GeneralPath getOutlineAbsolute()
          Get the absolute outline of the glyph.
 float getSize()
          Get the font size of this object
 boolean isDeformed()
          A flag to indicate if this glyph has been deformed.
 void setDeformed(boolean df)
           
 void setFont(processing.core.PFont pfont)
          Rebuild the internal representation of the glyph according to the properties of the newly specified Font object.
 void setGlyph(java.lang.String glyph)
          Rebuild the internal representation of the glyph based on the specified character.
 java.lang.String toString()
           
 
Methods inherited from class net.nexttext.TextObject
attachToLeft, attachToRight, detach, getAbsoluteCoordinateSystem, getBook, getBoundingPolygon, getBounds, getCenter, getColor, getColorAbsolute, getLeftSibling, getLocation, getParent, getPosition, getPositionAbsolute, getProperty, getPropertyNames, getRelativeBoundingPolygon, getRelativeCoordinateSystem, getRightSibling, getRotation, getStroke, getStrokeAbsolute, getStrokeColor, getStrokeColorAbsolute, init, initProperties, invalidateLocalBoundingPolygon, isFilled, isStroked
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

contours

public java.util.Vector contours
A vector containing int[] arrays with indices to the Control Points property list. These contours define the shape of the glyph


rendererCache

public java.lang.Object rendererCache
This object can be used by Renderers to cache information about TextObjectGlyphs. If the glyph is deformed this cache object will be reset to null.

Constructor Detail

TextObjectGlyph

public TextObjectGlyph(java.lang.String glyph,
                       processing.core.PFont pfont,
                       float size)
Default constructor. Position is set to (0,0,0) by default, and color is inherited from the parent.

Parameters:
glyph - A one character-long string
pfont - A processing.core.PFont object

TextObjectGlyph

public TextObjectGlyph(java.lang.String glyph,
                       processing.core.PFont pfont,
                       float size,
                       processing.core.PVector position)
Constructor with a specific position.

Parameters:
glyph - A one character-long string
pfont - A processing.core.PFont object
position - A PVector representing the glyph's relative position

TextObjectGlyph

public TextObjectGlyph(java.lang.String glyph,
                       processing.core.PFont pfont,
                       float size,
                       java.util.Map<java.lang.String,Property> props,
                       processing.core.PVector pos)
Constructor with extra properties and a specific position.

Parameters:
glyph - A one character-long string
pfont - A processing.core.PFont object
pos - A PVector representing the glyph's relative position
props - Initial properties for the glyph.

TextObjectGlyph

public TextObjectGlyph(TextObjectGlyph glyph)
Copy Constructor.

Parameters:
glyph - A glyph to copy
Method Detail

isDeformed

public boolean isDeformed()
A flag to indicate if this glyph has been deformed.

False means that the glyph and font information is sufficient to draw the glyph. True means that the "Control Points" property is needed to define the shape of the glyph.


setDeformed

public void setDeformed(boolean df)

getHeight

public int getHeight()
Get the greatest number of layers between this TextObject and the leaves of the tree.

Specified by:
getHeight in class TextObject
Returns:
0 if this node is a leaf of the tree, 1 + the greatest depth of its children otherwise.


getGlyph

public java.lang.String getGlyph()
Get the glyph of this object as a string of length 1.


getSize

public float getSize()
Get the font size of this object


setGlyph

public void setGlyph(java.lang.String glyph)
Rebuild the internal representation of the glyph based on the specified character. This operation is rather costly, so it should be used accordingly. NOTE: While a glyph is represented by a single character, the parameter here is of type string for two reasons: 1. String is the type used by the Font class in order to generate shapes. 2. We have been un-officially allowing more than one character per glyph for development purposes. So far it does not seem to cause any problem, however the proper way to represent words is to use the TextObjectBuilder.


setFont

public void setFont(processing.core.PFont pfont)
Rebuild the internal representation of the glyph according to the properties of the newly specified Font object. This operation is rather costly, so it should be used accordingly.


getFont

public processing.core.PFont getFont()
Returns this TextObjectGlyph's font attribute.


getLogicalBounds

public java.awt.geom.Rectangle2D getLogicalBounds()
Returns this glyph's logical bounds information used for spacing.


getControlPoints

public PVectorListProperty getControlPoints()
Convenience accessor for the control points.


getOutline

public java.awt.geom.GeneralPath getOutline()
Get the outline of the glyph.


getOutlineAbsolute

public java.awt.geom.GeneralPath getOutlineAbsolute()
Get the absolute outline of the glyph.


getLocalBoundingPolygon

public java.awt.Polygon getLocalBoundingPolygon()
See TextObject's getLocalBoundingPolygon() description for details.

Do not modify the returned Polygon, because it may be cached.

XXXBUG this method always returns a rectangle until we write an algorithm to calculate the convex hull of the set of control points.

Specified by:
getLocalBoundingPolygon in class TextObject
See Also:
TextObject.getLocalBoundingPolygon()

toString

public java.lang.String toString()
Specified by:
toString in class TextObject