From a6a701c4dbecde4392465a1bc5ffe8a82445a52f Mon Sep 17 00:00:00 2001 From: Steve Dougherty Date: Wed, 21 Jan 2026 06:01:00 -0500 Subject: [PATCH] Match PSDraw text() encoding to the latin-1 specification in setfont() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Without this, characters that are in latin-1 but reflected differently in UTF-8 will not be properly rendered. For example,"ó" becomes "ó". --- src/PIL/PSDraw.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/PIL/PSDraw.py b/src/PIL/PSDraw.py index 7fd4c5c94..e6b74a918 100644 --- a/src/PIL/PSDraw.py +++ b/src/PIL/PSDraw.py @@ -100,7 +100,8 @@ class PSDraw: Draws text at the given position. You must use :py:meth:`~PIL.PSDraw.PSDraw.setfont` before calling this method. """ - text_bytes = bytes(text, "UTF-8") + # The font is loaded as ISOLatin1Encoding, so use latin-1 here. + text_bytes = bytes(text, "latin-1") text_bytes = b"\\(".join(text_bytes.split(b"(")) text_bytes = b"\\)".join(text_bytes.split(b")")) self.fp.write(b"%d %d M (%s) S\n" % (xy + (text_bytes,)))