Factor out text rendering code and restructure as first step to turning this into a usable library.