Various fixes suggested by IntelliJ IDEA's Analyze tool.
(cherry picked from commit ac1cb965ea3e010e7b222111c1c7f4783d64bd30)
Refactor TrueTypeFont.