Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.flagstone.transform
Class FSCharacter

    java.lang.Object
      com.flagstone.transform.FSTransformObject
          com.flagstone.transform.FSCharacter

All Implemented Interfaces:
  java.lang.Cloneable

    public class FSCharacter

extends FSTransformObject

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.

# Example

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.

# History

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

### FSCharacter

    public FSCharacter(FSCoder coder)

  Construct an FSCharacter object, initalizing it with values decoded from an encoded object.

  Parameters:
    `coder` - an FSCoder containing the binary data.

### FSCharacter

    public FSCharacter(int anIndex,
                       int anAdvance)

  Constructs an FSCharacter specifying the index of the glyph to be displayed and the spacing to the next glyph.

  Parameters:
    `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.

### FSCharacter

    public FSCharacter(FSCharacter obj)

  Constructs an FSCharacter object by copying values from an existing object.

  Parameters:
    `obj` - an FSCharacter object.

Method Detail

### getGlyphIndex

    public int getGlyphIndex()

  Gets the index of the glyph, in a font definition object, that will displayed to represent this character.

  Returns:
    the index of the glyph that represents the character to be displayed.

### getAdvance

    public int getAdvance()

  Gets the spacing in twips between the glyph representing this character and the next.

  Returns:
    the distance in twips to the next glyph.

### setGlyphIndex

    public 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.

  Parameters:
    `anIndex` - the index of the glyph that represents the character to be displayed.

### setAdvance

    public void setAdvance(int aNumber)

  Sets the spacing in twips between the glyph representing this character and the next glyph to be displayed.

  Parameters:
    `aNumber` - the relative position in twips from the origin of the glyph representing this character to the next glyph.

### equals

    public boolean equals(java.lang.Object anObject)

  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 `FSTransformObject`
  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.

  Specified by:
    `appendDescription` in class `FSTransformObject`
  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)

  Specified by:
    `length` in class `FSTransformObject`

### encode

    public void encode(FSCoder coder)

  Specified by:
    `encode` in class `FSTransformObject`

### decode

    public void decode(FSCoder coder)

  Specified by:
    `decode` in class `FSTransformObject`

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD