mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-11-04 09:57:43 +03:00 
			
		
		
		
	Improve error message when creating TrueType fonts of invalid size
Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com>
This commit is contained in:
		
							parent
							
								
									697c24bc7d
								
							
						
					
					
						commit
						39ec56c6ea
					
				| 
						 | 
					@ -1071,3 +1071,9 @@ def test_raqm_missing_warning(monkeypatch):
 | 
				
			||||||
        "Raqm layout was requested, but Raqm is not available. "
 | 
					        "Raqm layout was requested, but Raqm is not available. "
 | 
				
			||||||
        "Falling back to basic layout."
 | 
					        "Falling back to basic layout."
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@pytest.mark.parametrize("size", [-1, 0])
 | 
				
			||||||
 | 
					def test_invalid_truetype_sizes_raise(layout_engine, size):
 | 
				
			||||||
 | 
					    with pytest.raises(ValueError):
 | 
				
			||||||
 | 
					        ImageFont.truetype(FONT_PATH, size, layout_engine=layout_engine)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -788,8 +788,13 @@ def truetype(font=None, size=10, index=0, encoding="", layout_engine=None):
 | 
				
			||||||
                     .. versionadded:: 4.2.0
 | 
					                     .. versionadded:: 4.2.0
 | 
				
			||||||
    :return: A font object.
 | 
					    :return: A font object.
 | 
				
			||||||
    :exception OSError: If the file could not be read.
 | 
					    :exception OSError: If the file could not be read.
 | 
				
			||||||
 | 
					    :exception ValueError: If the font size is not greater than zero.
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if size <= 0:
 | 
				
			||||||
 | 
					        msg = "font size must be greater than 0"
 | 
				
			||||||
 | 
					        raise ValueError(msg)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def freetype(font):
 | 
					    def freetype(font):
 | 
				
			||||||
        return FreeTypeFont(font, size, index, encoding, layout_engine)
 | 
					        return FreeTypeFont(font, size, index, encoding, layout_engine)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user