2.4.6.6 Determining Formatting Properties
This section specifies an algorithm for how to combine properties from various sources that influence the properties of a character position to obtain the final formatting.
Character, paragraph, and table properties of the text at any given character position are specified by lists of differences from the defaults. Property Storage explains how to determine defaults and how to apply property differences. This section further specifies which lists of property differences are applicable and the order in which they apply.
In general, the differences from defaults are specified by one or more styles as well as any directly applied property modifications. Multiple styles can influence the properties at a given character position. A table style, for example, can specify paragraph properties that apply to some or all paragraphs within that table. A paragraph in such a table can itself have a paragraph style, in which case two different lists of differences modify the properties of said paragraph.
Given character position cp, use the following algorithm to determine the properties of text at cp:
Part 1:
Determine defaults for all properties the application is interested in. For further specification, see Property Storage.
Split the properties into three groups based on the objects they apply to: paragraph properties, character properties, and table properties as specified by Single Property Modifies. These are the set of properties which will be modified throughout the algorithm to arrive at the desired properties.
All versions of the FIB contain exactly one FibRgFcLcb97 though it can be nested in a larger structure. Read an STSH from offset FibRgFcLcb97.fcStshf in the Table Stream, with size FibRgFcLcb97.lcbStshf. From the STSH, obtain an LPStshi and from that obtain an STSHI.
Apply the property modifications specified by the ftcAsci, ftcFE and ftcOther members of the STSHI.Stshif along with the ftcBi member of STSHI if specified.
Determine whether cp is in a table or not. For further specification, see Determining Cell Boundaries. If cp is not in a table, go to step 1 of part 2.
Determine the table style that is applied to the innermost row that contains cp as follows:
Apply the algorithm from Determining Row Boundaries to obtain the character position of the TTP mark of the innermost row that contains cp. Call this cpTtp.
Apply the algorithm from Direct Paragraph Formatting on cpTtp.
Apply the array of Prl elements that was obtained to the table row and determine the istd of the table style applied to this table row using sprmTIstd. Call it istdTable. If no table style is applied, go to step 1 of part 2.
Using the algorithm from Determining Properties of a Style, obtain a grpprlPapx, grpprlChpx, and a grpprlTapx (if available) from the istdTable. Apply any property modifications specified in grpprlChpx, grpprlPapx, and grpprlTapx to the character, paragraph, and table properties, respectively.
Find the position of the innermost cell that contains cp within the innermost table that contains cp by applying the algorithm from Determining Row Boundaries and Determining Cell Boundaries as appropriate. Specifically, determine if the innermost cell that contains cp belongs to the first row, first column, last row, or last column of the innermost table that contains cp. Also, determine whether the innermost cell that contains cp is in an even or an odd horizontal band based on horizontal banding applied in grpprlTapx with sprmTCHorzBands and, similarly, if it is in an even or an odd vertical band based on vertical banding applied in grpprlTapx with sprmTCVertBands. Note that if sprmTTlp.grfatl specifies that the top row of the table receives special formatting, then the top row of the table and any row with sprmTTableHeader applied with a value of 0x01 is not counted when determining odd or even horizontal banding. Similarly, if sprmTTlp.grfatl specifies that the logically leftmost column of the table receives special formatting, then that column is not counted when determining odd or even vertical banding.
Next, using the array of Prls obtained in step 6, determine if additional property differences need to be applied to cp based on its location in the table as specified by sprmTTlp.grfatl. If additional property differences need to be applied, look for sprmPCnfs within the grpprlPapx from step 7, sprmCCnfs within grpprlChpx from step 7, and sprmTCnfs within grpprlTapx from step 7 whose CNFC, see CNFOperand.cnfc, matches the position information found in step 8. The following table specifies which CNFC values match which position information.
CNFC Value
Matches …
0x0001
Any cell in the top row or with sprmTTableHeader applied with a value of 0x01 if sprmTTlp.grfatl specifies that top row of the table receives special formatting.
0x0002
Any cell in the bottom row if sprmTTlp.grfatl specifies that bottom row of the table receives special formatting and the cell does not match CNFC value 0x0001.
0x0004
Any cell in the logically leftmost column if sprmTTlp.grfatl specifies that the logically leftmost column receives special formatting.
0x0008
Any cell in the logically rightmost column if sprmTTlp.grfatl specifies that the logically rightmost column receives special formatting and the cell does not match CNFC value 0x0004.
0x0010
Any cell in an odd numbered vertical band if sprmTTlp.grfatl specifies that odd numbered vertical bands receive special formatting and the cell does not match CNFC values 0x0004 or 0x0008.
0x0020
Any cell in an even numbered vertical band if sprmTTlp.grfatl specifies that even numbered vertical bands receive special formatting, and the cell does not match CNFC values 0x0004 or 0x0008.
0x0040
Any cell in an odd numbered horizontal band if sprmTTlp.grfatl specifies that odd numbered horizontal bands receive special formatting, and the cell does not match CNFC values 0x0001 or 0x0002.
0x0080
Any cell in an even numbered horizontal band if sprmTTlp.grfatl specifies that even numbered horizontal bands receive special formatting, and the cell does not match CNFC values 0x0001 or 0x0002.
0x0100
The logically rightmost cell on the top row of the table if sprmTTlp.grfatl specifies that both the top row and the logically rightmost column receive special formatting and the cell does not match CNFC value 0x200.
0x0200
The logically leftmost cell on the top row of the table if sprmTTlp.grfatl specifies that both the top row and the logically leftmost column receive special formatting.
0x0400
The logically rightmost cell on the bottom row of the table if sprmTTlp.grfatl specifies that both the bottom row and the logically rightmost column receive special formatting and the cell does not match CNFC value 0x0100, 0x0200, or 0x0800.
0x0800
The logically leftmost cell on the bottom row of the table if sprmTTlp.grfatl specifies that both the bottom row and the logically leftmost column receive special formatting and the cell does not match CNFC value 0x0100 or 0x0200.
A single cell position can match multiple CNFC values. For example the logically rightmost cell on the top row could match all of these CNFC values: 0x0100, 0x0008, 0x0001. Apply conditional formatting in the following order.
CNFC Values
Conditional Formatting Type
0x0040 or 0x0080
Odd or even horizontal banding
0x0010 or 0x0020
Odd or even vertical banding
0x0004 or 0x0008
First or last column
0x0001 or 0x0002
First or last row
0x0100, 0x0200, 0x0400, or 0x0800
Corner cell
Apply any property modifications specified in a matching sprmCCnf, if one exists, to the character properties. Apply any property modifications specified in a matching sprmPCnf, if one exists, to paragraph properties. Apply any property modifications specified in a matching sprmTCnf, if one exists, to table properties.
Part 2:
Apply the algorithm from Direct Paragraph Formatting up to and including step 4. The remaining steps of that algorithm are applied later. Obtain GrpprlAndIstd. Using the algorithm from Determining Properties of a Style, obtain any paragraph property modifications that are specified by GrpprlAndIstd.istd.
Apply any paragraph property modifications obtained from GrpprlAndIstd.istd in the previous step. Next, apply any paragraph property modifications found in GrpprlAndIstd.grpprl. Finally, finish the remaining steps in the algorithm from Direct Paragraph Formatting that was started in the previous step.
If the paragraph that contains cp belongs to a list, apply any further paragraph property modifications specified by the list. For information about how to determine whether a paragraph belongs to a list and how to obtain the property modifications specified by the list, see Determining List Formatting of a Paragraph. At this point the paragraph properties reflect those of the paragraph that contains cp. The remaining steps determine the character properties.
Using the algorithm from Determining Properties of a Style, obtain any character property modifications specified by GrpprlAndIstd.istd from step 1 of part 2 or the value of the last sprmPIstdPermute if any in GrpprlAndIstd.grpprl. Apply any character property modifications obtained from the style to the character properties.
Finally, using the algorithm from Direct Character Formatting, obtain any property modifications to be applied to character properties and apply them.