Improved placement of fold marks

- Fold marks are placed at the end of the previous unfolded line,
  where possible.
- Based on some code by @vovkkk