"Orphans" prevention system for Unreal RichTextBlock component

Really, the need for the information about how the text component is rendering the text is only needed in the case of an “Orphan” being corrected producing an even worst effect of the last line of a paragraph being larger than the previous one:
image

Being kind of a corner case, it can be ignored and fix the Orphans by just processing the text and adding a NBSP character in the final space of each paragraph like so:

// UCMSTextBlock extends from UTextBlock
#define NBSP (TCHAR)160

void UCMSTextBlock::HandleOrphansFixing()
{
	// Convert text to string
	FString textString = Text.ToString();

	// Replace all NBSPs with normal spaces
	for (int i = 0; i < textString.Len(); i++)
		if (textString[i] == NBSP)
			textString[i] = ' ';

	// Look for line breaks and insert NBSP in the previous space
	int lastSpaceIndex = -1;
	for (int i = 0; i < textString.Len(); i++)
	{
		// Space
		if (textString[i] == ' ') 
			lastSpaceIndex = i;

		// Line break or end of the text, replace last space with NBSP
		if ((textString[i] == '\n' || i == textString.Len() - 1) && 
			lastSpaceIndex > 0)
			textString[lastSpaceIndex] = NBSP;
	}

	// Finally, replace component text
	SetText(FText::FromString(textString));
}