yet another algorithm to handle text wrapping