diff --git a/Tests/test_imagefont.py b/Tests/test_imagefont.py index 0440a661c9d..768cc2e3365 100644 --- a/Tests/test_imagefont.py +++ b/Tests/test_imagefont.py @@ -852,6 +852,14 @@ def test_variation_set_by_name(font: ImageFont.FreeTypeFont) -> None: _check_text(font, "Tests/images/variation_tiny_name.png", 40) +def test_truetype_bytes() -> None: + # Ensure bytestrings with the high bit set do not cause sign extension + font = ImageFont.truetype( + "Tests/fonts/FreeMono.ttf", 20, layout_engine=ImageFont.Layout.BASIC + ) + assert font.getbbox(b"\xe9") == font.getbbox("\u00e9") + + def test_variation_set_by_axes(font: ImageFont.FreeTypeFont) -> None: with pytest.raises(OSError): font.set_variation_by_axes([500, 50]) diff --git a/docs/releasenotes/13.1.0.rst b/docs/releasenotes/13.1.0.rst index 44729c75bad..a263312fa64 100644 --- a/docs/releasenotes/13.1.0.rst +++ b/docs/releasenotes/13.1.0.rst @@ -159,3 +159,10 @@ not bundled into the wheels, so the system zlib was used at runtime instead, and Pillow 13.0.0 also failed to import on systems where ``libz.so.1`` was not on the default library search path, such as NixOS. Linux wheels no longer require a system zlib, and gain the speed of zlib-ng as macOS and Windows wheels already did. + +Kerning in the basic layout engine +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +When libraqm is not available, kerning was applied at 1/64th of its intended size, +because a value in pixels was added to an advance in 26.6 fixed point precision. +The full kerning value is now applied even when libraqm is not available. diff --git a/src/_imagingft.c b/src/_imagingft.c index ee1f8c2c66e..0374f1ab3a2 100644 --- a/src/_imagingft.c +++ b/src/_imagingft.c @@ -432,7 +432,7 @@ text_layout_fallback( } for (i = 0; i < count; i++) { if (buffer) { - ch = buffer[i]; + ch = (unsigned char)buffer[i]; } else { ch = PyUnicode_READ_CHAR(string, i); } @@ -454,8 +454,8 @@ text_layout_fallback( ft_kerning_default, &delta ) == 0) { - (*glyph_info)[i - 1].x_advance += PIXEL(delta.x); - (*glyph_info)[i - 1].y_advance += PIXEL(delta.y); + (*glyph_info)[i - 1].x_advance += delta.x; + (*glyph_info)[i - 1].y_advance += delta.y; } }