Replaced function to detect text width.