calculate text offsets correctly