-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Crash when loading font on Japanese Windows 10 #4468
Comments
Would you be able to run the following script? This is code that I've put together to print the path of the font that Pillow is trying to access. Hopefully that should provide more insight. def printFontPath(path):
import os
windir = os.environ.get("WINDIR")
if windir:
print("Note: Searches in "+os.path.join(windir, "fonts"))
else:
print("Note: No WINDIR present")
from PIL import ImageFont
freeType = ImageFont.FreeTypeFont
class FreeTypeFont(freeType):
def __init__(self, font=None, size=10, index=0, encoding="", layout_engine=None):
if font != path:
print(font)
super().__init__(font, size, index, encoding, layout_engine)
ImageFont.FreeTypeFont = FreeTypeFont
try:
ImageFont.truetype(path)
except OSError:
pass
printFontPath("ARIAL.TTF") |
Thank you for the fast follow up. I will run the script as soon as I get back to that computer. |
It seems to be looking in the correct folder: PS C:\Users\Man\Documents\GitHub> & C:/Users/Man/AppData/Local/Programs/Python/Python37-32/python.exe c:/Users/Man/Documents/GitHub/crowd-ops\Projects\Add-Annotations/font2.py
Note: Searches in C:\WINDOWS\fonts
PS C:\Users\Man\Documents\GitHub> |
Ah, but, my script should have also printed a path for the font. The fact that it didn't should mean that Pillow isn't finding 'ARIAL.TTF' in C:\WINDOWS\fonts. What is the path to your installed ARIAL.TTF? |
I somehow solved it. Debugging I then opened the font by writing C:\Users\マヨ\Documents>python font2.py
Note: Searches in C:\WINDOWS\fonts
C:\WINDOWS\fonts\arial.ttf
C:\Users\マヨ\Documents> Using the path in picture 3 gives the unicode error: C:\Users\マヨ\Documents>python font2.py
File "font2.py", line 24
printFontPath("C:\USERS\マヨ\APPDATA\LOCAL\MICROSOFT\WINDOWS\FONTS\ARIAL.TTF")
^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 1-2: truncated \UXXXXXXXX escape
C:\Users\マヨ\Documents> Important to note is that I could only get the "Install button" to be enabled by opening the file through the command line. Opening the preview through right click did not enable the install button. I was able to replicate the problem/error by uninstalling the font making windows once again show that the font is installed in I would like to write this of as a "misspelled font name" BUT I am 100% sure that spelled the font name correctly in lower case letters before I tried upper case. The fact that installing and uninstalling the font made the script work/break without chaining it also proof that it was not a spelling problem together with the fact that I could run it without a problem on a mac machine. I was also able to recreate the problem a few times, so I just don't know what is going on... The reason I wrote this much is that I hope it will help anyone else who might run into the same problem in the future. I will try to reboot my PC after posting this. But if I can no longer replicate the error, then I do not know how I would be able to debug any further to find the root cause. Thank you very much for the help @radarhere |
What did you do?
Tried to draw text to an image using:
What did you expect to happen?
The text to be drawn
What actually happened?
Application Crashed
What are your OS, Python and Pillow versions?
Other
The font is installed (double-checked).
Saving the font in the same folder as the script and changing
to
is a viable work-around.
Also see sam210723/xrit-rx#9
The text was updated successfully, but these errors were encountered: