|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.flagstone.transform.FSTransformObject
com.flagstone.transform.FSText
public class FSText
FSText is used to display a line of text.
It contains an array of FSCharacter objects which identify the glyphs that will be displayed along with style information that sets the colour of the text, the size of the font and the relative placement of the line within a block of text.
Attributes | |
---|---|
identifier | The identifier, in the range 1..65535, of the font object which contains the glyphs representing each character displayed. Optional. Set to 0 if the font is not being changed. |
color | An FSColor object describing colour of the text. Optional. Set to null if the colour is not being changed. |
offsetX | The offset, in twips, relative to the left side bounding rectangle of the text block where the text will be displayed. Optional. Set to zero if no indent is being specified. |
offsetY | The offset, in twips, relative to the bottom of the bounding rectangle of the text block where the text will be displayed. Optional. Set to the height of the font if only a single line of text is being displayed so the characters are placed correctly within the bounding rectangle defined for the text object. |
height | The height of the font, in twips, used to render the characters. Optional. Set to zero if the font size is not being changed. |
characters | An array of FSCharacter objects which identify the glyph that will be displayed along with the spacing to the next character in the line of text. |
Whether the alpha channel in the colour needs to be specified depends on the class the FSText is added to. The FSDefineText2 class supports transparent text while FSDefineText class does not.
The x and y offsets are used to control how several FSText objects are laid out to create a block of text. The y offset is specified relative to the bottom edge of the bounding rectangle, which is actually closer to the top of the screen as the direction of the y-axis is from the top to the bottom of the screen. In this respect Flash is counter-intuitive. Lines with higher offset values are displayed below lines with lower offsets.
When several FSText objects are used to define a block of text using the FSDefineText or FSDefineText2 classes the attributes such as the font selected, size and colour must be specified in the first FSText object. For the remaining FSText objects these may be set to null or zero. The attributes will apply to all following FSText object until explicitly changed.
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.
1. Creating a simple string.
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.
ArrayList characters = 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. int xOffset = 0; int yOffset = 240; int fontSize = 240; FSText string = new FSText(font.getIdentifier(), FSColorTable.black(), xOffset, yOffset, fontSize, characters);
2. Creating a block of text.
Again this examples assumes a fixed size
font definition that contains glyphs for the set of characters.
ArrayList line1 = new ArrayList(); line1.add(new FSCharacter(19, 120)); // 's' line1.add(new FSCharacter(10, 120)); // 't' line1.add(new FSCharacter(18, 120)); // 'r' line1.add(new FSCharacter(9, 120)); // 'i' line1.add(new FSCharacter(14, 120)); // 'n' line1.add(new FSCharacter(6, 120)); // 'g' line1.add(new FSCharacter(0, 120)); // ' ' line1.add(new FSCharacter(28, 120)); // '1' // 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. int fontSize = 240; int yOffset = 240; FSText string1 = new FSText(font.getIdentifier(), FSColorTable.black(), 0, yOffset, fontSize, line1); ArrayList line1 = new ArrayList(); line2.add(new FSCharacter(19, 120)); // 's' line2.add(new FSCharacter(10, 120)); // 't' line2.add(new FSCharacter(18, 120)); // 'r' line2.add(new FSCharacter(9, 120)); // 'i' line2.add(new FSCharacter(14, 120)); // 'n' line2.add(new FSCharacter(6, 120)); // 'g' line2.add(new FSCharacter(0, 120)); // ' ' line2.add(new FSCharacter(29, 120)); // '2' // Display the second string 'one line' height (240 twips) below the first. // The font size and colour remain unchanged. yOffset += fontSize; FSText string2 = new FSText(0, yOffset, line2);
The FSText class represents both the TextRecordType0 and TextRecordType1 structures from the Macromedia Flash (SWF) File Format Specification. It was introduced in Flash 1.
Field Summary | |
---|---|
static int |
ANSI
Defines that the font character set is based on the ANSI UTF-8 standard which supports standard ASCII encoded strings. |
static int |
Japanese
|
static int |
Korean
|
static int |
Latin
|
static int |
SimplifiedChinese
|
static int |
SJIS
Defines that the font character set is based on the SJIS standard for representing Kanji characters. |
static int |
TraditionalChinese
|
static int |
Unicode
Defines that the font character set is based on the Unicode standard. |
Constructor Summary | |
---|---|
FSText(FSCoder coder)
Construct an FSText object, initalizing it with values decoded from an encoded object. |
|
FSText(FSText obj)
Constructs an FSText object by copying values from an existing object. |
|
FSText(int anIdentifier,
FSColor aColor,
int xOffset,
int yOffset,
int aHeight,
java.util.ArrayList anArray)
Constructs an FSText object, specifying the colour and position of the following FSText. |
|
FSText(int xOffset,
int yOffset,
java.util.ArrayList anArray)
Constructs an FSText object specifying the array of characters to be displayed and their relative placement within a block of text. |
Method Summary | |
---|---|
void |
add(FSCharacter aCharacter)
Adds an FSCharacter object to the array of characters. |
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. |
java.util.ArrayList |
getCharacters()
Gets the array of characters to be displayed. |
FSColor |
getColor()
Gets the colour of the font in which the text will be displayed. |
int |
getHeight()
Gets the height of the text. |
int |
getIdentifier()
Gets the identifier of the font in which the text will be displayed. |
int |
getOffsetX()
Gets the location of the start of the text relative to the left edge of the bounding rectangle in twips. |
int |
getOffsetY()
Gets the location of the start of the text relative to the bottom edge of the bounding rectangle in twips. |
int |
length(FSCoder coder)
|
void |
setCharacters(java.util.ArrayList anArray)
Sets the array of characters to be displayed. |
void |
setColor(FSColor aColor)
Sets the colour of the font in which the text will be displayed. |
void |
setHeight(int aHeight)
Sets the height of the text. |
void |
setIdentifier(int anIdentifier)
Sets the identifier of the font in which the text will be displayed. |
void |
setOffsetX(int xOffset)
Sets the location of the start of the text relative to the left edge of the bounding rectangle in twips. |
void |
setOffsetY(int yOffset)
Sets the location of the start of the text relative to the bottom edge of the bounding rectangle in twips. |
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 |
Field Detail |
---|
public static final int Unicode
public static final int SJIS
public static final int ANSI
public static final int Latin
public static final int Japanese
public static final int Korean
public static final int SimplifiedChinese
public static final int TraditionalChinese
Constructor Detail |
---|
public FSText(FSCoder coder)
coder
- an FSCoder containing the binary data.public FSText(int xOffset, int yOffset, java.util.ArrayList anArray)
xOffset
- the location of the text relative to the left edge of the
bounding rectangle enclosing the block of text.yOffset
- the location of the text relative to the bottom edge of the
bounding rectangle enclosing the block of text.anArray
- an array of FSCharacter objects.public FSText(int anIdentifier, FSColor aColor, int xOffset, int yOffset, int aHeight, java.util.ArrayList anArray)
anIdentifier
- the identifier of the font that the text will be rendered in.aColor
- the colour of the text.xOffset
- the location of the text relative to the left edge of the
bounding rectangle enclosing the text.yOffset
- the location of the text relative to the bottom edge of the
bounding rectangle enclosing the text.aHeight
- the height of the text in the chosen font.anArray
- an array of FSCharacter objects.public FSText(FSText obj)
obj
- an FSText object.Method Detail |
---|
public int getIdentifier()
public FSColor getColor()
public int getOffsetX()
public int getOffsetY()
public int getHeight()
public void setIdentifier(int anIdentifier)
anIdentifier
- the identifier of the font that the text will be rendered in.public void setColor(FSColor aColor)
aColor
- the colour of the text.public void setOffsetX(int xOffset)
xOffset
- the location of the text relative to the left edge of the
bounding rectangle enclosing the text.public void setOffsetY(int yOffset)
yOffset
- the location of the text relative to the bottom edge of the
bounding rectangle enclosing the text.public void setHeight(int aHeight)
aHeight
- the height of the text in the chosen font.public void add(FSCharacter aCharacter)
aCharacter
- an FSCharacter object.public java.util.ArrayList getCharacters()
public void setCharacters(java.util.ArrayList anArray)
anArray
- an array of FSCharacter objects.public java.lang.Object clone()
FSTransformObject
clone
in class FSTransformObject
public boolean equals(java.lang.Object anObject)
FSTransformObject
equals
in class FSTransformObject
public void appendDescription(java.lang.StringBuffer buffer, int depth)
FSTransformObject
appendDescription
in class FSTransformObject
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.public int length(FSCoder coder)
length
in class FSTransformObject
public void encode(FSCoder coder)
encode
in class FSTransformObject
public void decode(FSCoder coder)
decode
in class FSTransformObject
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |