mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-10-31 07:57:27 +03:00 
			
		
		
		
	add tests for opaque COLR and CBDT fonts
This commit is contained in:
		
							parent
							
								
									9151da162c
								
							
						
					
					
						commit
						55db572467
					
				
							
								
								
									
										
											BIN
										
									
								
								Tests/fonts/BungeeColor-Regular_colr_Windows.ttf
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Tests/fonts/BungeeColor-Regular_colr_Windows.ttf
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							|  | @ -2,10 +2,12 @@ | |||
| NotoNastaliqUrdu-Regular.ttf and NotoSansSymbols-Regular.ttf, from https://github.com/googlei18n/noto-fonts | ||||
| NotoSans-Regular.ttf, from https://www.google.com/get/noto/ | ||||
| NotoSansJP-Thin.otf, from https://www.google.com/get/noto/help/cjk/ | ||||
| NotoColorEmoji.ttf, from https://github.com/googlefonts/noto-emoji | ||||
| AdobeVFPrototype.ttf, from https://github.com/adobe-fonts/adobe-variable-font-prototype | ||||
| TINY5x3GX.ttf, from http://velvetyne.fr/fonts/tiny | ||||
| ArefRuqaa-Regular.ttf, from https://github.com/google/fonts/tree/master/ofl/arefruqaa | ||||
| ter-x20b.pcf, from http://terminus-font.sourceforge.net/ | ||||
| BungeeColor-Regular_colr_Windows.ttf, from https://github.com/djrrb/bungee | ||||
| 
 | ||||
| All of the above fonts are published under the SIL Open Font License (OFL) v1.1 (http://scripts.sil.org/cms/scripts/page.php?site_id=nrsi&id=OFL), which allows you to copy, modify, and redistribute them if you need to. | ||||
| 
 | ||||
|  |  | |||
							
								
								
									
										
											BIN
										
									
								
								Tests/fonts/NotoColorEmoji.ttf
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Tests/fonts/NotoColorEmoji.ttf
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								Tests/images/cbdt_notocoloremoji.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Tests/images/cbdt_notocoloremoji.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 6.2 KiB | 
							
								
								
									
										
											BIN
										
									
								
								Tests/images/cbdt_notocoloremoji_mask.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Tests/images/cbdt_notocoloremoji_mask.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 5.9 KiB | 
							
								
								
									
										
											BIN
										
									
								
								Tests/images/colr_bungee.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Tests/images/colr_bungee.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 4.4 KiB | 
							
								
								
									
										
											BIN
										
									
								
								Tests/images/colr_bungee_mask.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Tests/images/colr_bungee_mask.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 2.7 KiB | 
							
								
								
									
										
											BIN
										
									
								
								Tests/images/standard_embedded.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Tests/images/standard_embedded.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 2.8 KiB | 
|  | @ -840,6 +840,102 @@ class TestImageFont: | |||
|                 ValueError, lambda: d.multiline_text((0, 0), "foo\nbar", anchor=anchor) | ||||
|             ) | ||||
| 
 | ||||
|     def test_standard_embedded_color(self): | ||||
|         txt = "Hello World!" | ||||
|         ttf = ImageFont.truetype(FONT_PATH, 40, layout_engine=self.LAYOUT_ENGINE) | ||||
|         ttf.getsize(txt) | ||||
| 
 | ||||
|         img = Image.new("RGB", (300, 64), "white") | ||||
|         d = ImageDraw.Draw(img) | ||||
|         d.text((10, 10), txt, font=ttf, fill="#fa6", embedded_color=True) | ||||
| 
 | ||||
|         with Image.open("Tests/images/standard_embedded.png") as expected: | ||||
|             assert_image_similar(img, expected, max(self.metrics["multiline"], 3)) | ||||
| 
 | ||||
|     @pytest.mark.skipif( | ||||
|         parse_version(features.version_module("freetype2")) < parse_version("2.5.0"), | ||||
|         reason="Freetype 2.5.0 or newer required", | ||||
|     ) | ||||
|     def test_cbdt(self): | ||||
|         try: | ||||
|             font = ImageFont.truetype( | ||||
|                 "Tests/fonts/NotoColorEmoji.ttf", | ||||
|                 size=109, | ||||
|                 layout_engine=self.LAYOUT_ENGINE, | ||||
|             ) | ||||
| 
 | ||||
|             im = Image.new("RGB", (150, 150), "white") | ||||
|             d = ImageDraw.Draw(im) | ||||
| 
 | ||||
|             d.text((10, 10), "\u263A", embedded_color=True, font=font) | ||||
| 
 | ||||
|             with Image.open("Tests/images/cbdt_notocoloremoji.png") as expected: | ||||
|                 assert_image_similar(im, expected, self.metrics["multiline"]) | ||||
|         except IOError as ex: | ||||
|             assert str(ex) in ("unimplemented feature", "unknown file format") | ||||
|             pytest.skip("freetype compiled without libpng or unsupported") | ||||
| 
 | ||||
|     @pytest.mark.skipif( | ||||
|         parse_version(features.version_module("freetype2")) < parse_version("2.5.0"), | ||||
|         reason="Freetype 2.5.0 or newer required", | ||||
|     ) | ||||
|     def test_cbdt_mask(self): | ||||
|         try: | ||||
|             font = ImageFont.truetype( | ||||
|                 "Tests/fonts/NotoColorEmoji.ttf", | ||||
|                 size=109, | ||||
|                 layout_engine=self.LAYOUT_ENGINE, | ||||
|             ) | ||||
| 
 | ||||
|             im = Image.new("RGB", (150, 150), "white") | ||||
|             d = ImageDraw.Draw(im) | ||||
| 
 | ||||
|             d.text((10, 10), "\u263A", "black", font=font) | ||||
| 
 | ||||
|             with Image.open("Tests/images/cbdt_notocoloremoji_mask.png") as expected: | ||||
|                 assert_image_similar(im, expected, self.metrics["multiline"]) | ||||
|         except IOError as ex: | ||||
|             assert str(ex) in ("unimplemented feature", "unknown file format") | ||||
|             pytest.skip("freetype compiled without libpng or unsupported") | ||||
| 
 | ||||
|     @pytest.mark.skipif( | ||||
|         parse_version(features.version_module("freetype2")) < parse_version("2.10.0"), | ||||
|         reason="Freetype 2.10.0 or newer required", | ||||
|     ) | ||||
|     def test_colr(self): | ||||
|         font = ImageFont.truetype( | ||||
|             "Tests/fonts/BungeeColor-Regular_colr_Windows.ttf", | ||||
|             size=64, | ||||
|             layout_engine=self.LAYOUT_ENGINE, | ||||
|         ) | ||||
| 
 | ||||
|         im = Image.new("RGB", (300, 75), "white") | ||||
|         d = ImageDraw.Draw(im) | ||||
| 
 | ||||
|         d.text((15, 5), "Bungee", embedded_color=True, font=font) | ||||
| 
 | ||||
|         with Image.open("Tests/images/colr_bungee.png") as expected: | ||||
|             assert_image_similar(im, expected, 21) | ||||
| 
 | ||||
|     @pytest.mark.skipif( | ||||
|         parse_version(features.version_module("freetype2")) < parse_version("2.10.0"), | ||||
|         reason="Freetype 2.10.0 or newer required", | ||||
|     ) | ||||
|     def test_colr_mask(self): | ||||
|         font = ImageFont.truetype( | ||||
|             "Tests/fonts/BungeeColor-Regular_colr_Windows.ttf", | ||||
|             size=64, | ||||
|             layout_engine=self.LAYOUT_ENGINE, | ||||
|         ) | ||||
| 
 | ||||
|         im = Image.new("RGB", (300, 75), "white") | ||||
|         d = ImageDraw.Draw(im) | ||||
| 
 | ||||
|         d.text((15, 5), "Bungee", "black", font=font) | ||||
| 
 | ||||
|         with Image.open("Tests/images/colr_bungee_mask.png") as expected: | ||||
|             assert_image_similar(im, expected, 22) | ||||
| 
 | ||||
| 
 | ||||
| @skip_unless_feature("raqm") | ||||
| class TestImageFont_RaqmLayout(TestImageFont): | ||||
|  |  | |||
|  | @ -40,4 +40,4 @@ def test_similar(): | |||
|         fill=(0, 0, 0), | ||||
|         font=font_outline, | ||||
|     ) | ||||
|     assert_image_similar(im_bitmap, im_outline, 20) | ||||
|     assert_image_similar(im_bitmap, im_outline, 44) | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user