# Match shape key for mesh to size of text bounding box

I'm trying to place text and then put text bubbles around them. To preserve the text bubble corner curves, I'm using shape keys. But sizing their width and height is a problem. I calculated width and height of the text bounding box and tried driving the shape keys, but that wasn't accurate for some reason.

Below is my second attempt. This time I'm calculating the width and height of both the text and bubble bounding box.

In the picture below;

1. I increase iterate a number of times to incrementally approach the correct size.
2. The result is used to increase the bubble size
3. The code seems to work but gets caught in a loop somehow. The bubble flickers through the sizes after hitting it's limit.

I'm missing something with the loop structure I'm sure. Any help would be appreciated.

If you know of a better, more elegant way to size the text bubbles around text, I'm open for that too.

Blend File

Which is exactly what you want, but you might want to scale the rectangles a bit to give the text some space inside, this is easily done by translating the upper-right, upper-left, lower-left and lower-right vertices a bit in the directions $(1, 1), (1, -1), (-1, -1), (-1, 1)$ respectively (They might not be in the same order as I mentioned, so check first !):