|
|||||||||
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.FSCharacter
public class FSCharacter
The FSCharacter class is used to identify the glyph that is displayed for a given character in a line of text.
The spacing to the next character is also defined.
Attributes | |
---|---|
glyphIndex | An index into the array of FSShape objects that define the glyphs for a given font. |
advance | The distance, in twips, from the origin of the glyph representing the current character to the next glyph to be displayed. |
A single lines of text is displayed using an FSText object which contains an array of FSCharacter objects. Blocks of text can be created by combining one or more FSText objects. The size, colour and relative position of each line within the block is defined by the FSText object. The FSText objects are added to an FSDefineText object or an FSDefineText2 object (which supports transparent colours) which is then used to define the final size and orientation of the text when it is placed on the Display List.
This greatly simplified example illustrates how text strings are created. First the array of glyphs for each character is defined.
ArrayList alphabet = new ArrayList(); FSShape space = new Shape(...); // Glyph for ' ' FSShape a = new Shape(...); // Glyph for 'a' FSShape b = new Shape(...); // Glyph for 'b' ... FSShape z = new Shape(...); // Glyph for 'z' alphabet.add(space); alphabet.add(a); alphabet.add(b); ... alphabet.add(z); // Create the font containing the glyphs for each character movie.add(new FSDefineFont(movie.newIdentifier(), alphabet));
Now created the array of FSCharacter objects representing 'a string' Assume the font is a fixed width such as Courier and the spacing between characters is 160 twips - 8 pixels.
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' FSText string = new FSText(characters);
It should be immediately clear that creating strings and font definitions from scratch is a huge task requiring knowledge of drawing glyphs and how to layout glyphs to generate aesthetically pleasing text. Transform is a low-level library and such complicated code should be avoided at all costs. Fortunately it is 'relatively' easy to use convert existing font definitions such as those encoded in True Type Font files to into the font and text definition objects that can be used to create Flash files. Another useful approach is to use an existing font definition from a Flash file to obtain the glyph definitions, character codes and advance information.
Creating such font and text definitions is outside the scope of the documentation for this library. However refer to the Transform Utilities framework for Transform available on Flagstone Software's web site for ways to perform these tasks.
The FSCharacter class represents the GlyphEntry structure from Macromedia Flash (SWF) File Format Specification. It was introduced in Flash 1.
Constructor Summary | |
---|---|
FSCharacter(FSCharacter obj)
Constructs an FSCharacter object by copying values from an existing object. |
|
FSCharacter(FSCoder coder)
Construct an FSCharacter object, initalizing it with values decoded from an encoded object. |
|
FSCharacter(int anIndex,
int anAdvance)
Constructs an FSCharacter specifying the index of the glyph to be displayed and the spacing to the next glyph. |
Method Summary | |
---|---|
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. |
void |
decode(FSCoder coder)
|
void |
encode(FSCoder coder)
|
boolean |
equals(java.lang.Object anObject)
Returns true if anObject is equal to this one. |
int |
getAdvance()
Gets the spacing in twips between the glyph representing this character and the next. |
int |
getGlyphIndex()
Gets the index of the glyph, in a font definition object, that will displayed to represent this character. |
int |
length(FSCoder coder)
|
void |
setAdvance(int aNumber)
Sets the spacing in twips between the glyph representing this character and the next glyph to be displayed. |
void |
setGlyphIndex(int anIndex)
Sets the index of the glyph, contained in the array of FSShape object contained in a font definition object, that represents the character to be displayed. |
Methods inherited from class com.flagstone.transform.FSTransformObject |
---|
clone, name, toString |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public FSCharacter(FSCoder coder)
coder
- an FSCoder containing the binary data.public FSCharacter(int anIndex, int anAdvance)
anIndex
- the index into the array of FSShapes in a font definition
object that defines the glyph that represents the character to
be displayed.anAdvance
- the relative position in twips, from the origin of the glyph
representing this character to the next glyph to be displayed.public FSCharacter(FSCharacter obj)
obj
- an FSCharacter object.Method Detail |
---|
public int getGlyphIndex()
public int getAdvance()
public void setGlyphIndex(int anIndex)
anIndex
- the index of the glyph that represents the character to be
displayed.public void setAdvance(int aNumber)
aNumber
- the relative position in twips from the origin of the glyph
representing this character to the next glyph.public boolean equals(java.lang.Object anObject)
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 |