Skip to content

Commit a6a701c

Browse files
authored
Match PSDraw text() encoding to the latin-1 specification in setfont()
Without this, characters that are in latin-1 but reflected differently in UTF-8 will not be properly rendered. For example,"ó" becomes "ó".
1 parent e08f910 commit a6a701c

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/PIL/PSDraw.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ def text(self, xy: tuple[int, int], text: str) -> None:
100100
Draws text at the given position. You must use
101101
:py:meth:`~PIL.PSDraw.PSDraw.setfont` before calling this method.
102102
"""
103-
text_bytes = bytes(text, "UTF-8")
103+
# The font is loaded as ISOLatin1Encoding, so use latin-1 here.
104+
text_bytes = bytes(text, "latin-1")
104105
text_bytes = b"\\(".join(text_bytes.split(b"("))
105106
text_bytes = b"\\)".join(text_bytes.split(b")"))
106107
self.fp.write(b"%d %d M (%s) S\n" % (xy + (text_bytes,)))

0 commit comments

Comments
 (0)