PIL text provider: use `get_bbox` when `get_size` is not available. Allows latest versions of pillow to work along with older ones. (#8503)

This commit is contained in:
Akshay Arora 2023-12-11 23:02:27 +05:30 committed by GitHub
parent 3d045cd6ab
commit 49b81cb224
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 2 deletions

View File

@ -34,11 +34,16 @@ class LabelPIL(LabelBase):
def get_extents(self, text):
font = self._select_font()
w, h = font.getsize(text)
try:
w, h = font.getsize(text)
except AttributeError:
left, top, right, bottom = font.getbbox(text)
w = right - left
h = bottom
return w, h
def get_cached_extents(self):
return self._select_font().getsize
return self.get_extents
def _render_begin(self):
# create a surface, context, font...