STYLESHEET

A stylesheet is a collection of styles. In Word, each document has its own stylesheet.

A style is a set of formatting information collected together and given a name. Word 6.0 supports paragraph and character styles, previous versions supported only paragraph styles. Character styles have just character formatting, paragraph styles have both character and paragraph formatting. The style sheet establishes a correspondence between a style code and a style definition.

Note that the storage and behavior of styles has changed radically since Word 2 for Windows, beginning with nFib 63. Some of the differences are:

Character styles are supported.

The style code is called an istd, rather than an stc.

The istd is a short, where the stc was a byte.

The range of the istd is 0-4095, where 4095 is the null style. The range of the stc was 0-256, with 222 as the null style.

PAPX's have a short istd at the beginning, rather than a byte stc.

CHPX's are a grpprl, not a CHP.

Many other changes...

This document describes only the final Word 6.0 version of the stylesheet, not the Word 2.x version.

The styles for a document (both paragraph and character styles) are stored in an array in each document. When new styles are created, they are added to the end of the array. The array can have unused slots. Some slots at the beginning of the array are reserved for specific styles, whether they have been created yet or not. Paragraph and character styles are stored in the same array. Each document has a separate array, so the same style will usually have a different istd in two different documents. Thus style matching between documents must be done by name (or by sti if the styles are built-in.)

Styles are usually referred to using an istd. The istd is an index into an array of STD's (STyle Descriptions). A (doc, istd) pair uniquely identifies a style because it tells which style in which array.

Parts of a style (for more information, see the STD structure below):

sti: A style identifier. Built-in styles have an sti that indicates which built-in style they are. User-defined styles all have stiUser.

sgc: The type of style, either paragraph or character.

istdBase: The style that this style is based on.

istdNext: The style that should be applied after this one.

stzName: The name of a style, unique within its stylesheet.

UPX: The difference between this style and the one it is based on.

UPE: The properties of this style (a PAP, CHP, and/or grpprl).

Every paragraph has a paragraph style. Every character has a character style. The default paragraph style is Normal (stiNormal, istdNormal). The default character style is Default Paragraph Font (stiNormalChar, istdNormalChar).

The formatting of a paragraph (the PAP) and a character (the CHP) depend on the paragraph and character styles applied to them, as well as any additional formatting stored in the FKPs. The PAP and CHP are constructed in a layered fashion:

For a PAP:

An initial PAP is determined by getting the PAP from the paragraph's style.

Any paragraph formatting stored in the file (the FKP papx's) is then applied to that PAP.

For a CHP:

An initial CHP is determined by getting the CHP from the paragraph's style.

Properties from the character's style (the UPX.chpx.grpprl) are then applied to that CHP.

Any character formatting stored in the file (the FKP chpx's) is the applied to that CHP.

Note that the resulting PAP and CHP have fields that indicate what style was applied: PAP.istd, CHP.istd.