Text sorting by distance for rendering