previous chapter contents page top page next chapter

Text

June 10, 1992last updated August 29, 1994

Defined in Text.Def 
Inherits from Object, HasText
Uses extra
No translation

Class Description

Magic Cap uses objects of class Text to represent collections of characters. Text objects aren't viewable, but they're usually associated with objects of class TextContainer that display their contents. Class Text is the canonical implementation of the HasText mixin.

Version note: Much of the content of previous versions of this chapter has moved to the chapter on class HasText. The content that remains is woefully incomplete. We apologize for the inconvenience.

Remember that if the documentation and the software (especially the definition files) disagree, always trust the software.

Using a Text Object

To be written.

Programming Information

Instantiate: sometimes
Subclass: rarely
Call its methods: sometimes

Objects of the Text class contain the encoded characters that are used to display and edit human-readable text. You can use text objects whenever you need to create some text to be displayed in a text field object or another viewable object. Building on its superclass, class HasText, class Text defines a rich set of methods that allow you to change, display, measure, and search the text.

Here's an example of the most basic kind of text object:

Instance Text 6313;
            text: 'This is a plain vanilla text object.';
End Instance;

You might have noticed that you can't dump styled text objects properly. You can, however, create styled text objects by hand in your object definition files.

Styled text in Magic Cap is stored in chunks. A chunk of text consists of text in exactly one text style. For example, given the text

This is a test.

where "This" is underlined, the space between "This" and "is a" is plain, "is a" is bold, the space between "is a" and "test." is italic, and "test." is plain, the chunks would be "This", " ", "is a", " ", and "test."

A chunk contains a chunk code and the actual text run. The chunk code describes the characteristics of the text run. The very first chunk in a styled text object must be a list of the TextStyle objects used in the text. The chunk code you'll use for your styled text will be of the form $Cn, where n represents a one based index into the style table. This chunk code specifies which style the text run in this chunk is to be rendered in.

This is how you'd create the example styled text in an object definition file:

Instance Text 1;
  styleTableCode: $ D000;   // Signals the style table.
       numStyles: $ 0003;   // Three styles
          style1: iBook12Underlined;
          style2: iBook12Bold;
          style3: iBook12Italic; // these could also be \ references to TextStyle 
objects in your package
       chunkCode: $ C1;     // Set to style index 1
         textRun: 'This';
       chunkCode: $ C0;     // Set to base style
         textRun: ' ';
       chunkCode: $ C2;     // Set to style index 2
         textRun: 'is a';

       chunkCode: $ C3;     // Set to style index 3
         textRun: ' ';
       chunkCode: $ C0;     // Set to base style
         textRun: 'test.';
End Instance;

The chunk code always has its high bit set. Your text should therefore contain only standard ASCII characters, since any special characters from the Macintosh character set would be interpreted as a chunk code.

Methods defined by class Text

Class Text defines the following methods you might Call:

Method Description
StringToText Make the given string into a new text object
Converting 8-bit characters
ConvertFromMagic8Bit Convert the text from the magic format to unicode
ConvertToMagic8Bit Convert the text form unicode to the magic format
Manipulating single characters
CharacterIsAlphabetic Return true if the character is alphabetic
CharacterIsASCII Return true if the character is an ascii character
CharacterIsDash Return true if the character is a dash
CharacterIsDecimalDigit Return true if the character is a decimal digit
CharacterIsLowerCase Return true if the character is lowercase
CharacterIsPunctuation Return true if the character is a punctuation mark
CharacterIsSpace Return true if the character is the space character
CharacterIsWhiteSpace Return true if the character is a space or a control character
MakeCharacterUpperCase Change the character to its uppercase version
MakeCharacterLowerCase Change the character to its lowercase version

Description of fields

The Text class doesn't define any fields.

Related Classes

The HasText mixin defines many, many useful methods for manipulating text. See its chapter for more information.

Method Descriptions

To be written.