Skip to content

Commit 6564325

Browse files
authored
Encode using latin-1 in PSDraw text() to match the latin-1 specification in setfont() (python-pillow#9403)
2 parents 93c8a60 + a6a701c commit 6564325

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)