Repository: python-pillow/Pillow

Issue:
`ImageDraw.textbbox` doesn't work with the default font
### What did you do?

I tried to use `ImageDraw.textbbox` without specifying a font.

### What did you expect to happen?

I expected `ImageDraw.textbbox` to work without specifying a font like `ImageDraw.text` does.

### What actually happened?

It throws an `AttributeError`:

```
File "<...>/PIL/ImageDraw.py", line 657, in textbbox
    bbox = font.getbbox(
AttributeError: 'ImageFont' object has no attribute 'getbbox'
```

It also does this when specifying `ImageFont.load_default()` manually as shown below. It does work when using another font, as shown below in the commented out line.

### What are your OS, Python and Pillow versions?

* OS: Ubuntu 18.04
* Python: 3.6.9
* Pillow: 8.2.0

```python
from PIL import Image, ImageDraw, ImageFont
from io import BytesIO

size = (256, 256)

def thumbnail(orig, fmt, text=None):
    if isinstance(orig, bytes):
        orig = BytesIO(orig)
    image = Image.open(orig)
    image.thumbnail(size)
    if text is not None:
        draw = ImageDraw.Draw(image)
        # font = ImageFont.truetype("FreeSans", size=20)
        font = ImageFont.load_default()
        print(draw.textbbox((0, 0), text, font=font))
        draw.text((0, 0), text, font=font)
    result = BytesIO()
    image.save(result, fmt)
    return result.getvalue()
```



Discussion:
From the docs (emphasis added) https://pillow.readthedocs.io/en/stable/reference/ImageDraw.html#PIL.ImageDraw.ImageDraw.textbbox:

> Returns bounding box (in pixels) of given text relative to given anchor when rendered in font with provided direction, features, and language. **Only supported for TrueType fonts.**

The default ImageDraw font is in PIL font format, not TrueType.

The default font also doesn't support anchors and all glyphs fit within their own bounding box, so `textbbox` offers no advantages over `textsize`. (The inverse is not true, `textsize` is unreliable for TrueType fonts.) As a workaround you can use the following:
```python
if hasattr(font, "getbbox"):
    bbox = draw.textbbox(...)
else:
    w, h = draw.textsize(...)
    bbox = (x, y, x + w, y + h)
```
Alright, thanks I missed that it only worked for TrueType fonts. It would be nice if there was a check for that in `textbbox` so the mistake made was clear.

Resolving patch:
diff --git a/src/PIL/ImageDraw.py b/src/PIL/ImageDraw.py
--- a/src/PIL/ImageDraw.py
+++ b/src/PIL/ImageDraw.py
@@ -33,7 +33,7 @@
 import math
 import numbers
 
-from . import Image, ImageColor
+from . import Image, ImageColor, ImageFont
 
 """
 A simple 2D drawing interface for PIL images.
@@ -646,6 +646,8 @@ def textbbox(
 
         if font is None:
             font = self.getfont()
+        if not isinstance(font, ImageFont.FreeTypeFont):
+            raise ValueError("Only supported for TrueType fonts")
         mode = "RGBA" if embedded_color else self.fontmode
         bbox = font.getbbox(
             text, mode, direction, features, language, stroke_width, anchor


Test patch:
diff --git a/Tests/test_imagefont.py b/Tests/test_imagefont.py
--- a/Tests/test_imagefont.py
+++ b/Tests/test_imagefont.py
@@ -719,6 +719,13 @@ def test_variation_set_by_axes(self):
         font.set_variation_by_axes([100])
         self._check_text(font, "Tests/images/variation_tiny_axes.png", 32.5)
 
+    def test_textbbox_non_freetypefont(self):
+        im = Image.new("RGB", (200, 200))
+        d = ImageDraw.Draw(im)
+        default_font = ImageFont.load_default()
+        with pytest.raises(ValueError):
+            d.textbbox((0, 0), "test", font=default_font)
+
     @pytest.mark.parametrize(
         "anchor, left, left_old, top",
         (