com.flagstone.transform
Class FSDefineText2

java.lang.Object
  extended by com.flagstone.transform.FSTransformObject
      extended by com.flagstone.transform.FSMovieObject
          extended by com.flagstone.transform.FSDefineObject
              extended by com.flagstone.transform.FSDefineText2
All Implemented Interfaces:
java.lang.Cloneable

public class FSDefineText2
extends FSDefineObject

FSDefineText2 defines one or more lines of transparent text.

It extends the functionality provided by the FSDefineText class by supporting transparent colours. The characters, style and layout information is defined using FSText objects. The FSDefineText2 class acts as a container for the text, defining the bounding rectangle that encloses the text along with a coordinate transform that can be used to change the size and orientation of the text when it is displayed.

Attributes
type Identifies the data structure when it is encoded. Read-only.
identifier An unique identifier for this object in the range 1..65535.
bounds A bounding rectangle for the entire block of text defined in the object.
transform A coordinate transform describing the placement, size and rotation of the text block.
objects An array of FSText objects describing the characters to be displayed and their attributes.

The bounding rectangle and transform controls how the text is laid out. Each FSText object in the textRecords array specifies an offset from the left and bottom edges of the bounding rectangle, allowing successive lines of text to be arranged as a block or paragraph. The coordinate transform can be used to control the size and orientation of the text when it is displayed.

Examples

Creating a simple string. The creation and layout of the glyphs to create the text is too onerous to perform from scratch. It is easier and more convenient to use existing font definitions either by parsing an existing Flash file or by converting a font definition from a specification such as TrueType in order to obtain the glyphs and layout information.

This examples assumes a font definition that contains glyphs for the following set of characters ' ', 'a', 'b', 'c' .... 'x', 'y', 'z'. The font used fixed size for the spacing between glyphs .e.g. Courier.

 int fontSize = 240;
 int leading = 80;
 
 ArrayList characters = new ArrayList();
 ArrayList lines = new ArrayList();
 
 characters.add(new FSCharacter(1, 120)); // 'a'
 characters.add(new FSCharacter(0, 120)); // ' '
 characters.add(new FSCharacter(19, 120)); // 's'
 characters.add(new FSCharacter(10, 120)); // 't'
 characters.add(new FSCharacter(18, 120)); // 'r'
 characters.add(new FSCharacter(9, 120)); // 'i'
 characters.add(new FSCharacter(14, 120)); // 'n'
 characters.add(new FSCharacter(6, 120)); // 'g'
 
 // Create the string setting the height to be 12-point (240 twips) and displaying the characters in black.
 // the text is not indented or offset.
 
 lines.add(new FSText(font.getIdentifier, FSColor.black()), 0, 0, fontSize,
                                characters);
 
 // Calculate the bounding rectangle that encloses the text.
 // The width of the text by summing all the advances.
 
 int width = 0;
 int height = fontSize + leading;
 
 for (Iterator i = characters.iterator(); i.hasNext();)
        width += ((FSCharacter) i.next()).getAdvance();
 
 FSBounds bounds = new FSBounds(0, 0, width, height);
 
 // Define the text with no coordinate transformation (use the default unity transform which leaves
 // the text unchanged.
 
 FSDefineText text = new FSDefineText(movie.newIdentifier(), bounds,
                                new FSCoordTransform(), lines);
 
 

History

The FSDefineText2 class represents the DefineText2 tag from the Macromedia Flash (SWF) File Format Specification. It was introduced in Flash 3.


Field Summary
 
Fields inherited from class com.flagstone.transform.FSDefineObject
identifier
 
Fields inherited from class com.flagstone.transform.FSMovieObject
ButtonColorTransform, ButtonSound, DefineBitsPtr, DefineButton, DefineButton2, DefineFont, DefineFont2, DefineImage, DefineImage2, DefineJPEGImage, DefineJPEGImage2, DefineJPEGImage3, DefineMorphShape, DefineMovieClip, DefineShape, DefineShape2, DefineShape3, DefineSound, DefineText, DefineText2, DefineTextField, DefineVideo, DoAction, EnableDebugger, EnableDebugger2, Export, extendLength, FontInfo, FontInfo2, FrameLabel, Free, Import, Initialize, JPEGTables, length, LimitScript, PathsArePostscript, PlaceObject, PlaceObject2, Protect, QuicktimeMovie, RemoveObject, RemoveObject2, SerialNumber, SetBackgroundColor, ShowFrame, SoundStreamBlock, SoundStreamHead, SoundStreamHead2, StartSound, TabOrder, type, VideoFrame
 
Constructor Summary
FSDefineText2(FSCoder coder)
          Construct an FSDefineText2 object, initialising it with values decoded from an encoded object.
FSDefineText2(FSDefineText2 obj)
          Constructs an FSDefineText object by copying values from an existing object.
FSDefineText2(int anIdentifier, FSBounds aBounds, FSCoordTransform aTransform, java.util.ArrayList textRecordArray)
          Constructs an FSDefineText2 object with the specified bounding rectangle, coordinate transform and text records.
 
Method Summary
 void add(FSText anObject)
          Add a FSText object to the array of text records.
 void appendDescription(java.lang.StringBuffer buffer, int depth)
          AppendDescription is used to present a string description of the object including all nested objects up to a specified depth.
 java.lang.Object clone()
          Creates a deep copy of the entire object.
 void decode(FSCoder coder)
           
 void encode(FSCoder coder)
           
 boolean equals(java.lang.Object anObject)
          Returns true if anObject is equal to this one.
 FSBounds getBounds()
          Gets the bounding rectangle that completely encloses the text to be displayed.
 java.util.ArrayList getObjects()
          Gets the array of text records that define the text to be displayed as its attributes.
 FSCoordTransform getTransform()
          Gets the coordinate transform that controls how the text is displayed.
 int length(FSCoder coder)
           
 void setBounds(FSBounds aBounds)
          Sets the bounding rectangle that encloses the text being displayed.
 void setObjects(java.util.ArrayList anArray)
          Sets the array of text records that define the text to be displayed.
 void setTransform(FSCoordTransform aTransform)
          Sets the coordinate transform that changes the orientation and size of the text displayed.
 
Methods inherited from class com.flagstone.transform.FSDefineObject
getIdentifier, setIdentifier
 
Methods inherited from class com.flagstone.transform.FSMovieObject
getType
 
Methods inherited from class com.flagstone.transform.FSTransformObject
name, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FSDefineText2

public FSDefineText2(FSCoder coder)
Construct an FSDefineText2 object, initialising it with values decoded from an encoded object.

Parameters:
coder - an FSCoder containing the binary data.

FSDefineText2

public FSDefineText2(int anIdentifier,
                     FSBounds aBounds,
                     FSCoordTransform aTransform,
                     java.util.ArrayList textRecordArray)
Constructs an FSDefineText2 object with the specified bounding rectangle, coordinate transform and text records.

Parameters:
anIdentifier - the unique identifier for this object.
aBounds - the bounding rectangle enclosing the text.
aTransform - an FSCoordTransform to change the size and orientation of the text.
textRecordArray - an array of text record (FSTextStyle and FSText) object that define the text to be displayed.

FSDefineText2

public FSDefineText2(FSDefineText2 obj)
Constructs an FSDefineText object by copying values from an existing object.

Parameters:
obj - an FSDefineText object.
Method Detail

add

public void add(FSText anObject)
Add a FSText object to the array of text records.

Parameters:
anObject - an FSText object.

getBounds

public FSBounds getBounds()
Gets the bounding rectangle that completely encloses the text to be displayed.

Returns:
the bounding rectangle of the text.

getTransform

public FSCoordTransform getTransform()
Gets the coordinate transform that controls how the text is displayed.

Returns:
the coordinate transform.

getObjects

public java.util.ArrayList getObjects()
Gets the array of text records that define the text to be displayed as its attributes.

Returns:
the array of text records (FSTextStyle and FSText objects).

setBounds

public void setBounds(FSBounds aBounds)
Sets the bounding rectangle that encloses the text being displayed.

Parameters:
aBounds - the bounding rectangle enclosing the text.

setTransform

public void setTransform(FSCoordTransform aTransform)
Sets the coordinate transform that changes the orientation and size of the text displayed.

Parameters:
aTransform - an FSCoordTransform to change the size and orientation of the text.

setObjects

public void setObjects(java.util.ArrayList anArray)
Sets the array of text records that define the text to be displayed.

Parameters:
anArray - an array of FSText objects that define the text to be displayed.

clone

public java.lang.Object clone()
Description copied from class: FSTransformObject
Creates a deep copy of the entire object.

Overrides:
clone in class FSTransformObject
Returns:
a copy of the object.

equals

public boolean equals(java.lang.Object anObject)
Description copied from class: FSMovieObject
Returns true if anObject is equal to this one. Objects are considered equal if they would generate identical binary data when they are encoded to a Flash file.

Overrides:
equals in class FSMovieObject
Returns:
true if this object would be identical to anObject when encoded.

appendDescription

public void appendDescription(java.lang.StringBuffer buffer,
                              int depth)
Description copied from class: FSTransformObject
AppendDescription is used to present a string description of the object including all nested objects up to a specified depth. This method provide a more controlled way of creating a string representation of an object since large objects such as font or shape definitions can contain dozens of nested objects. The representation of the object is appended to the StringBuffer, showing the name of the class and values of the attributes it contains. If the object contains any attributes that are objects then the object graph will be traversed up to the specified depth. If objects are nested at a level less than specified depth then the full string representation of the object is displayed. For objects at the specified depth only the name of the class is displayed. Any objects below this depth are not displayed.

Overrides:
appendDescription in class FSDefineObject
Parameters:
buffer - a StringBuffer to which the description of each object is appended.
depth - the maximum level of nesting up to which objects will be displayed.

length

public int length(FSCoder coder)
Overrides:
length in class FSDefineObject

encode

public void encode(FSCoder coder)
Overrides:
encode in class FSDefineObject

decode

public void decode(FSCoder coder)
Overrides:
decode in class FSDefineObject