2.4.6.4 Determining Level Number of a Paragraph

The level number of a paragraph is the number in the number sequence of the level that corresponds to that paragraph, formatted according to an MSONFC (as specified in [MS-OSHARED] section 2.2.1.3). The number sequence of a level begins at a specified value and increments by 1 for each paragraph in the level. Also, the number sequence of a level can restart when certain other levels are encountered. See the specification of LVLF for more information. This section describes an algorithm to determine the level number of a paragraph containing a given character position.

Given character position cp, use the following algorithm to determine the level number of the paragraph containing cp:

  1. Follow steps 1 thru 10 of Determining List Formatting of a Paragraph to get the iLvlCur, lvl that correspond to the paragraph that cp belongs to. Also let lsidCur be lfo.lsid from step 4 of that algorithm.

  2. Let nfcCur be lvl.lvlf.nfc. If nfcCur is equal to 0xFF or 0x17, this level has no number sequence, and the level number of the paragraph is an empty string. In this case, let xsLevelNumber be an empty string, and the algorithm ends.

  3. Let iStartAt be lvl.lvlf.iStartAt.

  4. If lvl.lvlf.fNoRestart is nonzero, let iLvlRestartLim be lvl.lvlf.iLvlRestartLim. Otherwise, let iLvlRestartLim be iLvlCur.

  5. Let numCur be iStartAt.

  6. For each paragraph p that has a nonzero iLfo property and that is in the same Valid Selection as cp, beginning with the paragraph starting at the lowest character position up to but not including the paragraph containing cp, carry out steps 7 to 12 below.

  7. Determine lfo.lsid and lfolvl for paragraph p using steps 1 through 6 of Determining List Formatting of a Paragraph. If lfo.lsid is not equal to lsidCur, continue to the next paragraph.

  8. If the iLvl property of the paragraph p is less than iLvlRestartNum, let numCur by iStartAt.

  9. If the iLvl property of the paragraph p is not equal to iLvlCur, continue to the next paragraph.

  10. If the value of the iLfo property of the paragraph p has not been encountered before in the execution of this algorithm and lvolvl.fStartAt is nonzero, then let numCur be lfolvl.iStartAt and continue to the next paragraph.

  11. Let numCur be numCur + 1.

  12. If the paragraph p does not contain cp, return to step 6.

  13. Let xsLevelNumber be a string containing the number specified by numCur formatted according to the MSONFC (as specified in [MS-OSHARED] section 2.2.1.3) specified by nfcCur.

xsLevelNumber is now the level number of the paragraph.