com.flagstone.transform.font
Class FontInfo

java.lang.Object
  extended by com.flagstone.transform.font.FontInfo
All Implemented Interfaces:
Copyable<MovieTag>, SWFEncodeable, MovieTag

public final class FontInfo
extends Object
implements MovieTag

FontInfo defines the name and face of a font and maps the codes for a given character set to the glyphs that are drawn to represent each character.

Three different encoding schemes are supported for the character codes. The ANSI character set is used for Latin languages, SJIS is used for Japanese language characters and Unicode is used for any character set. Since Flash 5 Unicode is the preferred encoding scheme.

The index of each entry in the codes list matches the index in the corresponding glyph in the shapes list of an DefineFont object, allowing a given character code to be mapped to a given glyph.

FontInfo also allows the font associated with a Flash file to be mapped to a font installed on the device where the Flash Player displaying the file is hosted. The use of a font from a device is not automatic but is determined by the HTML tag option deviceFont which is passed to the Flash Player when it is first started. If a device does not support a given font then the glyphs in the DefineFont class are used to render the characters.

An important distinction between the host device to specify the font and using the glyphs in an DefineFont object is that the device font is not anti-aliased and the rendering is dependent on the host device. The glyphs in an DefineFont object are anti-aliased and are guaranteed to look identical on every device the text is displayed.


Constructor Summary
FontInfo(FontInfo object)
          Creates and initialises a FontInfo object using the values copied from another FontInfo object.
FontInfo(int uid, String fontName, boolean isBold, boolean isItalic)
          Constructs a basic FontInfo object specifying only the name and style of the font.
FontInfo(SWFDecoder coder)
          Creates and initialises an FontInfo object using values encoded in the Flash binary format.
 
Method Summary
 void addCode(int aCode)
          Add a code to the list of codes.
 FontInfo copy()
          Creates a complete copy of this object.
 void encode(SWFEncoder coder, Context context)
          Encode an object to the Flash binary format.
 List<Integer> getCodes()
          Get the list of character codes.
 CharacterFormat getEncoding()
          Get the encoding scheme used for characters rendered in the font, either ASCII, SJIS or UCS2.
 int getIdentifier()
          Get the unique identifier of the font definition that this font information is for.
 String getName()
          Get the name of the font family.
 boolean isBold()
          Is the font weight bold.
 boolean isItalic()
          Is the font style italics.
 boolean isSmall()
          Does the font have a small point size.
 int prepareToEncode(Context context)
          Prepare an object for encoding, returning the expected size of an object when it is encoded.
 void setBold(boolean aBool)
          Sets the font is bold.
 void setCodes(List<Integer> list)
          Sets the list of character codes.
 void setEncoding(CharacterFormat anEncoding)
          Sets the font character encoding.
 void setIdentifier(int uid)
          Sets the identifier of the font that this font information is for.
 void setItalic(boolean aBool)
          Sets the font is italics.
 void setName(String aString)
          Sets the name of the font.
 void setSmall(boolean aBool)
          Sets the font is small.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FontInfo

public FontInfo(SWFDecoder coder)
         throws IOException
Creates and initialises an FontInfo object using values encoded in the Flash binary format.

Parameters:
coder - an SWFDecoder object that contains the encoded Flash data.
Throws:
IOException - if an error occurs while decoding the data.

FontInfo

public FontInfo(int uid,
                String fontName,
                boolean isBold,
                boolean isItalic)
Constructs a basic FontInfo object specifying only the name and style of the font.

Parameters:
uid - the unique identifier of the DefineFont that contains the glyphs for the font.
fontName - the name assigned to the font, identifying the font family.
isBold - indicates whether the font weight is bold (true) or normal (false).
isItalic - indicates whether the font style is italic (true) or plain (false).

FontInfo

public FontInfo(FontInfo object)
Creates and initialises a FontInfo object using the values copied from another FontInfo object.

Parameters:
object - a FontInfo object from which the values will be copied.
Method Detail

getIdentifier

public int getIdentifier()
Get the unique identifier of the font definition that this font information is for.

Returns:
the unique identifier of the font.

getName

public String getName()
Get the name of the font family.

Returns:
the font name.

getEncoding

public CharacterFormat getEncoding()
Get the encoding scheme used for characters rendered in the font, either ASCII, SJIS or UCS2.

Returns:
the encoding used for the character codes.

isSmall

public boolean isSmall()
Does the font have a small point size. This is used only with a Unicode font encoding.

Returns:
true if the font is small.

setSmall

public void setSmall(boolean aBool)
Sets the font is small. Used only with Unicode fonts ot provide better appearance when the point size is small.

Parameters:
aBool - true if the font will be aligned on pixel boundaries.

isItalic

public boolean isItalic()
Is the font style italics.

Returns:
true if the font is in italics.

isBold

public boolean isBold()
Is the font weight bold.

Returns:
true if the font weight is bold.

getCodes

public List<Integer> getCodes()
Get the list of character codes.

Returns:
the list of character codes defined in the font.

setIdentifier

public void setIdentifier(int uid)
Sets the identifier of the font that this font information is for.

Parameters:
uid - the unique identifier of the DefineFont that contains the glyphs for the font. Must be in the range 1..65535.

setName

public void setName(String aString)
Sets the name of the font. The name be omitted (set to an empty string) if the font is embedded in the Flash file, i.e. the corresponding DefineFont object has all the glyph information.

Parameters:
aString - the name assigned to the font, identifying the font family. Must not be null.

setEncoding

public void setEncoding(CharacterFormat anEncoding)
Sets the font character encoding.

Parameters:
anEncoding - the encoding used to identify characters, either ASCII, SJIS or UNICODE.

setItalic

public void setItalic(boolean aBool)
Sets the font is italics.

Parameters:
aBool - a boolean flag indicating whether the font will be rendered in italics.

setBold

public void setBold(boolean aBool)
Sets the font is bold.

Parameters:
aBool - a boolean flag indicating whether the font will be rendered in bold face.

addCode

public void addCode(int aCode)
Add a code to the list of codes. The index position of a character code in the list identifies the index of the corresponding glyph in the DefineFont object.

Parameters:
aCode - a code for a glyph. Must be in the range 0..65535.

setCodes

public void setCodes(List<Integer> list)
Sets the list of character codes. The index position of a character code in the list identifies the index of the corresponding glyph in the DefineFont object.

Parameters:
list - the list mapping glyphs to particular character codes. Must not be null.

copy

public FontInfo copy()
Creates a complete copy of this object.

Specified by:
copy in interface Copyable<MovieTag>
Returns:
a deep-copy of this object. New instances of mutable objects are copied and immutable instances are shared.

toString

public String toString()
Overrides:
toString in class Object

prepareToEncode

public int prepareToEncode(Context context)
Prepare an object for encoding, returning the expected size of an object when it is encoded. This method also used to initialise variables, such as offsets and flags that will be used when the object is encoded. Generally the method returns the size in bytes, however when called on objects that use bit fields such as shapes the methods will return the size in bits.

Specified by:
prepareToEncode in interface SWFEncodeable
Parameters:
context - an Context that allows information to be passed between objects to control how they are initialised for encoding.
Returns:
the size of the object when it is encoded.

encode

public void encode(SWFEncoder coder,
                   Context context)
            throws IOException
Encode an object to the Flash binary format.

Specified by:
encode in interface SWFEncodeable
Parameters:
coder - an SWFEncoder object.
context - an Context that allows information to be passed between objects to control how they are initialised for encoding.
Throws:
IOException - if an error occurs while encoding the object.


Copyright © 2002-2010 Flagstone Software Ltd.. All Rights Reserved.