mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-10-31 07:57:27 +03:00 
			
		
		
		
	Raise an error if textbbox is used without a FreeTypeFont
This commit is contained in:
		
							parent
							
								
									affa059e95
								
							
						
					
					
						commit
						362d504011
					
				|  | @ -719,6 +719,13 @@ class TestImageFont: | ||||||
|         font.set_variation_by_axes([100]) |         font.set_variation_by_axes([100]) | ||||||
|         self._check_text(font, "Tests/images/variation_tiny_axes.png", 32.5) |         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( |     @pytest.mark.parametrize( | ||||||
|         "anchor, left, left_old, top", |         "anchor, left, left_old, top", | ||||||
|         ( |         ( | ||||||
|  |  | ||||||
|  | @ -33,7 +33,7 @@ | ||||||
| import math | import math | ||||||
| import numbers | import numbers | ||||||
| 
 | 
 | ||||||
| from . import Image, ImageColor | from . import Image, ImageColor, ImageFont | ||||||
| 
 | 
 | ||||||
| """ | """ | ||||||
| A simple 2D drawing interface for PIL images. | A simple 2D drawing interface for PIL images. | ||||||
|  | @ -646,6 +646,8 @@ class ImageDraw: | ||||||
| 
 | 
 | ||||||
|         if font is None: |         if font is None: | ||||||
|             font = self.getfont() |             font = self.getfont() | ||||||
|  |         if not isinstance(font, ImageFont.FreeTypeFont): | ||||||
|  |             raise ValueError("Only supported for TrueType fonts") | ||||||
|         mode = "RGBA" if embedded_color else self.fontmode |         mode = "RGBA" if embedded_color else self.fontmode | ||||||
|         bbox = font.getbbox( |         bbox = font.getbbox( | ||||||
|             text, mode, direction, features, language, stroke_width, anchor |             text, mode, direction, features, language, stroke_width, anchor | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user