I'm not sure I understand the question.
Each line is word-wrapped, then the spacing between the letters increased until the rightmost edge of the last word is aligned with the right margin. If the space between words passes a certain aesthetic threshold, the spacing between the letters in each word is increased until the result is more balanced. If there is only one word between the margins, the letters in the word are also spaced apart.
I imagine that in order to avoid calculating every line every time you make an edit, some data structures are maintained which keep the calculated values for each txt line. Only when an event occurs in the document that invalidates a line will its word-wrapping and full justification attributes have to be recalculated:
Typing on a line recalculates the line.
If the affected line pushes a word to the next line or pulls a word from the next line, the next line is also recalculated, with a ripple effect until a paragraph mark is encountered or the change does not affect the next line.
If a new line is created or removed from the end of the paragraph, all subsequent paragraphs must be marked suspect and recalculated as text flowing around floating objects can affect word-wrapping by changing the width of a line next to the object.