Refactored out the text centering algorithm so it can be tested