How to use

The main script you work with is the "Type.Class" script. Once you have created a new instance of the script, you can use its mGetImage() method to get images of the specified text like this:

myTextObj = script("Type.Class").new()

textImage = myTextObj.mGetImage("Some text")

You can also supply a 'settings' list when you create the instance of use the mGetImage method. This list can specify any of the following options

  • fontFace: which font to use (symbol)
  • width: the maximun width of the returned image (#integer)
  • wrap: whether to wrap the text if it exceeds the specified width (#boolean)
  • autoInsertEllipses: if the #wrap setting is false and the text is wider than the specified width, then set this to TRUE to automatiically add ellipses to the end of the text
  • Leading: leading between lines of text (#Integer)
  • Kerning: the letter-spacing, in pixels (#integer

For example:

myTextObj = script("Type.Class").new([#FontFace: #Header, #Width:360])

textImage = myTextObj.mGetImage(SomeLongText)

Once you have the textImage, you can copy it to another image (using Ink:36 for mono fonts) or use one of the TextDisplayWidgets to show the text in a 'Text Box' type widget.

More Detail

The Font class is only responsible for generating individual characters. It is the job of the 'Type class' to generate an overall image for a string. This type.class will return an image for the specified string, using the Font Class to generate images for each character. The type class handles general formatting duties (wrapping text, kerning between characters, inserting ellipses if the string does not fit etc). The Type class doesn't handle the actual displaying of the text image - this is left to the various interface objects (text display wigets, button widgets, etc).

Whilst many interface/display objects may each create their own 'Text object', it is preferrable to only create a single instance of each pixel font. To ensure this, the Text objects get their reference to the FontObject via the FontMgr. The FontMgr is a script that creates all the pixel fonts and stores these in a 'library'. When a Type object wants to use a font, it gets a reference to the font from the FontMgr.

The Pixelfont System The Pixelfont System

First published 23/05/2005