Closed wilm02 closed 1 year ago
Meanwhile I found a solution by myself.
Exchanging the line
drawDC.DrawText(text, (0, 0, w, h), win32con.DT_LEFT)
with
ctypes.windll.gdi32.TextOutW (drawDC.GetSafeHdc(), 0,0, text, len (text))
will solve the problem with foreign characters.
Perhaps there might be a more elegant way.
Here is a Python program that outputs text in truetype font using native Windows routines. It works fine with one exception: UTF-8 / ISO-8859-1 encoding. I get the truetype output: "(~A)(1/4) = u-umla" instead of the expected "(:u) = u-umlaut". The beginning of the output is the typical to an UTF-8 text opened with ISO-8859-1 coding. The end of the output is truncated, because the width seems to be calculated correctly. This program runs under Windows 10 64 bit with python 3.10.5 and pywin32-306.
Doing the same in C, using the string "(:u) = u-umlaut" directly in source, the truetype output depends on the coding of the source file. With an ISO-8859-1 source file I get the expected truetype output: "(:u) = u-umlaut". With an UTF-8 source file I get the truetype output: "(~A)(1/4) = u-umlaut". But in Python UTF-8 is fix for source files.
How can I solve this problem?