previous chapter contents page top page next chapter

TextFormatter

June 10, 1992last updated September 30, 1993

Defined in TextFormatter.Def 
Inherits implementation from Array
Array
   TextFormatter
      OneLineFormatter

Class Description

The TextFormatter class defines the operations that are used to lay out and format text objects. TextFormatter also defines a number of operations that are useful for converting between text concepts, such as selections and ranges, and graphics concepts, such as boxes and paths.

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

Using a TextFormatter Object

To be written.

Programming Information

To be written.

Operations you might call

The TextFormatter class defines the following methods that you might Call:

Method Description

Methods of TextFormatter Class

Many TextFormatter operations use the concept of a text selection, which is a range of text in a Text object. A text selection includes both a range of characters and a range of lines, both of which describe the selection.

Here are the descriptions for text selection and related types:

typedef ulong ArrayPoint;

An ArrayPoint is simply a long integer that refers to a position within an Array object (Text is a subclass of Array).

typedef ArrayPoint   TextPoint;

The TextPoint type is a position between two characters in a Text object. The text point before the first character is numbered 0, the position between the first and second characters is numbered 1, and so on.

typedef struct
   {
   ArrayPoint       start;
   ulong            length;
   } ArrayRange;

The ArrayRange type describes a part of an array by giving its starting point (start) and the number of characters (length) in the range.

typedef ArrayRange  TextRange;
typedef ArrayRange  LineRange;

The TextRange and LineRange types define ranges of characters and lines, respectively, for text objects.

typedef struct
   {
   TextRange         chars;
   LineRange         lines;
   } TextSelection;

Finally, the TextSelection type is defined as a structure that contains both a range of characters and a range of lines.

Formatting

Format

operation Format()

Format lays out the entire Text object according to the TextFormatter, then redraws it.

Reformat

operation Reformat(changeStart: TextPoint; insertLength: Unsigned; 
deleteLength: Unsigned; VAR dirtyBox: Box): Boolean

If part of the Text object changes because of characters being inserted or deleted, Reformat lays out part of the Text object according to the TextFormatter. Reformat works on the part of the Text object that starts at changeStart and continues . The dirtyBox parameter is set to describe the area of text that's being redrawn.

Text Geometry

DotToTextSelection

operation DotToTextSelection(nearestWhitespace: Boolean; d: Dot; VAR s: 
TextSelection)

DotToTextSelection sets the s parameter to a selection in the Text object that corresponds to the Dot described by d. The selection returned in s always contains zero characters; that is, it's an insertion point between two characters. This operation is useful for finding out what character was touched by a user.

For example, given Dot d and the Text object in the following:

DotToTextSelection produces this selection:

s.chars.start is 31
s.chars.length is 0
s.lines.start is 0
s.lines.length is 1

BoxToLineRange

operation BoxToLineRange(b: Box; VAR lines: LineRange)

BoxToLineRange sets the lines parameter to a line range in the Text object that corresponds to the Box described by b. {

For example, given Box b and the text object in the following:

BoxToLineRange produces the following line range:


lines.start is 1
lines.length is 2

TextPointAndLineToDot

operation TextPointAndLineToDot(p: TextPoint; line: Unsigned; VAR d: 
Dot)

TextPointAndLineToDot determines the dot that's at the location of the TextPoint p on the line given by the line parameter. The line parameter is used to distinguish the location of a TextPoint that may be at the end of one line or the start of another.

Given this text object and TextPoint p:

Assuming line is 0, calling TextPointAndLineToDot returns the Dot just before the word "Street" in the d parameter.

TextPointToLineRange

operation TextPointToLineRange(p: TextPoint; VAR lines: LineRange)

TextPointToLineRange calculates a line range that describes the TextPoint p. The line range containing the Text Point is returned in the lines parameter.

Given this text object and TextPoint p:

TextPointToLineRange produces the following line range:

lines.start is 0
lines.length is 1

TextRangeToLineRange

operation TextRangeToLineRange(r: TextRange; VAR lines: LineRange)

TextRangeToLineRange calculates the smallest line range that contains a given text range. TextRangeToLineRange converts the text range r to a line range in the lines parameter. The line range containing the text is returned in the lines parameter. The calculated line range contains more than the text range, unless the first character is the first character of a line and the last character is the last character of a line.

Given this text object:

and this text range:

r.start is 3
r.length is 9

The text range describes the text "your body" in the first line. Calling TextRangeToLineRange on this range produces the following line range:

lines.start is 0
lines.length is 1

TextSelectionToBox

operation TextSelectionToBox(s: TextSelection; VAR b: Box)

Call TextSelectionToBox to convert a text selection to the box that contains the selection.

TextSelectionToPath

operation TextSelectionToPath(s: TextSelection; pathObjectOrNil: 
Object): Object

Call TextSelectionToPath to convert a text selection to the path that describes the area of the selection.

LineRangeToTextRange

operation LineRangeToTextRange(lines: LineRange; VAR r: TextRange)

Call LineRangeToTextRange to convert a line range to a text range (this is the inverse of TextRangeToLineRange).

LineRangeToBox

operation LineRangeToBox(lines: LineRange; VAR b: Box)

Call LineRangeToBox to Convert a line range to a Box that contains the selection (this is the inverse of BoxToLineRange).