Our content and design teams have a specific request to prevent paragraphs from ending with an "orphan word" - a single word on the last line of text that has wrapped onto multiple lines. The designer's proposed solution is to adjust the margins slightly, perhaps by +/- 5%, in order to manipulate the word placement. While this can be done manually, we are looking for a code-based solution to ensure consistency across various sizes and languages.
Is there an efficient way to determine the number of words in the final line of a wrapped text block? Would breaking the string into individual spans for each word be the best approach?
We greatly appreciate any advice or guidance on this matter!