rougier / freetype-py

Python binding for the freetype library
Other
304 stars 88 forks source link

freetype.ft_errors.FT_Exception: FT_Exception: (cannot open resource) #98

Closed jeff5048 closed 6 years ago

jeff5048 commented 6 years ago

Hi,

I am new to Python programming. I don't know where else to post this issue. I installed freetype like this: python -m pip install --user freetype-py

It seemed to install okay.

There is an error when the following code is run in IDLE:

import freetype face = freetype.Face("Vera.ttf") face.set_char_size( 48*64 ) face.load_char('S') bitmap = face.glyph.bitmap print (bitmap.buffer)

I suspect there is no "Vera.ttf" file. The code doesn't work for common windows "ttf" files. Do fonts need to be moved to a specific directory?

Windows 10 Pro 64-bit OS and processor

The error is:

Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18) [MSC v.1900 64 bit (AMD64)] on win32 Type "copyright", "credits" or "license()" for more information.

= RESTART: C:\Users\jeff5\Desktop\Python\OpenGL_Exercises\freetypeExample.py = Traceback (most recent call last): File "C:\Users\jeff5\Desktop\Python\OpenGL_Exercises\freetypeExample.py", line 2, in face = freetype.Face("Vera.ttf") File "C:\Users\jeff5\AppData\Roaming\Python\Python36\site-packages\freetype__init.py", line 989, in init__ if error: raise FT_Exception( error ) freetype.ft_errors.FT_Exception: FT_Exception: (cannot open resource)

madig commented 6 years ago

Hi! If you want to run the code from IDLE, you probably need to specify the full path to a TTF you want to render, try e.g.

import freetype
face = freetype.Face(r'C:\Windows\Fonts\arial.ttf')
face.set_char_size( 48*64 )
face.load_char('S')
bitmap = face.glyph.bitmap
print (bitmap.buffer)

Note the r in front of 'C:\Windows\Fonts\arial.ttf', this makes Windows paths work in Python.

jeff5048 commented 6 years ago

Thank you madig. That did work! I was also able to get it to work by placing a ttf file in the directory with the example code file. It is outputting a bunch of comma delimited numbers to the Python 3.6.5 shell. The "r" before the path is a useful tip as I did not know that. Thx!