mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-10-30 23:47:27 +03:00 
			
		
		
		
	Accept float stroke widths
This commit is contained in:
		
							parent
							
								
									cb2a0c40f3
								
							
						
					
					
						commit
						01ba1e2252
					
				
							
								
								
									
										
											BIN
										
									
								
								Tests/images/imagedraw_stroke_float.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Tests/images/imagedraw_stroke_float.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 1.5 KiB | 
|  | @ -1368,6 +1368,20 @@ def test_stroke() -> None: | |||
|         ) | ||||
| 
 | ||||
| 
 | ||||
| @skip_unless_feature("freetype2") | ||||
| def test_stroke_float() -> None: | ||||
|     # Arrange | ||||
|     im = Image.new("RGB", (120, 130)) | ||||
|     draw = ImageDraw.Draw(im) | ||||
|     font = ImageFont.truetype("Tests/fonts/FreeMono.ttf", 120) | ||||
| 
 | ||||
|     # Act | ||||
|     draw.text((12, 12), "A", "#f00", font, stroke_width=0.5) | ||||
| 
 | ||||
|     # Assert | ||||
|     assert_image_similar_tofile(im, "Tests/images/imagedraw_stroke_float.png", 3.1) | ||||
| 
 | ||||
| 
 | ||||
| @skip_unless_feature("freetype2") | ||||
| def test_stroke_descender() -> None: | ||||
|     # Arrange | ||||
|  |  | |||
|  | @ -833,7 +833,7 @@ font_render(FontObject *self, PyObject *args) { | |||
|     Py_ssize_t id; | ||||
|     int mask = 0;  /* is FT_LOAD_TARGET_MONO enabled? */ | ||||
|     int color = 0; /* is FT_LOAD_COLOR enabled? */ | ||||
|     int stroke_width = 0; | ||||
|     float stroke_width = 0; | ||||
|     PY_LONG_LONG foreground_ink_long = 0; | ||||
|     unsigned int foreground_ink; | ||||
|     const char *mode = NULL; | ||||
|  | @ -853,7 +853,7 @@ font_render(FontObject *self, PyObject *args) { | |||
| 
 | ||||
|     if (!PyArg_ParseTuple( | ||||
|             args, | ||||
|             "OO|zzOzizLffO:render", | ||||
|             "OO|zzOzfzLffO:render", | ||||
|             &string, | ||||
|             &fill, | ||||
|             &mode, | ||||
|  | @ -919,8 +919,8 @@ font_render(FontObject *self, PyObject *args) { | |||
|         return NULL; | ||||
|     } | ||||
| 
 | ||||
|     width += stroke_width * 2 + ceil(x_start); | ||||
|     height += stroke_width * 2 + ceil(y_start); | ||||
|     width += ceil(stroke_width * 2 + x_start); | ||||
|     height += ceil(stroke_width * 2 + y_start); | ||||
|     image = PyObject_CallFunction(fill, "ii", width, height); | ||||
|     if (image == Py_None) { | ||||
|         PyMem_Del(glyph_info); | ||||
|  | @ -934,8 +934,8 @@ font_render(FontObject *self, PyObject *args) { | |||
|     Py_XDECREF(imageId); | ||||
|     im = (Imaging)id; | ||||
| 
 | ||||
|     x_offset -= stroke_width; | ||||
|     y_offset -= stroke_width; | ||||
|     x_offset = round(x_offset - stroke_width); | ||||
|     y_offset = round(y_offset - stroke_width); | ||||
|     if (count == 0 || width == 0 || height == 0) { | ||||
|         PyMem_Del(glyph_info); | ||||
|         return Py_BuildValue("N(ii)", image, x_offset, y_offset); | ||||
|  | @ -950,7 +950,7 @@ font_render(FontObject *self, PyObject *args) { | |||
| 
 | ||||
|         FT_Stroker_Set( | ||||
|             stroker, | ||||
|             (FT_Fixed)stroke_width * 64, | ||||
|             (FT_Fixed)round(stroke_width * 64), | ||||
|             FT_STROKER_LINECAP_ROUND, | ||||
|             FT_STROKER_LINEJOIN_ROUND, | ||||
|             0 | ||||
|  | @ -988,8 +988,8 @@ font_render(FontObject *self, PyObject *args) { | |||
|     } | ||||
| 
 | ||||
|     /* set pen position to text origin */ | ||||
|     x = (-x_min + stroke_width + x_start) * 64; | ||||
|     y = (-y_max + (-stroke_width) - y_start) * 64; | ||||
|     x = round((-x_min + stroke_width + x_start) * 64); | ||||
|     y = round((-y_max + (-stroke_width) - y_start) * 64); | ||||
| 
 | ||||
|     if (stroker == NULL) { | ||||
|         load_flags |= FT_LOAD_RENDER; | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user