Add sanitization of truetype fonts to fix #2531 and #2537

Fixes the issue causing #2531 and #2537 to render incorrectly.