diff options
author | Georg Brandl <georg@python.org> | 2022-07-30 09:12:27 +0200 |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2022-07-30 09:13:18 +0200 |
commit | 14f84f610a584a59bb8072fd558a9f68130cfad9 (patch) | |
tree | 857fed83c4ebe7f2f1e193fdd47ae1145e659c32 /pygments/formatters | |
parent | aaca62dab28d4924651e2cf3a6fce872ab522628 (diff) | |
download | pygments-git-14f84f610a584a59bb8072fd558a9f68130cfad9.tar.gz |
formatters/img: use new API for bounding box for Pillow 9.2
Diffstat (limited to 'pygments/formatters')
-rw-r--r-- | pygments/formatters/img.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/pygments/formatters/img.py b/pygments/formatters/img.py index 08400407..4839d86c 100644 --- a/pygments/formatters/img.py +++ b/pygments/formatters/img.py @@ -206,13 +206,17 @@ class FontManager: """ Get the character size. """ - return self.fonts['NORMAL'].getsize('M') + return self.get_text_size('M') def get_text_size(self, text): """ - Get the text size(width, height). + Get the text size (width, height). """ - return self.fonts['NORMAL'].getsize(text) + font = self.fonts['NORMAL'] + if hasattr(font, 'getbbox'): # Pillow >= 9.2.0 + return font.getbbox(text)[2:4] + else: + return font.getsize(text) def get_font(self, bold, oblique): """ @@ -520,7 +524,7 @@ class ImageFormatter(Formatter): text_fg = self._get_text_color(style), text_bg = self._get_text_bg_color(style), ) - temp_width, temp_hight = self.fonts.get_text_size(temp) + temp_width, _ = self.fonts.get_text_size(temp) linelength += temp_width maxlinelength = max(maxlinelength, linelength) charno += len(temp) |