Fix bug in text drawing code