2.4.4 Determining Cell Boundaries

This section describes an algorithm to find the boundaries of the innermost table cell containing a given character position or to determine that the given character position is not in a table cell. Every valid character position in a document belongs to a paragraph, so table depth can be computed for each paragraph. If a paragraph is found to be at depth zero, that paragraph is not in a table cell.

Given character position cp, use the following algorithm to determine if cp is in a table cell.

  1. Follow the procedure from Direct Paragraph Formatting to find the paragraph properties for the paragraph that contains cp. Apply the properties, and determine the table depth as specified in Overview of Tables. Call this itapOrig.

  2. If itapOrig is 0, then this paragraph is not in a table cell, so the following algorithms do not apply. Leave this algorithm. Otherwise, cp is in a table.

  3. If the character at character position cp is not a TTP mark as specified in Overview of Tables, then leave this algorithm.

  4. If itapOrig is 1, then the cp is not in a table cell. Leave this algorithm. Otherwise this TTP mark is in a cell itself, to determine the boundaries of the containing cell set itapOrig to itapOrig – 1 in the following algorithms.

Given a character position cp known to be at table depth itapOrig, follow this procedure to determine the character position of the last character in the innermost table cell that contains cp.

  1. Set itap to itapOrig.

  2. Determine the character position of the last character in the paragraph that contains cp, as specified in Determining Paragraph Boundaries. Let this position be called cpLast.

  3. Follow the procedure from Direct Paragraph Formatting to find the paragraph properties for the paragraph that contains cpLast. Apply the properties, and determine the table depth as specified in Overview of Tables. Call this itap'. It is invalid for itap' to be less than itap. If itap' is less than itap, leave the algorithm.

  4. If itap' is equal to itap, determine the text at character position cpLast, as specified in Retrieving Text. If this character is a cell mark, as specified in Overview of Tables, then cpLast is the desired output. Leave the algorithm.

  5. Let cp be cpLast + 1, and go to step 2.

Given a character position cp that is known to be at table depth itapOrig, follow this procedure to determine the character position of the first character in the innermost table cell that contains cp.

  1. Set itap to itapOrig.

  2. Determine the character position of the first character in the paragraph that contains cp, as specified in Determining Paragraph Boundaries. Let this character position be called cpFirst.

  3. If cpFirst is zero, then this is the desired output. Leave the algorithm. Negative values for cpFirst are invalid. If cpFirst is negative, leave the algorithm.

  4. Let cpPrev be cpFirst – 1. Follow the procedure from Direct Paragraph Formatting to find the paragraph properties for the paragraph that contains cpPrev. Apply the properties, and determine the table depth as specified in Overview of Tables. Call this itapPrev.

  5. If itapPrev is less than itap, then cpFirst is the desired output. Leave the algorithm.

  6. If itapPrev is equal to itap, determine the text at character position cpPrev, as specified in Retrieving Text. If this character is a cell mark or a TTP mark, then cpFirst is the desired output. Leave the algorithm.

7. Set cp to cpPrev. Go to step 2.