Bounding box algorithm for text