Introduction to formatting

Editable text and plain text have content, but no formatting. This means they can be stored and manipulated, but cannot be viewed, because viewing needs format information — obviously, it needs a font and, more subtly, it also needs paragraph alignment, colour etc.

There are two types of format: character and paragraph formats

  • character format information includes font, colour, bold, italic, underline. Each character has an associated effective format which consists of any format attributes which have been applied directly to that character or applied via a character style, or inherited from the formatting of preceding text.

    The TCharFormat class contains all information necessary to specify a character format.

  • paragraph format information includes left, right and hanging indent, space before, between and after lines, tabs, shading and borders and bullet points. Every paragraph has an effective format. This consists of the format attributes which have either been explicitly applied to that paragraph or applied via a paragraph style, or inherited from the formatting of preceding text.

  • The CParaFormat class contains all information necessary to specify a paragraph format.

    Paragraph format is a C class, rather than a T, because the object owns potentially unbounded arrays, such as the tab stops. Also, the representation of border specification is optimised to use minimum space if no borders are specified. So the paragraph format class needs a destructor, and it is therefore a C.

In order to economise on space, format specifications are built up in format layers CParaFormatLayer and CCharFormatLayer. Each layer specifies a number of attributes and their values. Functions are provided to manipulate and interrogate the attributes and values in a layer, and to find out the effective format from all the layers applying to a region of the text object. Format mask classes TParaFormatMask and TCharFormatMask play a key role in specifying which attributes are involved in these operations.

For global text, the same formatting applies to the entire text object. A character and paragraph format layer are specified for the global text object's constructor, and are used throughout the lifetime of the object. The effective format is taken by layering these over a default format which specifies values for all attributes.

For rich text, format layers may be overlaid, and may apply to any region of the text object. By this means, formatting for each character and paragraph may be controlled individually.

A paragraph style is a named format, represented by the CParagraphStyle class, which may be applied to a paragraph. A style may either replace all attributes already set, or change only the attributes specified in the layer. The paragraph style is a paragraph format layer with a name and, also, a character format layer which sets character formatting in the paragraph.