Better Text Layout

There are a number of relatively complex changes here, they should arguably be split up into separate commits.

1. When detecting text in a horizontal line, we already add a space between words if separated by more than `word_margin` apart.  However now, we only do it if there is not already an existing space. This prevents multiple spaces being placed between words.

2. Detect a horizontal line if the line is zero width. This improves our detection of horizonal lines when looking for both horizontal and vertical.

3. Don't detect a vertical line if the previous letter is whitspace. Prevents double spaces being caught as vert lines.

4. Improve upon an unfortunate O(N^2) algorithm which I have seen taking many minutes to execute.  Unfortunately, while the "fix" reduces algorithmic complexity, it isn't technically correct, so we only do it when we know things will take a long time.